Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): stop holding an edit against the daily send cap
Yudhi Armyndharisa10deeee34e8
diff --git a/src/modules/message/message.service.spec.ts b/src/modules/message/message.service.spec.tsindex 462648b89..0360e4970 100644--- a/src/modules/message/message.service.spec.ts+++ b/src/modules/message/message.service.spec.ts@@ -71,6 +71,7 @@ describe('MessageService', () => {let hookManager: jest.Mocked<Partial<HookManager>>;let lidMappingStore: { findLidsForPhone: jest.Mock; findPhoneForLid: jest.Mock };let mockEngine: ReturnType<typeof createMockEngine>;+ let pacing: SendPacingService;beforeEach(async () => {repository = {@@ -128,6 +129,7 @@ describe('MessageService', () => {}).compile();service = module.get<MessageService>(MessageService);+ pacing = module.get(SendPacingService);});// ── outbound send delegation ──────────────────────────────────────@@ -852,6 +854,14 @@ describe('MessageService', () => {);});+ // An edit only UPDATEs the existing row, so it is judged against the caps but never held in the+ // admission window: holding it would charge the day's allowance for a message that is not sent.+ it('checks an edit against the pacing caps without holding it', async () => {+ await service.editMessage('sess-1', { chatId: '[email protected]', messageId: 'wa-msg-1', body: 'edited' });++ expect(jest.mocked(pacing.assertSendAllowed)).toHaveBeenCalledWith('sess-1', '[email protected]', { hold: false });+ });+it('lets a plugin block an edit before the engine is called', async () => {(hookManager.execute as jest.Mock).mockResolvedValueOnce({ continue: false, data: {} });diff --git a/src/modules/message/message.service.ts b/src/modules/message/message.service.tsindex a3651584b..a03e58d99 100644--- a/src/modules/message/message.service.ts+++ b/src/modules/message/message.service.ts@@ -693,9 +693,10 @@ export class MessageService implements PluginMessagePort {// Every gated sender's DTO addresses its destination as `chatId` except forward, which uses// `toChatId` — without the fallback a forward skipped the cold-reachout gate entirely, while// its persisted row still drained the cold budget. Edit carries a chatId too; the edited- // message's own row already makes that chat warm, so the gate is a no-op there.+ // message's own row already makes that chat warm, so the cold rule is a no-op there. An edit+ // writes no row, so it is judged against the caps without being held as a new send.const target = input as { chatId?: string; toChatId?: string };- await this.pacing.assertSendAllowed(sessionId, target.chatId ?? target.toChatId);+ await this.pacing.assertSendAllowed(sessionId, target.chatId ?? target.toChatId, { hold: false });return applySendingGate(this.hookManager, sessionId, type, input, 'MessageService');}