From 99f4fe2e4374552db237039b84abff8d35dd6295 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 26 Jun 2024 17:27:38 -0300 Subject: [PATCH] fix: Ghost emoji correction in message sending Corrects an issue where a ghost emoji was being displayed in message sending. The 'Mentions' class was removed and its properties were moved to the 'Options' class. The 'everyOne' and 'mentioned' properties were replaced by 'mentionsEveryOne' and 'mentioned', respectively. This change improves the code readability and maintainability. The affected files are: - src/api/dto/sendMessage.dto.ts - src/api/services/channels/whatsapp.baileys.service.ts - src/api/services/channels/whatsapp.business.service.ts --- src/api/dto/sendMessage.dto.ts | 10 +-- .../channels/whatsapp.baileys.service.ts | 62 +++++++------------ .../channels/whatsapp.business.service.ts | 48 +++++--------- 3 files changed, 43 insertions(+), 77 deletions(-) diff --git a/src/api/dto/sendMessage.dto.ts b/src/api/dto/sendMessage.dto.ts index ef922ae1..46839366 100644 --- a/src/api/dto/sendMessage.dto.ts +++ b/src/api/dto/sendMessage.dto.ts @@ -5,18 +5,14 @@ export class Quoted { message: proto.IMessage; } -export class Mentions { - everyOne?: boolean; - mentioned?: string[]; -} - export class Options { delay?: number; presence?: WAPresence; quoted?: Quoted; - mentions?: Mentions; linkPreview?: boolean; encoding?: boolean; + mentionsEveryOne?: boolean; + mentioned?: string[]; } export class MediaMessage { @@ -44,7 +40,7 @@ export class Metadata { delay?: number; quoted?: Quoted; linkPreview?: boolean; - everyOne?: boolean; + mentionsEveryOne?: boolean; mentioned?: string[]; encoding?: boolean; } diff --git a/src/api/services/channels/whatsapp.baileys.service.ts b/src/api/services/channels/whatsapp.baileys.service.ts index 49271d69..ac356b5c 100644 --- a/src/api/services/channels/whatsapp.baileys.service.ts +++ b/src/api/services/channels/whatsapp.baileys.service.ts @@ -1831,26 +1831,24 @@ export class BaileysStartupService extends ChannelStartupService { throw new NotFoundException('Group not found'); } - if (options?.mentions) { - if (options.mentions?.everyOne) { - mentions = group.participants.map((participant) => participant.id); - } else if (options.mentions?.mentioned?.length) { - mentions = options.mentions.mentioned.map((mention) => { - const jid = this.createJid(mention); - if (isJidGroup(jid)) { - return null; - } - return jid; - }); - } + console.log('options', options); + + if (options.mentionsEveryOne) { + mentions = group.participants.map((participant) => participant.id); + } else if (options.mentioned?.length) { + mentions = options.mentioned.map((mention) => { + const jid = this.createJid(mention); + if (isJidGroup(jid)) { + return null; + } + return jid; + }); } } catch (error) { throw new NotFoundException('Group not found'); } } - console.log('message', message); - const messageSent = await (async () => { const option = { quoted, @@ -2073,10 +2071,8 @@ export class BaileysStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -2097,10 +2093,8 @@ export class BaileysStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } @@ -2352,10 +2346,8 @@ export class BaileysStartupService extends ChannelStartupService { delay: data?.delay, presence: 'composing', quoted: data?.quoted, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); @@ -2374,10 +2366,8 @@ export class BaileysStartupService extends ChannelStartupService { delay: data?.delay, presence: 'composing', quoted: data?.quoted, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -2541,10 +2531,8 @@ export class BaileysStartupService extends ChannelStartupService { delay: data?.delay, presence: 'composing', quoted: data?.quoted, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } @@ -2566,10 +2554,8 @@ export class BaileysStartupService extends ChannelStartupService { delay: data?.delay, presence: 'composing', quoted: data?.quoted, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } diff --git a/src/api/services/channels/whatsapp.business.service.ts b/src/api/services/channels/whatsapp.business.service.ts index cc0cd893..4f51c9b6 100644 --- a/src/api/services/channels/whatsapp.business.service.ts +++ b/src/api/services/channels/whatsapp.business.service.ts @@ -853,10 +853,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -938,10 +936,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -986,10 +982,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -1027,10 +1021,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } @@ -1051,10 +1043,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } @@ -1093,10 +1083,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); } @@ -1116,10 +1104,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, isIntegration, ); @@ -1188,10 +1174,8 @@ export class BusinessStartupService extends ChannelStartupService { presence: 'composing', quoted: data?.quoted, linkPreview: data?.linkPreview, - mentions: { - everyOne: data?.everyOne, - mentioned: data?.mentioned, - }, + mentionsEveryOne: data?.mentionsEveryOne, + mentioned: data?.mentioned, }, ); }