Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/api/dto/sendMessage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export class Options {
linkPreview?: boolean;
encoding?: boolean;
mentionsEveryOne?: boolean;
/** @deprecated use `mentionsEveryOne` instead. Kept for backward compatibility; will be removed in a future release. */
everyOne?: boolean;
mentioned?: string[];
webhookUrl?: string;
messageId?: string;
Expand Down Expand Up @@ -45,6 +47,8 @@ export class Metadata {
quoted?: Quoted;
linkPreview?: boolean;
mentionsEveryOne?: boolean;
/** @deprecated use `mentionsEveryOne` instead. Kept for backward compatibility; will be removed in a future release. */
everyOne?: boolean;
mentioned?: string[];
encoding?: boolean;
notConvertSticker?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Events, wa } from '@api/types/wa.types';
import { AudioConverter, Chatwoot, ConfigService, Openai, S3 } from '@config/env.config';
import { BadRequestException, InternalServerErrorException } from '@exceptions';
import { createJid } from '@utils/createJid';
import { normalizeFileName } from '@utils/normalizeSendMessageOptions';
import { sendTelemetry } from '@utils/sendTelemetry';
import axios from 'axios';
import { isBase64, isURL } from 'class-validator';
Expand Down Expand Up @@ -607,7 +608,7 @@ export class EvolutionStartupService extends ChannelStartupService {
}

public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
const mediaData: SendMediaDto = { ...data };
const mediaData: SendMediaDto = normalizeFileName({ ...data });

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Events, wa } from '@api/types/wa.types';
import { AudioConverter, Chatwoot, ConfigService, Database, Openai, S3, WaBusiness } from '@config/env.config';
import { BadRequestException, InternalServerErrorException } from '@exceptions';
import { createJid } from '@utils/createJid';
import { normalizeFileName } from '@utils/normalizeSendMessageOptions';
import { status } from '@utils/renderStatus';
import { sendTelemetry } from '@utils/sendTelemetry';
import axios from 'axios';
Expand Down Expand Up @@ -1284,7 +1285,7 @@ export class BusinessStartupService extends ChannelStartupService {
}

public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
const mediaData: SendMediaDto = { ...data };
const mediaData: SendMediaDto = normalizeFileName({ ...data });

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { Instance, Message } from '@prisma/client';
import { createJid } from '@utils/createJid';
import { fetchLatestWaWebVersion } from '@utils/fetchLatestWaWebVersion';
import { makeProxyAgent, makeProxyAgentUndici } from '@utils/makeProxyAgent';
import { normalizeFileName, resolveMentionsEveryOne } from '@utils/normalizeSendMessageOptions';
import { getOnWhatsappCache, saveOnWhatsappCache } from '@utils/onWhatsappCache';
import { status } from '@utils/renderStatus';
import { sendTelemetry } from '@utils/sendTelemetry';
Expand Down Expand Up @@ -2643,7 +2644,7 @@ export class BaileysStartupService extends ChannelStartupService {
throw new NotFoundException('Group not found');
}

if (options?.mentionsEveryOne === true) {
if (resolveMentionsEveryOne(options)) {
mentions = group.participants.map((participant) => participant.id);
} else if (options?.mentioned?.length) {
mentions = options.mentioned.map((mention) => {
Expand Down Expand Up @@ -3265,7 +3266,7 @@ export class BaileysStartupService extends ChannelStartupService {
}

public async mediaMessage(data: SendMediaDto, file?: any, isIntegration = false) {
const mediaData: SendMediaDto = { ...data };
const mediaData: SendMediaDto = normalizeFileName({ ...data });

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

Expand Down
32 changes: 32 additions & 0 deletions src/utils/normalizeSendMessageOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Logger } from '@config/logger.config';

const logger = new Logger('SendMessageOptions');
const warnedAliases = new Set<string>();

const warnOnce = (key: string, message: string) => {
if (warnedAliases.has(key)) return;
warnedAliases.add(key);
logger.warn(message);
};

export const normalizeFileName = <T extends { fileName?: string }>(data: T): T => {
if (!data) return data;
const legacy = (data as any).filename;
if (data.fileName === undefined && legacy !== undefined) {
return { ...data, fileName: legacy };
}
return data;
};

export const resolveMentionsEveryOne = (input: any): boolean => {
if (!input) return false;
if (input.mentionsEveryOne === true) return true;
if (input.everyOne === true) {
warnOnce(
'everyOne',
'"everyOne" is deprecated and will be removed in a future release. Use "mentionsEveryOne" instead.',
);
return true;
}
return false;
};
9 changes: 9 additions & 0 deletions src/validate/message.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const textMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -117,6 +118,7 @@ export const mediaMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand All @@ -143,6 +145,7 @@ export const ptvMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand All @@ -169,6 +172,7 @@ export const audioMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -219,6 +223,7 @@ export const stickerMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -248,6 +253,7 @@ export const locationMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -335,6 +341,7 @@ export const pollMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -392,6 +399,7 @@ export const listMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down Expand Up @@ -443,6 +451,7 @@ export const buttonsMessageSchema: JSONSchema7 = {
},
quoted: { ...quotedOptionsSchema },
mentionsEveryOne: { type: 'boolean', enum: [true, false] },
everyOne: { type: 'boolean', enum: [true, false], description: 'Deprecated alias for "mentionsEveryOne".' },
mentioned: {
type: 'array',
minItems: 1,
Expand Down
Loading