Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): drop a native-flow CTA from a classic button prompt
Yudhi Armyndharisd614c360e0f3
diff --git a/src/engine/adapters/baileys-message-mapper.spec.ts b/src/engine/adapters/baileys-message-mapper.spec.tsindex dbac78a3a..153a15475 100644--- a/src/engine/adapters/baileys-message-mapper.spec.ts+++ b/src/engine/adapters/baileys-message-mapper.spec.ts@@ -541,6 +541,47 @@ describe('extractBaileysButtons (prompt choices Sim/Não / list rows)', () => {]);});+ it('drops a native-flow CTA carried inside a classic buttonsMessage', () => {+ // The same envelope can hold both a reply button and a CTA that opens a URL or dials a number.+ // A CTA cannot be answered, so publishing it would offer a choice the click route must refuse.+ expect(+ extractBaileysButtons(+ {+ buttonsMessage: {+ buttons: [+ { buttonId: 'yes', buttonText: { displayText: 'Sim' } },+ {+ buttonId: 'docs',+ buttonText: { displayText: 'Open the docs' },+ nativeFlowInfo: { name: 'cta_url', paramsJson: JSON.stringify({ url: 'https://example.test' }) },+ },+ ],+ },+ },+ 'buttonsMessage',+ ),+ ).toEqual([{ id: 'yes', text: 'Sim' }]);+ });++ it('keeps a native-flow quick reply carried inside a classic buttonsMessage', () => {+ expect(+ extractBaileysButtons(+ {+ buttonsMessage: {+ buttons: [+ {+ buttonId: 'yes',+ buttonText: { displayText: 'Sim' },+ nativeFlowInfo: { name: 'quick_reply' },+ },+ ],+ },+ },+ 'buttonsMessage',+ ),+ ).toEqual([{ id: 'yes', text: 'Sim' }]);+ });+it('extracts interactiveMessage native-flow quick replies', () => {expect(extractBaileysButtons(diff --git a/src/engine/adapters/baileys-message-mapper.ts b/src/engine/adapters/baileys-message-mapper.tsindex 49b2982de..a8886a774 100644--- a/src/engine/adapters/baileys-message-mapper.ts+++ b/src/engine/adapters/baileys-message-mapper.ts@@ -343,6 +343,8 @@ export interface BaileysButtonsPromptContent {buttons?: Array<{buttonId?: string | null;buttonText?: { displayText?: string | null } | null;+ /** Present on a NATIVE_FLOW button, whose `name` decides whether it can be answered at all. */+ nativeFlowInfo?: { name?: string | null; paramsJson?: string | null } | null;} | null> | null;} | null;interactiveMessage?: {@@ -492,6 +494,14 @@ export function extractBaileysClickableButtons((content.buttonsMessage?.buttons ?? []).map((button, position) => {const text = button?.buttonText?.displayText?.trim();if (!text) return undefined;+ // A button in this envelope can still be a native-flow CTA (open a URL, dial a number), and+ // those cannot be answered with a reply. Keyed off the presence of nativeFlowInfo rather+ // than the type enum, which reaches us as a number or as its string name depending on how+ // the message was decoded, and which a CTA may omit entirely.+ const flow = button?.nativeFlowInfo;+ if (flow && !CLICKABLE_NATIVE_FLOW_NAMES.has(flow.name ?? '')) {+ return undefined;+ }const id = button?.buttonId?.trim() || text;return { id, text, index: position };}),