Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): pass the bulk recipient to message:sending and failed
Yudhi Armyndharis65dcacd19804
diff --git a/src/modules/message/bulk-message.service.spec.ts b/src/modules/message/bulk-message.service.spec.tsindex 23720ae53..64ea3730a 100644--- a/src/modules/message/bulk-message.service.spec.ts+++ b/src/modules/message/bulk-message.service.spec.ts@@ -652,14 +652,24 @@ describe('BulkMessageService.processBatch', () => {await runProcessBatch();+ // The recipient is in `input`, as on a single send, so a recipient-based plugin can decide.expect(hookManager.execute).toHaveBeenCalledWith('message:sending',- expect.objectContaining({ type: 'text', sessionId: 's1' }),+ expect.objectContaining({ type: 'text', sessionId: 's1', input: { text: 'hi', chatId: '[email protected]' } }),expect.objectContaining({ source: 'BulkMessageService' }),);expect(engine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hi');});+ it('keeps sending an item to its own recipient when the gate rewrites input.chatId', async () => {+ repo.findOne.mockResolvedValue(makeBatch(1));+ hookManager.execute.mockResolvedValueOnce({ continue: true, data: { input: { text: 'hi', chatId: '[email protected]' } } });++ await runProcessBatch();++ expect(engine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hi');+ });+it('fails just the plugin-blocked message (continue:false) without calling the engine for it', async () => {repo.findOne.mockResolvedValue(makeBatch(1));hookManager.execute.mockResolvedValueOnce({ continue: false, data: {} }); // block message 0@@ -677,7 +687,7 @@ describe('BulkMessageService.processBatch', () => {expect(hookManager.execute).toHaveBeenCalledWith('message:failed',- expect.objectContaining({ type: 'text', error: 'boom' }),+ expect.objectContaining({ type: 'text', error: 'boom', input: { text: 'hi', chatId: '[email protected]' } }),expect.objectContaining({ source: 'BulkMessageService' }),);});diff --git a/src/modules/message/bulk-message.service.ts b/src/modules/message/bulk-message.service.tsindex b931eb41e..959a0a460 100644--- a/src/modules/message/bulk-message.service.ts+++ b/src/modules/message/bulk-message.service.ts@@ -464,9 +464,11 @@ export class BulkMessageService implements OnApplicationBootstrap {// Per-message moderation gate — the SAME message:sending hook single sends use, so a// compliance/moderation plugin sees bulk traffic too (bulk previously bypassed it entirely).// A block fails just THIS message (honouring stopOnError below); a plugin may also rewrite it.+ // `input` carries the recipient like a single send's DTO does, so a recipient-based plugin can+ // decide; a rewritten chatId is ignored, the item always goes to its own msg.chatId.const gate = await this.hookManager.execute('message:sending',- { sessionId: batch.sessionId, input: content, type: msg.type },+ { sessionId: batch.sessionId, input: { ...content, chatId: msg.chatId }, type: msg.type },{ sessionId: batch.sessionId, source: 'BulkMessageService' },);if (!gate.continue) {@@ -551,7 +553,12 @@ export class BulkMessageService implements OnApplicationBootstrap {if (!blockedByPlugin && !isPacingLimitedError(error)) {await this.hookManager.execute('message:failed',- { sessionId: batch.sessionId, error: sanitized.message, input: content, type: msg.type },+ {+ sessionId: batch.sessionId,+ error: sanitized.message,+ input: { ...content, chatId: msg.chatId },+ type: msg.type,+ },{ sessionId: batch.sessionId, source: 'BulkMessageService' },);}