Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(message): publish the mentions, filename and preview url caps
Yudhi Armyndharis634a4ae1febe
diff --git a/src/modules/message/dto/send-message.dto.spec.ts b/src/modules/message/dto/send-message.dto.spec.tsindex 48680155b..4210b7e1f 100644--- a/src/modules/message/dto/send-message.dto.spec.ts+++ b/src/modules/message/dto/send-message.dto.spec.ts@@ -1,6 +1,8 @@+import { DECORATORS } from '@nestjs/swagger';import { plainToInstance } from 'class-transformer';import { validate } from 'class-validator';import {+ CustomLinkPreviewDto,SendTextMessageDto,SendMediaMessageDto,SendAudioMessageDto,@@ -15,6 +17,7 @@ import {SEND_POLL_BODY_EXAMPLES,} from './send-message.dto';import { SendLocationDto, SendContactDto, SendPollDto } from './message-actions.dto';+import { SendTemplateMessageDto } from './send-template.dto';import { GLOBAL_VALIDATION_OPTIONS } from '../../../config/app-validation';// Read the production pipe's own options rather than restating them, so these cases cannot assert a@@ -268,3 +271,23 @@ describe('SendMediaMessageDto base64', () => {expect(errors.map(e => e.property)).toContain('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('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+ Record<string, unknown> | undefined;++ it.each([SendTextMessageDto, SendMediaMessageDto, SendTemplateMessageDto])('%p bounds mentions', cls => {+ expect(published(cls, 'mentions')).toMatchObject({+ maxItems: 1024,+ items: { type: 'string', maxLength: 64 },+ });+ });++ it('bounds the media filename and the custom preview url', () => {+ expect(published(SendMediaMessageDto, 'filename')?.maxLength).toBe(255);+ expect(published(CustomLinkPreviewDto, 'url')?.maxLength).toBe(2048);+ });+});diff --git a/src/modules/message/dto/send-message.dto.ts b/src/modules/message/dto/send-message.dto.tsindex 00a3c4e8d..31eca12e1 100644--- a/src/modules/message/dto/send-message.dto.ts+++ b/src/modules/message/dto/send-message.dto.ts@@ -63,6 +63,7 @@ export class CustomLinkPreviewDto {@ApiProperty({description: 'The URL as it appears in the message text — WhatsApp anchors the preview to it.',example: 'https://example.com/launch',+ maxLength: CUSTOM_PREVIEW_URL_MAX_LENGTH,})@IsString()@IsNotEmpty()@@ -105,7 +106,13 @@ export class SendTextMessageDto {@MaxLength(MESSAGE_TEXT_MAX_LENGTH)text!: string;- @ApiPropertyOptional({ description: MENTIONS_DESCRIPTION, example: ['[email protected]'], type: [String] })+ @ApiPropertyOptional({+ description: MENTIONS_DESCRIPTION,+ example: ['[email protected]'],+ type: [String],+ maxItems: MENTIONS_MAX,+ items: { type: 'string', maxLength: MENTION_WID_MAX_LENGTH },+ })@IsOptional()@IsArray()@ArrayMaxSize(MENTIONS_MAX)@@ -217,6 +224,7 @@ export class SendMediaMessageDto {description:"Filename for the media. Only rendered on document sends — defaults to 'file' when omitted (a URL-based document send on whatsapp-web.js first derives the URL basename)",example: 'image.jpg',+ maxLength: 255,})@IsOptional()@IsString()@@ -233,7 +241,13 @@ export class SendMediaMessageDto {@MaxLength(1024)caption?: string;- @ApiPropertyOptional({ description: MENTIONS_DESCRIPTION, example: ['[email protected]'], type: [String] })+ @ApiPropertyOptional({+ description: MENTIONS_DESCRIPTION,+ example: ['[email protected]'],+ type: [String],+ maxItems: MENTIONS_MAX,+ items: { type: 'string', maxLength: MENTION_WID_MAX_LENGTH },+ })@IsOptional()@IsArray()@ArrayMaxSize(MENTIONS_MAX)diff --git a/src/modules/message/dto/send-template.dto.ts b/src/modules/message/dto/send-template.dto.tsindex bfb955c46..89e5aeb58 100644--- a/src/modules/message/dto/send-template.dto.ts+++ b/src/modules/message/dto/send-template.dto.ts@@ -55,7 +55,13 @@ export class SendTemplateMessageDto {// The rendered body is dispatched through the same path as send-text, so it carries the same two// optionals. `quotedMessageId` is deliberately NOT among them: docs/06 publishes this route as one// that rejects it.- @ApiPropertyOptional({ description: MENTIONS_DESCRIPTION, example: ['[email protected]'], type: [String] })+ @ApiPropertyOptional({+ description: MENTIONS_DESCRIPTION,+ example: ['[email protected]'],+ type: [String],+ maxItems: MENTIONS_MAX,+ items: { type: 'string', maxLength: MENTION_WID_MAX_LENGTH },+ })@IsOptional()@IsArray()@ArrayMaxSize(MENTIONS_MAX)