Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(baileys): expose the sender of a broadcast-list message
Yudhi Armyndharis2b8390d6674c
diff --git a/src/engine/adapters/baileys-message-mapper.spec.ts b/src/engine/adapters/baileys-message-mapper.spec.tsindex 90f08609d..677bab5bf 100644--- a/src/engine/adapters/baileys-message-mapper.spec.ts+++ b/src/engine/adapters/baileys-message-mapper.spec.ts@@ -340,6 +340,31 @@ describe('buildIncomingMessageFromBaileys', () => {expect(r.author).toBe('[email protected]');});+ it('exposes the sender of a received broadcast-list message as author and keeps the list as the chat', () => {+ const normalize = (jid: string) => jid.replace('@s.whatsapp.net', '@c.us');+ const r = buildIncomingMessageFromBaileys(+ { ...base, remoteJid: '1700000000@broadcast', participant: '[email protected]' },+ normalize,+ );+ expect(r.chatId).toBe('1700000000@broadcast');+ expect(r.from).toBe('1700000000@broadcast');+ expect(r.isStatusBroadcast).toBe(false);+ expect(r.isGroup).toBe(false);+ expect(r.author).toBe('[email protected]');+ });++ it('keeps the list as the chat for a broadcast-list message the account sent', () => {+ const normalize = (jid: string) => jid.replace('@s.whatsapp.net', '@c.us');+ const r = buildIncomingMessageFromBaileys(+ { ...base, remoteJid: '1700000000@broadcast', fromMe: true, participant: '[email protected]' },+ normalize,+ );+ expect(r.chatId).toBe('1700000000@broadcast');+ expect(r.from).toBe('[email protected]');+ expect(r.to).toBe('1700000000@broadcast');+ expect(r.author).toBe('[email protected]');+ });+it('converts extended-text status styling: backgroundArgb -> #RRGGBB, font passed through', () => {const r = buildIncomingMessageFromBaileys({...base,diff --git a/src/engine/adapters/baileys-message-mapper.ts b/src/engine/adapters/baileys-message-mapper.tsindex 2c0defe39..894cb1ec9 100644--- a/src/engine/adapters/baileys-message-mapper.ts+++ b/src/engine/adapters/baileys-message-mapper.ts@@ -906,10 +906,10 @@ export function mapBaileysStatus(status: number | null | undefined): DeliverySta*/export interface BaileysIncomingFields {id: string;- /** The chat JID (`key.remoteJid`): a contact, a `@g.us` group, or `status@broadcast`. */+ /** The chat JID (`key.remoteJid`): a contact, a `@g.us` group, `status@broadcast`, or a broadcast list. */remoteJid: string;fromMe: boolean;- /** Group sender (`key.participant`); `remoteJid` is the group JID for group messages. */+ /** Sender in a group, status or broadcast list (`key.participant`); `remoteJid` names the chat. */participant?: string;body: string;/** Result of `getContentType(msg.message)`. */@@ -948,8 +948,9 @@ export interface BaileysIncomingFields {/*** Build a neutral {@link IncomingMessage} from extracted Baileys fields. The chat is always* `remoteJid` (Baileys reports the conversation directly); `fromMe` only flips from/to. The group- * sender — and likewise the poster of a status broadcast — lives in `participant` (exposed as- * `author`), matching the wwjs convention where `from` is the group JID / broadcast channel.+ * sender, the poster of a status broadcast and the sender of a broadcast-list message all live in+ * `participant` (exposed as `author`), matching the wwjs convention where `from` is the group JID or+ * the broadcast id.*/export function buildIncomingMessageFromBaileys(fields: BaileysIncomingFields,@@ -980,11 +981,12 @@ export function buildIncomingMessageFromBaileys(isStatusBroadcast,};- // The sender behind a group message — or the poster behind a status broadcast — lives in- // `participant` (exposed as `author`), matching the wwjs convention where `from` is the group JID- // (or the shared status@broadcast channel). Without the status arm, buildIncomingStatus can only- // resolve the poster to the pseudo-JID itself and drops every Baileys status.- if ((isGroup || isStatusBroadcast) && fields.participant) {+ // The sender behind a group message, the poster behind a status broadcast and the sender behind a+ // broadcast-list message all live in `participant` (exposed as `author`), matching the wwjs+ // convention where `from` is the group JID or the `@broadcast` id. Without the status arm,+ // buildIncomingStatus can only resolve the poster to the pseudo-JID itself and drops every Baileys+ // status; without the list arm, a list message names only the list and loses its sender.+ if ((isGroup || rawChatId.endsWith('@broadcast')) && fields.participant) {incoming.author = normalizeJid(fields.participant);}