Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(message): type-check both template identifiers when present

Yudhi Armyndharis24e27052fde3
diff --git a/src/modules/message/dto/send-message.dto.spec.ts b/src/modules/message/dto/send-message.dto.spec.ts
index 4210b7e1f..7410d85a6 100644
--- a/src/modules/message/dto/send-message.dto.spec.ts
+++ b/src/modules/message/dto/send-message.dto.spec.ts
@@ -274,6 +274,28 @@ describe('SendMediaMessageDto base64', () => {
// @nestjs/swagger derives no bounds from the validators, so each one is declared on the decorator;
// without it the published schema advertises an unbounded field the server answers 400 for.
+describe('SendTemplateMessageDto identifiers', () => {
+ // TemplateService.resolve reads templateId first, so a templateName next to it must not switch the
+ // type check off.
+ it('rejects a non-string templateId even when a templateName is present', async () => {
+ const errors = await validateDto(SendTemplateMessageDto, {
+ chatId: '[email protected]',
+ templateId: ['a'],
+ templateName: 'x',
+ });
+ expect(errors.map(e => e.property)).toContain('templateId');
+ });
+
+ it('rejects a non-string templateName even when a templateId is present', async () => {
+ const errors = await validateDto(SendTemplateMessageDto, {
+ chatId: '[email protected]',
+ templateId: 'a',
+ templateName: ['x'],
+ });
+ expect(errors.map(e => e.property)).toContain('templateName');
+ });
+});
+
describe('published schema bounds', () => {
const published = (cls: new () => object, key: string): Record<string, unknown> | undefined =>
Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, cls.prototype as object, key) as
diff --git a/src/modules/message/dto/send-template.dto.ts b/src/modules/message/dto/send-template.dto.ts
index 89e5aeb58..a32bfe854 100644
--- a/src/modules/message/dto/send-template.dto.ts
+++ b/src/modules/message/dto/send-template.dto.ts
@@ -4,7 +4,6 @@ import {
IsNotEmpty,
IsOptional,
IsObject,
- ValidateIf,
IsArray,
ArrayMaxSize,
MaxLength,
@@ -31,7 +30,6 @@ export class SendTemplateMessageDto {
@IsOptional()
@IsString()
@IsNotEmpty()
- @ValidateIf((o: SendTemplateMessageDto) => !o.templateName)
templateId?: string;
@ApiPropertyOptional({
@@ -41,7 +39,6 @@ export class SendTemplateMessageDto {
@IsOptional()
@IsString()
@IsNotEmpty()
- @ValidateIf((o: SendTemplateMessageDto) => !o.templateId)
templateName?: string;
@ApiPropertyOptional({