Guides
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:
| Tool | Permission | Returns |
|---|---|---|
list_outbound_templates | Change actions and procedures | The 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_templates | Read agent settings | The 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. |
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"}'{
"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.
| Tool | number / fromNumberId | Result |
|---|---|---|
list_whatsapp_templates | Left out | The first connected number's account. |
list_whatsapp_templates | A number as listed, or its id | That number's account. A number that isn't connected returns VALIDATION_INVALID_BODY. |
send_campaign | Required for WhatsApp | The 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.
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.
replyBehavior | When a customer replies |
|---|---|
ai_reply | The agent answers, as in any WhatsApp conversation. |
takeover | A 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:
| Tool | Does |
|---|---|
list_whatsapp_automations | Reads the order-created automation: its number, rules, fallback template and whether it's on. |
save_whatsapp_automation | Adds or changes it through a review. Needs Shopify connected. |
delete_whatsapp_automation | Deletes it through a review. |
See WhatsApp automations.
Error codes
WhatsApp-specific error codes beyond the standard authentication and rate-limiting errors:
| Code | HTTP | Description |
|---|---|---|
VALIDATION_INVALID_BODY | 409 | The 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_ARGUMENTS | 400 | An argument failed the tool's schema. |
INSUFFICIENT_PERMISSION | 403 | Templates need Read agent settings; campaigns need Change actions and procedures. |
TOOL_FAILED | 500 | WhatsApp couldn't be reached. |