feat(whatsapp_business): add AI-agent friendly props for send-text-using-template#19821
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified. |
|
Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:
|
WalkthroughAdds three new public props (headerVars, bodyVars, buttonVars) and bumps action version to 0.0.7. The run method now supports both UI label parsing and programmatic template retrieval via getMessageTemplate, and prioritizes the new variable arrays with fallbacks when building template components. Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/System
participant Action as send-text-using-template
participant TemplateAPI as getMessageTemplate
participant WhatsApp as WhatsApp API
User->>Action: Invoke action (with or without label)
alt Label present
Action->>Action: Parse label → templateName, language
else No label
Action->>TemplateAPI: getMessageTemplate(template_id)
TemplateAPI-->>Action: Return template details
Action->>Action: Derive templateName, language
end
Action->>Action: Build parameters (use headerVars/bodyVars/buttonVars or fallbacks)
Action->>Action: Assemble components array (omit empty body)
Action->>WhatsApp: Send templated message
WhatsApp-->>Action: Response
Action-->>User: Return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In
`@components/whatsapp_business/actions/send-text-using-template/send-text-using-template.mjs`:
- Around line 151-158: The buttonParameters construction uses a loose
key.includes("button_") filter that may match unintended props; change the
filter to a precise match (e.g., use key.startsWith("button_") or a stricter
regex like /^button_\d+$/) when building buttonParameters from this, so it only
picks explicit button_* properties consistent with the header exact-match
approach used elsewhere (update the filter where buttonParameters is assigned).
- Around line 106-119: The code assumes label contains " - " but doesn't guard
for lastIndexOf returning -1; update the branch that handles
this.messageTemplate?.label so after computing lastDashIndex you check if
lastDashIndex === -1 and handle the malformed label: set templateName = label
(use the entire label) and language = '' (or undefined) as a safe default, or
alternatively fall back to fetching template details via
this.whatsapp.getMessageTemplate using the template id; ensure you update usages
of templateName and language accordingly. Use the identifiers label,
lastDashIndex, templateName, language and
this.whatsapp.getMessageTemplate/getMessageTemplate to locate the change.
components/whatsapp_business/actions/send-text-using-template/send-text-using-template.mjs
Show resolved
Hide resolved
components/whatsapp_business/actions/send-text-using-template/send-text-using-template.mjs
Show resolved
Hide resolved
3e4f034 to
47e9e6e
Compare
…ing-template - Add headerVars, bodyVars, buttonVars array props for programmatic use - Support messageTemplate as string (template ID) for API/agent calls - Fix template name parsing bug when name contains " - " - Only push body component if parameters exist Backward compatible: existing UI workflow unchanged.
47e9e6e to
a4b8c20
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
components/whatsapp_business/actions/send-text-using-template/send-text-using-template.mjs (1)
124-161: Add validation to enforce single-variable limits for header and URL button parameters.WhatsApp Cloud API constrains TEXT headers and URL button variables to exactly 1 parameter each. The code currently allows
headerVarsandbuttonVarsto map multiple array entries into the parameters list, which violates API constraints and causes message send failures. Add checks to ensure these arrays contain at most one element.🔧 Proposed fix (guard against multiple vars)
// Header parameters - use headerVars array if provided, otherwise fall back to individual props let headerParameters; if (this.headerVars?.length) { + if (this.headerVars.length > 1) { + throw new Error("Template header supports only one variable."); + } - headerParameters = this.headerVars.map((text) => ({ + headerParameters = [{ type: "text", - text, + text: this.headerVars[0], - })); + }]; } else { headerParameters = Object.keys(this) .filter((key) => key === "header_{{1}}") .map((key) => ({ type: "text", text: this[key], })); } // Button parameters - use buttonVars array if provided, otherwise fall back to individual props let buttonParameters; if (this.buttonVars?.length) { + if (this.buttonVars.length > 1) { + throw new Error("Template URL button supports only one variable."); + } - buttonParameters = this.buttonVars.map((text) => ({ + buttonParameters = [{ type: "text", - text, + text: this.buttonVars[0], - })); + }]; } else { buttonParameters = Object.keys(this) .filter((key) => key === "button_{{1}}") .map((key) => ({ type: "text", text: this[key], })); }
michelle0927
left a comment
There was a problem hiding this comment.
Thank you for your contribution! Ready for QA!
|
Hi everyone, all test cases are passed! Ready for release! Test reports
|
Summary
headerVars,bodyVars,buttonVarsarray props for programmatic/AI-agent usemessageTemplateas string (template ID) for API/agent callsDetails
This change makes the
send-text-using-templateaction usable by AI agents and programmatic API calls by:{{1}},header_{{1}}, agents can pass arrays:{ "messageTemplate": "template_id", "headerVars": ["value1"], "bodyVars": ["value1", "value2"] }Auto-fetch template details: When messageTemplate is a string (not object), the action fetches template name/language automatically.
Bug fix: Template names containing " - " are now parsed correctly using lastIndexOf.
Backward Compatible
Existing UI workflow is unchanged.
Summary by CodeRabbit
New Features
Improvements
Chores
✏️ Tip: You can customize this high-level summary in your review settings.