Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): bound the click id, and tidy four small inconsistencies
Yudhi Armyndharisa395627af2f9
diff --git a/src/engine/adapters/baileys-message-mapper.spec.ts b/src/engine/adapters/baileys-message-mapper.spec.tsindex 9b6772445..dc73f67f9 100644--- a/src/engine/adapters/baileys-message-mapper.spec.ts+++ b/src/engine/adapters/baileys-message-mapper.spec.ts@@ -553,7 +553,7 @@ describe('extractBaileysButtons (prompt choices Sim/Não / list rows)', () => {{buttonId: 'docs',buttonText: { displayText: 'Open the docs' },- nativeFlowInfo: { name: 'cta_url', paramsJson: JSON.stringify({ url: 'https://example.test' }) },+ nativeFlowInfo: { name: 'cta_url' },},],},diff --git a/src/engine/adapters/baileys-message-mapper.ts b/src/engine/adapters/baileys-message-mapper.tsindex 77bab15a4..257b4a231 100644--- a/src/engine/adapters/baileys-message-mapper.ts+++ b/src/engine/adapters/baileys-message-mapper.ts@@ -343,8 +343,12 @@ 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;+ /**+ * Present on a NATIVE_FLOW button. Only `name` is read, to decide whether the button can be+ * answered at all; the params of a classic button's reply come from `buttonId`/`buttonText`+ * beside it, not from this block.+ */+ nativeFlowInfo?: { name?: string | null } | null;} | null> | null;} | null;interactiveMessage?: {diff --git a/src/engine/adapters/whatsapp-web-js.adapter.ts b/src/engine/adapters/whatsapp-web-js.adapter.tsindex 11fe708f6..26417bbcb 100644--- a/src/engine/adapters/whatsapp-web-js.adapter.ts+++ b/src/engine/adapters/whatsapp-web-js.adapter.ts@@ -732,7 +732,8 @@ export class WhatsAppWebJsAdapter extends EventEmitter implements IWhatsAppEngin// whatsapp-web.js has no interactive button-reply send path; the parameters are not named so the// method reads as the 501 it is, and TypeScript accepts the narrower signature for the interface.- clickButton(): Promise<MessageResult> {+ // eslint-disable-next-line @typescript-eslint/require-await+ async clickButton(): Promise<MessageResult> {throw new EngineNotSupportedError('clickButton');}diff --git a/src/modules/events/events.gateway.ts b/src/modules/events/events.gateway.tsindex 80e1aaf5d..0e9f4f79b 100644--- a/src/modules/events/events.gateway.ts+++ b/src/modules/events/events.gateway.ts@@ -381,6 +381,9 @@ export class EventsGateway implements OnGatewayInit, OnGatewayConnection, OnGate// process, holding a slot of the cap above and keeping the Socket object reachable.if (client.disconnected) {this.untrackSocket(client);+ // Logged rather than returned silently: the disconnect handler has already written a+ // "Client disconnected" line for a client nothing ever announced as connected.+ this.logger.log(`Client ${client.id} authenticated after it had already gone (key: ${validKey.name})`);return;}this.logger.log(`Client connected: ${client.id} (key: ${validKey.name})`);@@ -414,8 +417,9 @@ export class EventsGateway implements OnGatewayInit, OnGatewayConnection, OnGate* the documented example client both do, never saw a subscribe confirmation, a pong, or any of the* refusals (FORBIDDEN_SESSION, INVALID_SESSION, INVALID_EVENTS, INVALID_MESSAGE).*- * A path that answered and then closed the socket keeps its own emit; emitting to a socket that is- * already gone is a no-op, and skipping it here keeps that frame single.+ * A path that answered and then closed the socket keeps its own emit, and this skips it rather than+ * emitting again: socket.io still accepts a write to a disconnected socket, so without the guard a+ * client could be handed the same frame twice on its way out.*/private reply<T>(client: Socket, frame: T): T {if (!client.disconnected) {diff --git a/src/modules/integration/ingress.service.spec.ts b/src/modules/integration/ingress.service.spec.tsindex ac74b2787..3b09b5163 100644--- a/src/modules/integration/ingress.service.spec.ts+++ b/src/modules/integration/ingress.service.spec.ts@@ -552,7 +552,8 @@ describe('dedupOn: body (a provider that rotates its delivery id on retry)', ()const second = deps();await new IngressService(second).handle({ ...req, headers: { 'x-delivery': '' }, rawBody: '{"n":2}' });- expect(second.enqueue).toHaveBeenCalledTimes(1);+ // The ids differ, which is the whole point: a blank header must not collapse two bodies onto one+ // dedup row. (A fresh `deps()` always enqueues, so asserting the call count would prove nothing.)expect((second.enqueue.mock.calls[0] as [unknown, string])[1]).not.toBe(firstId);});});diff --git a/src/modules/message/dto/message-actions.dto.ts b/src/modules/message/dto/message-actions.dto.tsindex 76bf993a2..b1c5da51c 100644--- a/src/modules/message/dto/message-actions.dto.ts+++ b/src/modules/message/dto/message-actions.dto.ts@@ -304,6 +304,9 @@ export class ClickButtonDto {})@IsString()@IsNotEmpty()+ // Persisted verbatim as the message body when `text` is omitted, so it carries the same bound the+ // label beside it does rather than an unbounded string.+ @MaxLength(MESSAGE_TEXT_MAX_LENGTH)buttonId!: string;@ApiPropertyOptional({