Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
refactor(message): read template variable names from the shared renderer
Yudhi Armyndharis46ef1facbb25
diff --git a/src/modules/message/batch-media.util.ts b/src/modules/message/batch-media.util.tsindex 2e2dcd96d..d2d65c546 100644--- a/src/modules/message/batch-media.util.ts+++ b/src/modules/message/batch-media.util.ts@@ -1,14 +1,7 @@import { DataSource, In, QueryDeepPartialEntity } from 'typeorm';+import { templateVariableNames } from '../../common/utils/template-render';import { BatchStatus, MessageBatch } from './entities/message-batch.entity';-/**- * The names a template body asks for, in the renderer's own syntax: canonical `{{ name }}` and the- * legacy `{name}` (see PLACEHOLDER_PATTERN in common/utils/template-render.ts, which a spec keeps in step).- */-export function templateVariableNames(body: string): string[] {- return Array.from(body.matchAll(/\{\{\s*([\w.-]+)\s*\}\}|\{(\w+)\}/g), match => match[1] ?? match[2]);-}-/*** Drop base64 payloads from a finished batch's stored message list. A completed/cancelled batch is* terminal (never resumed), so the (often multi-MB) base64 in `message_batches.messages` is deaddiff --git a/src/modules/message/bulk-media-variables.spec.ts b/src/modules/message/bulk-media-variables.spec.tsindex b8fdbf1dd..60abab1a3 100644--- a/src/modules/message/bulk-media-variables.spec.ts+++ b/src/modules/message/bulk-media-variables.spec.ts@@ -7,8 +7,7 @@ import { BulkMessageService } from './bulk-message.service';import { MessageBatch, BatchStatus } from './entities/message-batch.entity';import { Message } from './entities/message.entity';import type { MessageService } from './message.service';-import { renderTemplate } from '../../common/utils/template-render';-import { templateVariableNames } from './batch-media.util';+import { renderTemplate, templateVariableNames } from '../../common/utils/template-render';import type { SendPacingService } from './send-pacing.service';describe('bulk media variable cleanup', () => {diff --git a/src/modules/message/dto/bulk-message.dto.ts b/src/modules/message/dto/bulk-message.dto.tsindex 97e5ce45c..273c28506 100644--- a/src/modules/message/dto/bulk-message.dto.ts+++ b/src/modules/message/dto/bulk-message.dto.ts@@ -29,7 +29,7 @@ import {} from './send-message.dto';import { isMentionWid } from './is-mention-wid.validator';import { BatchMessageStatus, BatchStatus } from '../entities/message-batch.entity';-import { templateVariableNames } from '../batch-media.util';+import { templateVariableNames } from '../../../common/utils/template-render';/*** A bulk mention is a WID or a placeholder that the item's `variables` fill in, so one batch can tag a