Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(wwebjs): report button and list replies as text

Yudhi Armyndharis3c809b5929a7
diff --git a/src/engine/adapters/message-mapper.spec.ts b/src/engine/adapters/message-mapper.spec.ts
index 9d6ffb44e..af4b09dcd 100644
--- a/src/engine/adapters/message-mapper.spec.ts
+++ b/src/engine/adapters/message-mapper.spec.ts
@@ -187,6 +187,11 @@ describe('mapWwebjsMessageType (engine type-token -> neutral MessageType boundar
['poll_creation', 'poll'],
['order', 'order'],
['product', 'product'],
+ // A tapped button, list row or template button: WA Web carries the chosen option's text in the
+ // body, and Baileys reports the same replies as text (#562).
+ ['buttons_response', 'text'],
+ ['list_response', 'text'],
+ ['template_button_reply', 'text'],
['e2e_notification', 'unknown'], // any unmapped wwebjs type
])('maps wwebjs type %s -> %s', (raw, expected) => {
expect(mapWwebjsMessageType(raw)).toBe(expected);
diff --git a/src/engine/adapters/message-mapper.ts b/src/engine/adapters/message-mapper.ts
index 101a6bfe1..1e6043bf5 100644
--- a/src/engine/adapters/message-mapper.ts
+++ b/src/engine/adapters/message-mapper.ts
@@ -10,7 +10,14 @@ import { chatKind } from '../identity/wa-id';
*/
export function mapWwebjsMessageType(raw: string): MessageType {
switch (raw) {
+ // Besides plain `chat`, a tapped button, list row or template button: WA Web carries the chosen
+ // option's text in the body, and Baileys reports the same replies as `text` (#562). `hsm` and
+ // `interactive` prompts are left out: their body can be empty, and an empty text is worse than
+ // `unknown`.
case 'chat':
+ case 'buttons_response':
+ case 'list_response':
+ case 'template_button_reply':
return 'text';
case 'image':
return 'image';