Skip to content
Merged
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
34 changes: 26 additions & 8 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3437,16 +3437,34 @@ export class BaileysStartupService extends ChannelStartupService {
let mediaMessage: any;
let mediaType: string;

for (const type of TypeMediaMessage) {
mediaMessage = msg.message[type];
if (mediaMessage) {
mediaType = type;
break;
if (msg.message?.templateMessage) {
const template =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Potential edge case if both hydratedTemplate and hydratedFourRowTemplate are undefined.

Accessing template[type] without verifying that template is defined may cause a runtime error. Please add a check to ensure template is defined before using it.

msg.message.templateMessage.hydratedTemplate || msg.message.templateMessage.hydratedFourRowTemplate;

for (const type of TypeMediaMessage) {
if (template[type]) {
mediaMessage = template[type];
mediaType = type;
msg.message = { [type]: { ...template[type], url: template[type].staticUrl } };
break;
}
}

if (!mediaMessage) {
throw 'Template message does not contain a supported media type';
}
} else {
for (const type of TypeMediaMessage) {
mediaMessage = msg.message[type];
if (mediaMessage) {
mediaType = type;
break;
}
}
}

if (!mediaMessage) {
throw 'The message is not of the media type';
if (!mediaMessage) {
throw 'The message is not of the media type';
}
}

if (typeof mediaMessage['mediaKey'] === 'object') {
Expand Down