Skip to content
QwryAI
Documentation
Pages

Guides

WhatsApp

List your approved WhatsApp templates and send them to your contacts as an Outbound campaign

The WhatsApp tools read the approved message templates on the WhatsApp numbers connected to your agent, and send them through Outbound. A template is the only way to start a WhatsApp conversation with someone who hasn't messaged you in the last 24 hours, so this is how your code reaches customers first: an order update, a back-in-stock alert, a reminder.

Sends go to your QwryAI contacts, picked by contact or by search, and run as an Outbound campaign: you see who it reaches and what it costs before anything is sent. Customer replies arrive in the agent's normal WhatsApp conversations. The numbers come from Channels › WhatsApp; see WhatsApp to connect one.

Listing templates

Two tools list templates, for different jobs:

ToolPermissionReturns
list_outbound_templatesChange actions and proceduresThe approved templates one number can send as a campaign, with their variables and, for any that can't be sent, why. Takes number_id from get_outbound.
list_whatsapp_templatesRead agent settingsThe approved templates on one number's account (the first by default): name, language, body, category and parameters, the number of {{n}} values it takes. Takes an optional number.
Bash
curl -X POST 'https://api.qwryai.com/public/v1/tools/list_whatsapp_templates' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"chatbotId": "YOUR_AGENT_ID"}'
JSON
{
  "success": true,
  "data": {
    "templates": [
      {
        "name": "order_shipped",
        "language": "en",
        "body": "Hi {{1}}, good news: your order {{2}} is on its way.",
        "category": "UTILITY",
        "parameters": 2
      }
    ]
  }
}

Selecting a template

Templates are named by name and language together. Only templates Meta has approved are listed, so anything in the list can be chosen. Create and edit templates in WhatsApp Manager; see WhatsApp templates.

Choosing the sender

get_outbound lists the channels that can send: each connected WhatsApp number with its id, the email From address, and the reason a channel can't send, if any. Pass the number's id as fromNumberId when you send, and as number_id to list_outbound_templates.

Toolnumber / fromNumberIdResult
list_whatsapp_templatesLeft outThe first connected number's account.
list_whatsapp_templatesA number as listed, or its idThat number's account. A number that isn't connected returns VALIDATION_INVALID_BODY.
send_campaignRequired for WhatsAppThe number the campaign sends from.

Template variables

Each {{n}} in a template needs a value. In send_campaign, mapping gives one value per variable, keyed by component and number, such as body:1 and body:2. Each value is either a contact field, { "type": "contact", "field": "name" } (also email, phone or a custom attribute, with an optional fallback), or fixed text, { "type": "static", "value": "…" }. A contact with no value and no fallback is skipped.

Bash
curl -X POST 'https://api.qwryai.com/public/v1/tools/send_campaign' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "chatbotId": "YOUR_AGENT_ID",
    "channel": "whatsapp",
    "name": "November shipping update",
    "fromNumberId": "NUMBER_ID",
    "template": { "name": "order_shipped", "language": "en" },
    "mapping": {
      "body:1": { "type": "contact", "field": "name", "fallback": "there" },
      "body:2": { "type": "static", "value": "1043" }
    },
    "audience": { "mode": "all", "search": "sam.tester@example.com", "filter": { "conditions": [] } },
    "replyBehavior": "ai_reply"
  }'

audience is either { "mode": "all", "filter": { "conditions": [] }, "search": "…" }, everyone a contact filter and search match, or { "mode": "manual", "identifiers": ["…"] }, contacts picked by their identifier. GET /public/v1/tools lists the full input schema.

Delivery and conversations

send_campaign doesn't send. It returns a review that shows how many contacts the campaign reaches, who it skips and why, and the credits it costs: one credit per message. The campaign starts when you apply the review, or at start_at if you scheduled it.

replyBehaviorWhen a customer replies
ai_replyThe agent answers, as in any WhatsApp conversation.
takeoverA Helpdesk ticket opens for your team.

Follow a campaign with get_outbound_campaign, which lists its recipients 50 per page with each one's delivery status and why any were skipped. control_campaign pauses, resumes or stops it.

WhatsApp automations

To send a template automatically when a Shopify order is created, use the WhatsApp automation tools instead of a campaign:

ToolDoes
list_whatsapp_automationsReads the order-created automation: its number, rules, fallback template and whether it's on.
save_whatsapp_automationAdds or changes it through a review. Needs Shopify connected.
delete_whatsapp_automationDeletes it through a review.

See WhatsApp automations.

Error codes

WhatsApp-specific error codes beyond the standard authentication and rate-limiting errors:

CodeHTTPDescription
VALIDATION_INVALID_BODY409The agent has no connected WhatsApp number, the number asked for isn't connected to it, or the campaign input doesn't match the template, such as a missing variable. message says which.
INVALID_ARGUMENTS400An argument failed the tool's schema.
INSUFFICIENT_PERMISSION403Templates need Read agent settings; campaigns need Change actions and procedures.
TOOL_FAILED500WhatsApp couldn't be reached.

Explore the documentation