Skip to content

sendMessageWeb() only handles images, should support audio/video/documents #9

@adam91holt

Description

@adam91holt

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions