Problem
The sendMessageWeb() function in src/web/outbound.ts currently treats all media as images:
if (options.mediaUrl) {
const media = await loadWebMedia(options.mediaUrl);
payload = {
image: media.buffer,
caption: body || undefined,
mimetype: media.contentType,
};
}
This means audio files get sent as broken images, videos don't play, and documents aren't properly attached.
Proposed solution
Check media.kind and construct the appropriate payload:
- audio: Use
audio field with ptt: true for voice notes, and set mimetype to "audio/ogg; codecs=opus" when content type is audio/ogg (WhatsApp requires the explicit codec specification)
- video: Use
video field
- image: Use
image field (current behavior)
- document: Use
document field with fileName
if (media.kind === "audio") {
const audioMimetype =
media.contentType === "audio/ogg"
? "audio/ogg; codecs=opus"
: media.contentType;
payload = {
audio: media.buffer,
ptt: true,
mimetype: audioMimetype,
};
} else if (media.kind === "video") {
payload = { video: media.buffer, caption: body || undefined, mimetype: media.contentType };
} else if (media.kind === "image") {
payload = { image: media.buffer, caption: body || undefined, mimetype: media.contentType };
} else {
payload = { document: media.buffer, fileName: "file", caption: body || undefined, mimetype: media.contentType };
}
Benefits
- Voice notes sent via
pnpm warelay send will work correctly as playable PTT messages
- Videos will be playable
- Documents (PDFs, etc.) will be properly attached with filenames
Related
Problem
The
sendMessageWeb()function insrc/web/outbound.tscurrently treats all media as images:This means audio files get sent as broken images, videos don't play, and documents aren't properly attached.
Proposed solution
Check
media.kindand construct the appropriate payload:audiofield withptt: truefor voice notes, and set mimetype to"audio/ogg; codecs=opus"when content type isaudio/ogg(WhatsApp requires the explicit codec specification)videofieldimagefield (current behavior)documentfield withfileNameBenefits
pnpm warelay sendwill work correctly as playable PTT messagesRelated