Skip to content

fix(message): treat poll as a first-class message type#626

Merged
rmyndharis merged 1 commit into
mainfrom
fix/poll-first-class-messagetype
Jul 5, 2026
Merged

fix(message): treat poll as a first-class message type#626
rmyndharis merged 1 commit into
mainfrom
fix/poll-first-class-messagetype

Conversation

@rmyndharis

Copy link
Copy Markdown
Owner

Summary

Follow-up to #622 (native WhatsApp polls). That change persists outgoing polls with type: 'poll', but 'poll' was never added to the engine-neutral MessageType union, so the reported type diverged depending on how a client observed the same message:

  • GET /messages and chat history returned type: 'poll' (the persisted value).
  • The live message.sent websocket/webhook event is built from the adapter type mappers, which had no poll case, so it reported type: 'unknown'.
  • The dashboard coerced the persisted 'poll' back to 'unknown' via asMessageType().

The value degraded gracefully (the 📊 <question> body still rendered), but one message reporting two different types breaks the invariant the codebase documents in api.ts — that persisted rows, the message.sent/message.received payloads, and the websocket all share the same neutral type values.

Changes

  • Add 'poll' to the MessageType union (whatsapp-engine.interface.ts).
  • Map incoming poll messages to 'poll' in both adapters' mappers — whatsapp-web.js poll_creation, and Baileys pollCreationMessage / pollCreationMessageV2 / pollCreationMessageV3 (WhatsApp bumps the content key across versions).
  • Mirror 'poll' in the dashboard MESSAGE_TYPES so it is no longer coerced to unknown, and give it a stable color in the stats chart.
  • Add a persistence assertion to the sendPoll service spec (it previously only checked the engine-call args, not the persisted type/body).

With this, sent and received polls report poll consistently across REST, the websocket, webhooks, and the dashboard.

Verification

  • Backend: npm run lint + npm run build clean; full Jest suite green (1927 tests, incl. updated mapper and service specs).
  • Dashboard: npm run build, npm run lint, and npm run i18n:check all pass.

… and dashboard

Native polls (#622) were persisted with type 'poll', but 'poll' was not a member
of the MessageType union, so the type diverged by path: REST/DB history reported
'poll' while the live message.sent websocket/webhook event (built from the adapter
type mappers) and the dashboard (via asMessageType) both coerced the same message
to 'unknown'.

- Add 'poll' to the engine-neutral MessageType union.
- Map incoming poll messages to 'poll' in both mappers (wwjs 'poll_creation';
  Baileys 'pollCreationMessage'/V2/V3).
- Mirror 'poll' in the dashboard MESSAGE_TYPES and give it a stable chart color.
- Assert the persisted type/body in the sendPoll service spec.
@rmyndharis rmyndharis merged commit 444c548 into main Jul 5, 2026
9 checks passed
@rmyndharis rmyndharis deleted the fix/poll-first-class-messagetype branch July 5, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant