Skip to content

Fix WhatsApp media sends when mediaUrl is empty but mediaUrls is populated#64394

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
eric-fr4:fix/whatsapp-mediaurls-fallback
Apr 12, 2026
Merged

Fix WhatsApp media sends when mediaUrl is empty but mediaUrls is populated#64394
vincentkoc merged 3 commits into
openclaw:mainfrom
eric-fr4:fix/whatsapp-mediaurls-fallback

Conversation

@eric-fr4

@eric-fr4 eric-fr4 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Fix WhatsApp media sends when outbound flow uses mediaUrls

Summary

This fixes a WhatsApp outbound regression where openclaw message send --media ... can return a message ID but still send a text-only message.

In the affected runtime path, the WhatsApp sender only checks options.mediaUrl, while the upstream send flow can populate attachments via options.mediaUrls.

When mediaUrl is empty and mediaUrls contains the attachment, the outbound send silently downgrades to text.

Reproduction

  1. Use openclaw message send --channel whatsapp --to ... --media ....
  2. The command returns a valid message ID.
  3. Gateway logs show:
hasMedia:false
  1. The recipient gets a text-only message instead of the image.

Root cause

sendMessageWhatsApp() only looks at options.mediaUrl when deciding whether the outbound message includes media.

However, the surrounding send flow can provide attachments in options.mediaUrls.

Fix

Normalize options.mediaUrls and fall back to the first valid entry when options.mediaUrl is empty.

const mediaUrls = Array.isArray(options.mediaUrls)
  ? options.mediaUrls
      .map((entry) => typeof entry === "string" ? entry.trim() : "")
      .filter(Boolean)
  : [];

const primaryMediaUrl = options.mediaUrl?.trim() || mediaUrls[0];

Why this is safe

  • preserves current behavior when mediaUrl is already set
  • only changes the empty-mediaUrl path
  • uses the first valid normalized URL/path from the existing mediaUrls array
  • aligns the WhatsApp sender with the data shape already produced by the upstream message flow

Validation

Before:

{"hasMedia":false} sending message

After:

{"hasMedia":true} sending message

The same test then delivers the actual WhatsApp image instead of a text-only message.

@openclaw-barnacle openclaw-barnacle Bot added channel: whatsapp-web Channel integration: whatsapp-web size: XS labels Apr 10, 2026
@greptile-apps

greptile-apps Bot commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent downgrade in WhatsApp outbound sends where sendMessageWhatsApp() only checked options.mediaUrl but the upstream send flow can populate options.mediaUrls. The fix normalizes mediaUrls, trims entries, filters blanks, and falls back to mediaUrls[0] when mediaUrl is absent — preserving existing behavior when mediaUrl is set. A dedicated test covering whitespace-padded array entries is included.

Confidence Score: 5/5

Safe to merge — targeted fix with no behavioral regression on the existing path and a covering test for the new fallback.

The change is minimal and strictly additive: it computes primaryMediaUrl from mediaUrls only when mediaUrl is absent or empty, so every existing caller that sets mediaUrl is unaffected. The normalization (trim + filter-falsy) correctly skips whitespace-only entries. The new test validates the fix end-to-end. No P0 or P1 findings.

No files require special attention.

Reviews (1): Last reviewed commit: "Fix WhatsApp media fallback" | Re-trigger Greptile

@vincentkoc vincentkoc self-assigned this Apr 12, 2026
@vincentkoc vincentkoc force-pushed the fix/whatsapp-mediaurls-fallback branch from 116d86e to e3e6b73 Compare April 12, 2026 15:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e3e6b73e86

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md
eric-fr4 and others added 3 commits April 12, 2026 16:55
Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vincentkoc vincentkoc force-pushed the fix/whatsapp-mediaurls-fallback branch from e3e6b73 to 23cbeaa Compare April 12, 2026 15:56
@vincentkoc vincentkoc merged commit ad826ea into openclaw:main Apr 12, 2026
39 of 40 checks passed
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…lated (openclaw#64394)

* Fix WhatsApp media fallback

Accept the first mediaUrls entry when mediaUrl is empty so outbound WhatsApp sends do not silently downgrade media messages to text.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* chore(changelog): credit WhatsApp mediaUrls fallback

* fix(changelog): restore 2026.4.10 release block

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: whatsapp-web Channel integration: whatsapp-web size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants