Skip to content

Commit

Permalink
fix: Ghost emoji correction in message sending
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dgcode-tec committed Jun 26, 2024
1 parent 0ded76d commit 99f4fe2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 77 deletions.
10 changes: 3 additions & 7 deletions src/api/dto/sendMessage.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -44,7 +40,7 @@ export class Metadata {
delay?: number;
quoted?: Quoted;
linkPreview?: boolean;
everyOne?: boolean;
mentionsEveryOne?: boolean;
mentioned?: string[];
encoding?: boolean;
}
Expand Down
62 changes: 24 additions & 38 deletions src/api/services/channels/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
);
Expand All @@ -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,
},
);
}
Expand Down Expand Up @@ -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,
},
);

Expand All @@ -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,
);
Expand Down Expand Up @@ -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,
},
);
}
Expand All @@ -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,
},
);
}
Expand Down
48 changes: 16 additions & 32 deletions src/api/services/channels/whatsapp.business.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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,
},
);
}
Expand All @@ -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,
},
);
}
Expand Down Expand Up @@ -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,
},
);
}
Expand All @@ -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,
);
Expand Down Expand Up @@ -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,
},
);
}
Expand Down

0 comments on commit 99f4fe2

Please sign in to comment.