Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): persist the bulk item's own media and caption
Yudhi Armyndharis388cb8289e57
diff --git a/src/modules/message/bulk-message.service.spec.ts b/src/modules/message/bulk-message.service.spec.tsindex 789736399..7036dd7e1 100644--- a/src/modules/message/bulk-message.service.spec.ts+++ b/src/modules/message/bulk-message.service.spec.ts@@ -575,6 +575,40 @@ describe('BulkMessageService.processBatch', () => {);});+ it('persists the media and caption the item type sent, not a stray key on the same item', async () => {+ engine.sendVideoMessage = jest.fn().mockResolvedValue({ id: 'wa1', timestamp: 111 });+ const batch = makeBatch(2);+ batch.messages = [+ {+ chatId: '[email protected]',+ type: 'video',+ content: {+ text: 'not sent',+ caption: 'clip',+ image: { url: 'https://x/y.jpg', mimetype: 'image/jpeg' },+ video: { base64: 'AAAA', mimetype: 'video/mp4' },+ },+ },+ { chatId: '[email protected]', type: 'text', content: { text: 'hi', image: { url: 'https://x/y.jpg' } } },+ ];+ repo.findOne.mockResolvedValue(batch);++ await runProcessBatch();++ expect(messageService.saveOutgoingMessage).toHaveBeenCalledWith(+ 's1',+ expect.objectContaining({+ chatId: '[email protected]',+ body: 'clip',+ metadata: { media: { mimetype: 'video/mp4', data: 'AAAA', filename: undefined } },+ }),+ );+ expect(messageService.saveOutgoingMessage).toHaveBeenCalledWith(+ 's1',+ expect.objectContaining({ chatId: '[email protected]', body: 'hi', metadata: undefined }),+ );+ });+it('runs the message:sending gate for each bulk message (bulk no longer bypasses moderation)', async () => {repo.findOne.mockResolvedValue(makeBatch(1));diff --git a/src/modules/message/bulk-message.service.ts b/src/modules/message/bulk-message.service.tsindex 6df246895..bedf68220 100644--- a/src/modules/message/bulk-message.service.ts+++ b/src/modules/message/bulk-message.service.ts@@ -762,14 +762,17 @@ export class BulkMessageService implements OnApplicationBootstrap {content: BulkMessageContent,result: MessageResult,): Promise<void> {- const media = content.image ?? content.video ?? content.audio ?? content.document;+ // Store what sendMessage sent: the media under the item's own type key, and the caption for a+ // media item (audio carries none). Other keys on the item were never delivered.+ const media = type === 'text' ? undefined : content[type as 'image' | 'video' | 'audio' | 'document'];+ const body = type === 'text' ? content.text : type === 'audio' ? undefined : content.caption;// A bulk audio item flagged ptt is a voice note; store it in the 'voice' bucket like inbound PTT.const persistType = type === 'audio' && content.audio?.ptt ? 'voice' : type;try {await this.messageService.saveOutgoingMessage(sessionId, {waMessageId: result.id,chatId,- body: content.text ?? content.caption ?? '',+ body: body ?? '',type: persistType,timestamp: result.timestamp,status: MessageStatus.SENT,