feat(cloud-api): support CTA URL buttons in sendButtons#2634
Open
iscarelli wants to merge 2 commits into
Open
Conversation
On the Cloud API (WhatsApp Business) channel, sendButtons hardcoded every
button to type "reply", so a button with type "url" failed with
"interactive.action.buttons.0.reply is required: id" (code 100). This made it
impossible to send a link (CTA URL) button in a free-form session message,
even though the Cloud API supports it via the interactive "cta_url" type.
This preserves url buttons through buttonMessage and, when a cta_url button is
present, builds an interactive cta_url message
(action.name = "cta_url", parameters = { display_text, url }) instead of the
reply-button payload. Per the Cloud API, cta_url allows a single link button and
cannot be combined with reply buttons, so the first url button wins.
The reply-button path is unchanged. The internal text echo now falls back to the
button displayText so cta_url buttons no longer render as "undefined".
Closes evolution-foundation#1249
Contributor
Reviewer's GuideSupport CTA URL (link) buttons in Cloud API WhatsApp sendButtons by mapping URL buttons to WhatsApp interactive cta_url messages and preserving their display text in internal echoes, while keeping existing reply-button behavior unchanged. Sequence diagram for WhatsApp Cloud API sendButtons CTA URL handlingsequenceDiagram
participant Client
participant BusinessStartupService
participant MetaCloudAPI
Client->>BusinessStartupService: sendMessageWithTyping(message_with_buttons)
alt [cta_url button present]
BusinessStartupService->>BusinessStartupService: build cta_url interactive content
BusinessStartupService->>MetaCloudAPI: post(content, messages)
MetaCloudAPI-->>BusinessStartupService: response with wamid
else [no cta_url button]
BusinessStartupService->>BusinessStartupService: build reply interactive content
BusinessStartupService->>MetaCloudAPI: post(content, messages)
MetaCloudAPI-->>BusinessStartupService: response with wamid
end
Flow diagram for buttonMessage URL to cta_url mappingflowchart TD
A[buttonMessage receives data.buttons] --> B{button.type === url?}
B -->|Yes| C[Create button with type cta_url]
C --> D[Set displayText and url]
D --> F[Return mapped buttons]
B -->|No| E[Create button with type reply and reply.title]
E --> F[Return mapped buttons]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
quoted ? (content.context = { message_id: quoted.id }) : content;ternary in the new cta_url branch is a no-op on the false path and harder to read; consider replacing it with a simpleif (quoted) { content.context = { message_id: quoted.id }; }for clarity. - In the cta_url mapping within
sendButtons, you are assumingdisplayTextandurlare always present; if these can be user-provided, consider guarding against undefined values or falling back consistently (similar to thereply?.title ?? displayTextecho).
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `quoted ? (content.context = { message_id: quoted.id }) : content;` ternary in the new cta_url branch is a no-op on the false path and harder to read; consider replacing it with a simple `if (quoted) { content.context = { message_id: quoted.id }; }` for clarity.
- In the cta_url mapping within `sendButtons`, you are assuming `displayText` and `url` are always present; if these can be user-provided, consider guarding against undefined values or falling back consistently (similar to the `reply?.title ?? displayText` echo).Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Address review: use an if for the quoted context instead of the no-op ternary, only treat a url button as cta_url when it actually has a url, and fall back display_text to the url when displayText is absent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add support for CTA URL (link) buttons in
sendButtonson the Cloud API (WhatsApp Business) channel.Why
On the Cloud API channel,
buttonMessagemapped every button totype: 'reply', so sending a button withtype: 'url'failed at Meta with:This made it impossible to send a link button in a free-form (session) message, even though the Cloud API supports it through the interactive
cta_urltype. Reported in #1249.How
buttonMessagenow preservestype: 'url'buttons (as acta_urlentry) instead of forcing them into the reply shape.sendMessageWithTypingdetects acta_urlbutton and builds an interactivecta_urlmessage:cta_urlallows a single link button and cannot be combined with reply buttons, so the first url button wins.displayText, so cta_url buttons no longer render asundefined.Request example
POST /message/sendButtons/{instance} { "number": "5599999999999", "title": "Your gallery is ready!", "buttons": [ { "type": "url", "displayText": "Open gallery", "url": "https://example.com/g/abc" } ] }Testing
Tested against a live WhatsApp Business (Cloud API) number: the button is accepted by Meta (returns a
wamid) and renders as a tappable link button inside the 24h session window. Existing reply-button sends are unaffected.Closes #1249
Summary by Sourcery
Add support for CTA URL buttons in WhatsApp Cloud API sendButtons so link buttons can be sent as interactive messages in session conversations.
New Features:
Enhancements: