Repository navigation
feat(webhooks): add normalized message_edit event - #27
Conversation
|
Lost in the diff? Review this PR in Change Stack to follow the change map from intent to exact ranges. 📝 WalkthroughWalkthroughThis PR implements end-to-end support for WhatsApp message edit events. A new normalized ChangesMessage Edit Event Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/engine-zapo/src/events.ts (1)
305-305: 💤 Low valueConsider a more defensive fallback for missing message id.
The fallback chain
pm?.key?.id ?? event.key.id ?? ''defaults to an empty string if both sources are missing. While rare, an empty string might not be a valid message identifier for downstream consumers (e.g., webhook delivery, client-side message tracking).Consider throwing an error or logging a warning if both id sources are missing, or document this edge case behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/engine-zapo/src/events.ts` at line 305, The id assignment uses pm?.key?.id ?? event.key.id ?? '' which can silently produce an invalid empty id; update the logic around where id is set (the object using pm, event, and key) to defensively handle missing ids: explicitly check pm?.key?.id and event.key.id and if both are absent either throw a descriptive Error or emit a warning via the existing logger (e.g., processLogger.warn) and abort/skip creating the message, ensuring downstream consumers never receive an empty string id; reference the pm, event, and key variables and the id property when implementing this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/engine-zapo/src/events.ts`:
- Line 305: The id assignment uses pm?.key?.id ?? event.key.id ?? '' which can
silently produce an invalid empty id; update the logic around where id is set
(the object using pm, event, and key) to defensively handle missing ids:
explicitly check pm?.key?.id and event.key.id and if both are absent either
throw a descriptive Error or emit a warning via the existing logger (e.g.,
processLogger.warn) and abort/skip creating the message, ensuring downstream
consumers never receive an empty string id; reference the pm, event, and key
variables and the id property when implementing this change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 88e28ee0-ea9d-4160-9c42-1a3eac48411d
📒 Files selected for processing (10)
apps/api/src/http/openapi.tspackages/engine-baileys/src/engine.tspackages/engine-baileys/src/events.test.tspackages/engine-baileys/src/events.tspackages/engine-zapo/src/engine.tspackages/engine-zapo/src/events.test.tspackages/engine-zapo/src/events.tspackages/types/src/engine.tspackages/types/src/schemas.test.tspackages/types/src/webhook.ts
|
Sobre o ponto do |
Resumo
Adiciona o evento normalizado
message_edit(id da mensagem original + novo conteúdo), entregue por webhook e SSE de forma idêntica nas enginesbaileysezapo(issue #8). 8 commits, ~11 arquivos.Closes #8. A forma (edição pelo app mobile,
secretEncryptedMessage) não entra nesta entrega e fica rastreada em #26.Backend
@multi-wa/types: novomessageEditEventSchemana uniãoengineEventSchemaemessage_editnowebhookEventTypeSchema.engine-baileys: detecta a edição clássica (protocolMessagetipoMESSAGE_EDIT) nomessages.upserte emitemessage_edit(isBaileysEditUpsert+mapBaileysEdit).engine-zapo: emitemessage_editda edição clássica (protocolMessageno eventomessage) e do addonmessage_editdecifrado.message_editnoWEBHOOK_DELIVERY_SCHEMA, com exemplos (1:1 e grupo) e descrição.Bug fixes / limpeza
protocolMessageque não é edição (revoke, ephemeral, peer-data, sync), que antes vazava comomessagecomcontent: { type: 'unknown', kind: 'protocolMessage' }, nas duas engines (isBaileysProtocolMessage/isZapoProtocolMessage).messageSecretno zapo que se mostrou inócua (a lib só persiste o secret de poll/event/bot - ver gap abaixo).Gap conhecido - forma (edição pelo app mobile)
A edição feita pelo celular chega como addon criptografado (
secretEncryptedMessage), que exige omessageSecretda mensagem original. Esse caminho fica não suportado de forma confiável nas duas engines, por limitação das libs:messageSecretapenas de poll/event/bot, nunca de texto; a única fonte seria omessagesmailbox (sem TTL, cresce sem limite). Limitação da lib (vinikjkkj/zapo#159).7.0.0-rc13) não decifrasecretEncryptedMessage. Há PRs abertos no upstream (WhiskeySockets/Baileys#2554 / #2547) que adicionam o decrypt nativo; a ideia é adotar quando saírem em release e configurargetMessage.A forma (edição via WhatsApp Web/Desktop, conteúdo em claro) funciona normalmente nas duas engines.
Plano de teste
pnpm linttermina sem warningspnpm typecheckpassapnpm buildpassaTEST_DATABASE_URL=... pnpm test:coveragepassa (211 testes, thresholds de cobertura ok)message_edit(id da original + novo texto) chegando no SSE/webhook, nas duas enginesprotocolMessageque não é edição não gera mais eventomessagecomcontentunknownSummary by CodeRabbit
message_editevent type for integrations