Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(message): charge a bare number and its qualified twin as one contact
Yudhi Armyndharisda5d7cf91d03
diff --git a/src/modules/message/send-pacing-cold-query.spec.ts b/src/modules/message/send-pacing-cold-query.spec.tsindex 56bd45f8d..48929dbc1 100644--- a/src/modules/message/send-pacing-cold-query.spec.ts+++ b/src/modules/message/send-pacing-cold-query.spec.ts@@ -286,6 +286,11 @@ describe('group reachouts against a real database', () => {await expect(reachout('s1', ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]'])).resolves.toBeUndefined();});+ // A bare number and its qualified form are the same contact: the engines qualify it themselves.+ it('counts a bare number and its qualified form once', async () => {+ await expect(reachout('s1', ['628111', '[email protected]', '628222', '[email protected]', '[email protected]'])).resolves.toBeUndefined();+ });+// The two paths share one budget, so a day spent on direct messages leaves nothing for group adds.it("shares the day's budget with cold sends already made", async () => {await addMessage('[email protected]', TODAY);diff --git a/src/modules/message/send-pacing.service.ts b/src/modules/message/send-pacing.service.tsindex 627961e6b..fc0a6ef9a 100644--- a/src/modules/message/send-pacing.service.ts+++ b/src/modules/message/send-pacing.service.ts@@ -12,6 +12,7 @@ import { EngineNotSupportedError } from '../../common/errors/engine-not-supporteimport { EngineThrottledError } from '../../common/errors/engine-throttled.error';import { EngineNotSentError } from '../../common/errors/engine-not-sent.error';import { SsrfBlockedError } from '../../common/security/ssrf-guard';+import { toParticipantWid } from '../../engine/identity/wa-id';import { AuditService } from '../audit/audit.service';import { AuditAction } from '../audit/entities/audit-log.entity';@@ -410,7 +411,7 @@ export class SendPacingService {// The same id twice in one request is one contact, and must cost one. Each contact is probed// under both user-id dialects (see dialectVariants) — a contact known under the other spelling// is not a stranger.- const unique = [...new Set(contactIds)];+ const unique = [...new Set(contactIds.map(toParticipantWid))];const variantsByContact = new Map(unique.map(id => [id, dialectVariants(id)]));const knownRows = await this.messageRepository.createQueryBuilder('m')