Skip to content
Open
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
16 changes: 14 additions & 2 deletions src/api/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,22 @@ export class Whatsapp extends BusinessLayer {
messageId = messageId.id;
}

if (!messageId) {
throw new Error(
'downloadMedia: messageId is undefined or null. ' +
'Make sure the message object (e.g. quotedMsgObj) exists before calling downloadMedia.'
);
}

return await evaluateAndReturn(
this.page,
async (messageId) =>
WPP.util.blobToBase64(await WPP.chat.downloadMedia(messageId)),
async (messageId) => {
const media = await WPP.chat.downloadMedia(messageId);
if (!media) {
throw new Error(`downloadMedia: no media found for message id "${messageId}". The message may not contain downloadable media.`);
}
return WPP.util.blobToBase64(media);
},
messageId
);
}
Expand Down