Skip to content

Commit 06d5057

Browse files
enzowilliamclaude
andcommitted
refactor: extract send-message normalization helpers and keep everyOne as deprecated alias
- Add src/utils/normalizeSendMessageOptions.ts with normalizeFileName (uses undefined-check so intentional empty fileName is preserved) and resolveMentionsEveryOne (accepts everyOne alias and logs a one-shot deprecation warning). - Apply normalizeFileName in baileys, evolution and meta mediaMessage services, removing the duplicated (data as any).filename cast. - Restore backward compatibility for everyOne: schemas accept it as a deprecated alias, DTOs expose it as @deprecated, and baileys uses resolveMentionsEveryOne when computing mentions. - Fix unrelated axios AxiosHeaderValue type errors surfacing in pre-commit tsc (baileys + chatwoot content-type header casts). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ac9fd35 commit 06d5057

6 files changed

Lines changed: 52 additions & 16 deletions

File tree

src/api/dto/sendMessage.dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export class Options {
1212
linkPreview?: boolean;
1313
encoding?: boolean;
1414
mentionsEveryOne?: boolean;
15+
/** @deprecated use `mentionsEveryOne` instead. Kept for backward compatibility; will be removed in a future release. */
16+
everyOne?: boolean;
1517
mentioned?: string[];
1618
webhookUrl?: string;
1719
messageId?: string;
@@ -45,6 +47,8 @@ export class Metadata {
4547
quoted?: Quoted;
4648
linkPreview?: boolean;
4749
mentionsEveryOne?: boolean;
50+
/** @deprecated use `mentionsEveryOne` instead. Kept for backward compatibility; will be removed in a future release. */
51+
everyOne?: boolean;
4852
mentioned?: string[];
4953
encoding?: boolean;
5054
notConvertSticker?: boolean;

src/api/integrations/channel/evolution/evolution.channel.service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Events, wa } from '@api/types/wa.types';
1616
import { AudioConverter, Chatwoot, ConfigService, Openai, S3 } from '@config/env.config';
1717
import { BadRequestException, InternalServerErrorException } from '@exceptions';
1818
import { createJid } from '@utils/createJid';
19+
import { normalizeFileName } from '@utils/normalizeSendMessageOptions';
1920
import { sendTelemetry } from '@utils/sendTelemetry';
2021
import axios from 'axios';
2122
import { isBase64, isURL } from 'class-validator';
@@ -607,11 +608,7 @@ export class EvolutionStartupService extends ChannelStartupService {
607608
}
608609

609610
public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
610-
const mediaData: SendMediaDto = {
611-
...data,
612-
// Normalize filename to fileName (handle case-insensitivity)
613-
fileName: data.fileName || (data as any).filename,
614-
};
611+
const mediaData: SendMediaDto = normalizeFileName({ ...data });
615612

616613
if (file) mediaData.media = file.buffer.toString('base64');
617614

src/api/integrations/channel/meta/whatsapp.business.service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Events, wa } from '@api/types/wa.types';
2323
import { AudioConverter, Chatwoot, ConfigService, Database, Openai, S3, WaBusiness } from '@config/env.config';
2424
import { BadRequestException, InternalServerErrorException } from '@exceptions';
2525
import { createJid } from '@utils/createJid';
26+
import { normalizeFileName } from '@utils/normalizeSendMessageOptions';
2627
import { status } from '@utils/renderStatus';
2728
import { sendTelemetry } from '@utils/sendTelemetry';
2829
import axios from 'axios';
@@ -1284,11 +1285,7 @@ export class BusinessStartupService extends ChannelStartupService {
12841285
}
12851286

12861287
public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
1287-
const mediaData: SendMediaDto = {
1288-
...data,
1289-
// Normalize filename to fileName (handle case-insensitivity)
1290-
fileName: data.fileName || (data as any).filename,
1291-
};
1288+
const mediaData: SendMediaDto = normalizeFileName({ ...data });
12921289

12931290
if (file) mediaData.media = file.buffer.toString('base64');
12941291

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import { Instance, Message } from '@prisma/client';
8686
import { createJid } from '@utils/createJid';
8787
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
8888
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
89+
import { normalizeFileName, resolveMentionsEveryOne } from '@utils/normalizeSendMessageOptions';
8990
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
9091
import { status } from '@utils/renderStatus';
9192
import { sendTelemetry } from '@utils/sendTelemetry';
@@ -2643,7 +2644,7 @@ export class BaileysStartupService extends ChannelStartupService {
26432644
throw new NotFoundException('Group not found');
26442645
}
26452646

2646-
if (options?.mentionsEveryOne === true) {
2647+
if (resolveMentionsEveryOne(options)) {
26472648
mentions = group.participants.map((participant) => participant.id);
26482649
} else if (options?.mentioned?.length) {
26492650
mentions = options.mentioned.map((mention) => {
@@ -3265,11 +3266,7 @@ export class BaileysStartupService extends ChannelStartupService {
32653266
}
32663267

32673268
public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
3268-
const mediaData: SendMediaDto = {
3269-
...data,
3270-
// Normalize filename to fileName (handle case-insensitivity)
3271-
fileName: data.fileName || (data as any).filename,
3272-
};
3269+
const mediaData: SendMediaDto = normalizeFileName({ ...data });
32733270

32743271
if (file) mediaData.media = file.buffer.toString('base64');
32753272

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Logger } from '@config/logger.config';
2+
3+
const logger = new Logger('SendMessageOptions');
4+
const warnedAliases = new Set<string>();
5+
6+
const warnOnce = (key: string, message: string) => {
7+
if (warnedAliases.has(key)) return;
8+
warnedAliases.add(key);
9+
logger.warn(message);
10+
};
11+
12+
export const normalizeFileName = <T extends { fileName?: string }>(data: T): T => {
13+
if (!data) return data;
14+
const legacy = (data as any).filename;
15+
if (data.fileName === undefined && legacy !== undefined) {
16+
return { ...data, fileName: legacy };
17+
}
18+
return data;
19+
};
20+
21+
export const resolveMentionsEveryOne = (input: any): boolean => {
22+
if (!input) return false;
23+
if (input.mentionsEveryOne === true) return true;
24+
if (input.everyOne === true) {
25+
warnOnce(
26+
'everyOne',
27+
'"everyOne" is deprecated and will be removed in a future release. Use "mentionsEveryOne" instead.',
28+
);
29+
return true;
30+
}
31+
return false;
32+
};

src/validate/message.schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const textMessageSchema: JSONSchema7 = {
7878
},
7979
quoted: { ...quotedOptionsSchema },
8080
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
81+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
8182
mentioned: {
8283
type: 'array',
8384
minItems: 1,
@@ -117,6 +118,7 @@ export const mediaMessageSchema: JSONSchema7 = {
117118
},
118119
quoted: { ...quotedOptionsSchema },
119120
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
121+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
120122
mentioned: {
121123
type: 'array',
122124
minItems: 1,
@@ -143,6 +145,7 @@ export const ptvMessageSchema: JSONSchema7 = {
143145
},
144146
quoted: { ...quotedOptionsSchema },
145147
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
148+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
146149
mentioned: {
147150
type: 'array',
148151
minItems: 1,
@@ -169,6 +172,7 @@ export const audioMessageSchema: JSONSchema7 = {
169172
},
170173
quoted: { ...quotedOptionsSchema },
171174
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
175+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
172176
mentioned: {
173177
type: 'array',
174178
minItems: 1,
@@ -219,6 +223,7 @@ export const stickerMessageSchema: JSONSchema7 = {
219223
},
220224
quoted: { ...quotedOptionsSchema },
221225
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
226+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
222227
mentioned: {
223228
type: 'array',
224229
minItems: 1,
@@ -248,6 +253,7 @@ export const locationMessageSchema: JSONSchema7 = {
248253
},
249254
quoted: { ...quotedOptionsSchema },
250255
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
256+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
251257
mentioned: {
252258
type: 'array',
253259
minItems: 1,
@@ -335,6 +341,7 @@ export const pollMessageSchema: JSONSchema7 = {
335341
},
336342
quoted: { ...quotedOptionsSchema },
337343
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
344+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
338345
mentioned: {
339346
type: 'array',
340347
minItems: 1,
@@ -392,6 +399,7 @@ export const listMessageSchema: JSONSchema7 = {
392399
},
393400
quoted: { ...quotedOptionsSchema },
394401
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
402+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
395403
mentioned: {
396404
type: 'array',
397405
minItems: 1,
@@ -443,6 +451,7 @@ export const buttonsMessageSchema: JSONSchema7 = {
443451
},
444452
quoted: { ...quotedOptionsSchema },
445453
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
454+
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
446455
mentioned: {
447456
type: 'array',
448457
minItems: 1,

0 commit comments

Comments
 (0)