-
-
Notifications
You must be signed in to change notification settings - Fork 40k
Closed
Description
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
audiofield withptt: truefor voice notes, and set mimetype to"audio/ogg; codecs=opus"when content type isaudio/ogg(WhatsApp requires the explicit codec specification) - video: Use
videofield - image: Use
imagefield (current behavior) - document: Use
documentfield withfileName
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 sendwill work correctly as playable PTT messages - Videos will be playable
- Documents (PDFs, etc.) will be properly attached with filenames
Related
- WhatsApp voice notes fail without explicit "audio/ogg; codecs=opus" mimetype #7 (voice note mimetype fix in auto-reply)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels