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
This commit is contained in:
Davidson Gomes 2024-06-26 17:27:38 -03:00
parent 0ded76d366
commit 99f4fe2e43
3 changed files with 43 additions and 77 deletions

View File

@ -5,18 +5,14 @@ export class Quoted {
message: proto.IMessage; message: proto.IMessage;
} }
export class Mentions {
everyOne?: boolean;
mentioned?: string[];
}
export class Options { export class Options {
delay?: number; delay?: number;
presence?: WAPresence; presence?: WAPresence;
quoted?: Quoted; quoted?: Quoted;
mentions?: Mentions;
linkPreview?: boolean; linkPreview?: boolean;
encoding?: boolean; encoding?: boolean;
mentionsEveryOne?: boolean;
mentioned?: string[];
} }
export class MediaMessage { export class MediaMessage {
@ -44,7 +40,7 @@ export class Metadata {
delay?: number; delay?: number;
quoted?: Quoted; quoted?: Quoted;
linkPreview?: boolean; linkPreview?: boolean;
everyOne?: boolean; mentionsEveryOne?: boolean;
mentioned?: string[]; mentioned?: string[];
encoding?: boolean; encoding?: boolean;
} }

View File

@ -1831,26 +1831,24 @@ export class BaileysStartupService extends ChannelStartupService {
throw new NotFoundException('Group not found'); throw new NotFoundException('Group not found');
} }
if (options?.mentions) { console.log('options', options);
if (options.mentions?.everyOne) {
mentions = group.participants.map((participant) => participant.id); if (options.mentionsEveryOne) {
} else if (options.mentions?.mentioned?.length) { mentions = group.participants.map((participant) => participant.id);
mentions = options.mentions.mentioned.map((mention) => { } else if (options.mentioned?.length) {
const jid = this.createJid(mention); mentions = options.mentioned.map((mention) => {
if (isJidGroup(jid)) { const jid = this.createJid(mention);
return null; if (isJidGroup(jid)) {
} return null;
return jid; }
}); return jid;
} });
} }
} catch (error) { } catch (error) {
throw new NotFoundException('Group not found'); throw new NotFoundException('Group not found');
} }
} }
console.log('message', message);
const messageSent = await (async () => { const messageSent = await (async () => {
const option = { const option = {
quoted, quoted,
@ -2073,10 +2071,8 @@ export class BaileysStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -2097,10 +2093,8 @@ export class BaileysStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }
@ -2352,10 +2346,8 @@ export class BaileysStartupService extends ChannelStartupService {
delay: data?.delay, delay: data?.delay,
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
@ -2374,10 +2366,8 @@ export class BaileysStartupService extends ChannelStartupService {
delay: data?.delay, delay: data?.delay,
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -2541,10 +2531,8 @@ export class BaileysStartupService extends ChannelStartupService {
delay: data?.delay, delay: data?.delay,
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }
@ -2566,10 +2554,8 @@ export class BaileysStartupService extends ChannelStartupService {
delay: data?.delay, delay: data?.delay,
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }

View File

@ -853,10 +853,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -938,10 +936,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -986,10 +982,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -1027,10 +1021,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }
@ -1051,10 +1043,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }
@ -1093,10 +1083,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }
@ -1116,10 +1104,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
isIntegration, isIntegration,
); );
@ -1188,10 +1174,8 @@ export class BusinessStartupService extends ChannelStartupService {
presence: 'composing', presence: 'composing',
quoted: data?.quoted, quoted: data?.quoted,
linkPreview: data?.linkPreview, linkPreview: data?.linkPreview,
mentions: { mentionsEveryOne: data?.mentionsEveryOne,
everyOne: data?.everyOne, mentioned: data?.mentioned,
mentioned: data?.mentioned,
},
}, },
); );
} }