Skip to content

feat(whatsapp_business): add AI-agent friendly props for send-text-using-template#19821

Merged
michelle0927 merged 2 commits intoPipedreamHQ:masterfrom
aliasgher5252:feat/whatsapp-ai-agent-support
Jan 26, 2026
Merged

feat(whatsapp_business): add AI-agent friendly props for send-text-using-template#19821
michelle0927 merged 2 commits intoPipedreamHQ:masterfrom
aliasgher5252:feat/whatsapp-ai-agent-support

Conversation

@aliasgher5252
Copy link
Contributor

@aliasgher5252 aliasgher5252 commented Jan 23, 2026

Summary

  • Add headerVars, bodyVars, buttonVars array props for programmatic/AI-agent 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

Details

This change makes the send-text-using-template action usable by AI agents and programmatic API calls by:

  1. New array props: Instead of requiring dynamic props like {{1}}, header_{{1}}, agents can pass arrays:
   {
     "messageTemplate": "template_id",
     "headerVars": ["value1"],
     "bodyVars": ["value1", "value2"]
   }
  1. Auto-fetch template details: When messageTemplate is a string (not object), the action fetches template name/language automatically.

  2. Bug fix: Template names containing " - " are now parsed correctly using lastIndexOf.

Backward Compatible
Existing UI workflow is unchanged.

Summary by CodeRabbit

  • New Features

    • Added three array inputs — headerVars, bodyVars, buttonVars — for programmatic/AI-supplied template variables.
  • Improvements

    • Template handling now supports both UI-labeled and programmatic invocations; array variables take precedence over individual props.
    • Prevents sending empty body blocks when no body variables are present.
  • Chores

    • Version bumps: action component to 0.0.7 and package to 0.0.14.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
pipedream-docs-redirect-do-not-edit Ignored Ignored Jan 23, 2026 3:42pm

Request Review

@pipedream-component-development
Copy link
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@pipedream-component-development
Copy link
Collaborator

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:

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 23, 2026

Walkthrough

Adds 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

Cohort / File(s) Summary
WhatsApp Template Message Action
components/whatsapp_business/actions/send-text-using-template/send-text-using-template.mjs
Version bumped 0.0.6 → 0.0.7. Added public props headerVars, bodyVars, buttonVars (string[]). run extended to parse label-based templateName/language or fetch template via getMessageTemplate when no label. Parameter construction now prefers the new arrays with fallbacks to header_{{1}}, dynamic body_{{n}}, and button_{{1}}. Only includes body component if body params exist.
Package metadata
components/whatsapp_business/package.json
Version bumped 0.0.13 → 0.0.14 (package version only).

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding AI-agent friendly props (headerVars, bodyVars, buttonVars) to the send-text-using-template action.
Description check ✅ Passed The description is comprehensive and complete, covering the summary, details, implementation approach, backward compatibility, and examples.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

…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.
@aliasgher5252 aliasgher5252 force-pushed the feat/whatsapp-ai-agent-support branch from 47e9e6e to a4b8c20 Compare January 23, 2026 09:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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 headerVars and buttonVars to 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 michelle0927 moved this from Ready for PR Review to In Review in Component (Source and Action) Backlog Jan 23, 2026
Copy link
Collaborator

@michelle0927 michelle0927 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! Ready for QA!

@michelle0927 michelle0927 moved this from In Review to Ready for QA in Component (Source and Action) Backlog Jan 23, 2026
@vunguyenhung vunguyenhung moved this from Ready for QA to Ready for Release in Component (Source and Action) Backlog Jan 26, 2026
@vunguyenhung
Copy link
Contributor

Hi everyone, all test cases are passed! Ready for release!

Test reports

@michelle0927 michelle0927 merged commit 9c629f8 into PipedreamHQ:master Jan 26, 2026
9 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Release to Done in Component (Source and Action) Backlog Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

User submitted Submitted by a user

Development

Successfully merging this pull request may close these issues.

7 participants