Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): drop a prompt choice whose id is over the cap instead of rewriting it
Yudhi Armyndharis5b179a5a9e3c
diff --git a/src/engine/adapters/baileys-message-mapper.spec.ts b/src/engine/adapters/baileys-message-mapper.spec.tsindex d181b3b62..dbac78a3a 100644--- a/src/engine/adapters/baileys-message-mapper.spec.ts+++ b/src/engine/adapters/baileys-message-mapper.spec.ts@@ -633,6 +633,17 @@ describe('extractBaileysButtons (prompt choices Sim/Não / list rows)', () => {expect(buttons![0].id).toBe('row_0');});+ // A row id goes back to the business bot verbatim on a click, so an over-long one is dropped+ // rather than rewritten into an id the bot would not recognise; only the label is trimmed.+ it('drops a choice whose id is over the cap instead of truncating it', () => {+ const rows = [+ { rowId: 'r'.repeat(BUTTON_TEXT_MAX_LENGTH + 1), title: 'too long to send back' },+ { rowId: 'ok', title: 'fine' },+ ];+ const buttons = extractBaileysButtons({ listMessage: { sections: [{ rows }] } }, 'listMessage');+ expect(buttons).toEqual([{ id: 'ok', text: 'fine' }]);+ });+it('yields nothing for a non-prompt content type', () => {expect(extractBaileysButtons({}, 'conversation')).toBeUndefined();expect(extractBaileysButtons({ buttonsMessage: { buttons: [] } }, 'buttonsMessage')).toBeUndefined();diff --git a/src/engine/adapters/baileys-message-mapper.ts b/src/engine/adapters/baileys-message-mapper.tsindex 8d521da76..49b2982de 100644--- a/src/engine/adapters/baileys-message-mapper.ts+++ b/src/engine/adapters/baileys-message-mapper.ts@@ -548,9 +548,11 @@ function collectChoices(entries: Array<BaileysClickableChoice | undefined>): Baiconst choices: BaileysClickableChoice[] = [];for (const entry of entries) {if (!entry) continue;- const id = entry.id.slice(0, BUTTON_TEXT_MAX_LENGTH);+ // The id goes back to the business bot verbatim on a click, so it is never rewritten: an id past+ // the cap is dropped (WhatsApp caps row ids far below it), while a long label is only trimmed.+ const id = entry.id;const text = entry.text.slice(0, BUTTON_TEXT_MAX_LENGTH);- if (!id || !text) continue;+ if (!id || id.length > BUTTON_TEXT_MAX_LENGTH || !text) continue;choices.push({ id, text, index: entry.index });if (choices.length >= BUTTONS_MAX_ENTRIES) break;}