Send WhatsApp templates
Create a WhatsApp template and send it to a contact once Meta approves it. Then read its results. To message the contact outside the 24-hour service window, use an approved template.
Before you start
You need a connected WhatsApp number in the workspace and your Platica API key in PLATIC_API_KEY.
Check Meta's guidelines for names, categories and content before creating the template.
To use the platform, see Manage your WhatsApp number.
Find your WhatsApp number
The
prefixedChannelIdof a WhatsApp channel (it starts withwb-) is thechannelIdyou send messages from. (List channels)curl https://api.platic.ai/v1/channels \ -H "Authorization: Bearer $PLATIC_API_KEY"import { Platic } from "platic-sdk"; const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! }); const channels = await platic.channels.list(); const whatsapp = channels.filter((channel) => channel.prefixedChannelId?.startsWith("wb-")); for (const channel of whatsapp) { console.log(channel.prefixedChannelId, channel.displayPhoneNumber, channel.health.state); }Which WhatsApp numbers do I have connected?
Tool:
list_channels.Keep the number's
prefixedChannelIdinCHANNEL_ID.Create the template
Platica creates it in the workspace's WhatsApp Business account (WABA) and sends it to Meta's review. It starts as
PENDINGand can't be sent until Meta approves it. Every variable ({{1}},{{2}}) needs an example value. (Create a template)curl https://api.platic.ai/v1/whatsapp/templates \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "order_ready", "language": "es_MX", "category": "UTILITY", "components": [ { "type": "BODY", "text": "Hola {{1}}, tu pedido {{2}} está listo para recoger.", "example": { "body_text": [["Ana", "A-1024"]] } }, { "type": "FOOTER", "text": "Acme" } ] }'const template = await platic.whatsapp.templates.create({ name: "order_ready", language: "es_MX", category: "UTILITY", components: [ { type: "BODY", text: "Hola {{1}}, tu pedido {{2}} está listo para recoger.", example: { body_text: [["Ana", "A-1024"]] }, }, { type: "FOOTER", text: "Acme" }, ], }); console.log(template.status, template.nextStep);Create a utility template in Spanish (Mexico) called order_ready that tells a customer their order is ready to pick up. It takes the customer's name and the order number.
Tool:
create_whatsapp_template.nametakes only lowercase letters, numbers and underscores, and it is the name you use when you send.categoryisMARKETING,UTILITYorAUTHENTICATION.languageis a Meta language code, likees,es_MXoren_US.If the workspace has several WhatsApp Business accounts, send
wabaIdwith the one the template belongs to. Without it the error isWABA_REQUIREDanddetails.availablelists them. For an image, video or document header, put the file's public URL inexample.header_url.Wait for Meta's review
Check the template's status and wait for
APPROVEDbefore sending it. The review time depends on Meta. (Get a template)curl "https://api.platic.ai/v1/whatsapp/templates/order_ready?language=es_MX" \ -H "Authorization: Bearer $PLATIC_API_KEY"const current = await platic.whatsapp.templates.get("order_ready", { language: "es_MX" }); console.log(current.status, current.languages);Did Meta approve the order_ready template?
Tool:
get_whatsapp_template.The name and language identify a template version:
order_readyines_MXand inen_USare different versions. If you omitlanguage, you receive the only available version or, if there are several, an approved one.To receive approval or rejection on your server, subscribe a webhook to
template.status.updated. See Receive webhooks and Payloads.Send it
Send the approved template to a contact. If there is an open conversation with them, the message joins it; if not, a new one is created.
conversationIdis the contact's phone number in E.164 format, without+. (Send a template message)curl https://api.platic.ai/v1/messages/template \ -H "Authorization: Bearer $PLATIC_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "channelId": "'$CHANNEL_ID'", "conversationId": "5215512345678", "responderAgentId": "'$AGENT_ID'", "template": { "name": "order_ready", "language": "es_MX", "params": ["Ana", "A-1024"] } }'if (current.status !== "APPROVED") { throw new Error(`order_ready is ${current.status}: only an approved template can be sent`); } // api_example is a ready template filled with the example values: replace the ones you need. const sent = await platic.messages.sendTemplate({ channelId: process.env.CHANNEL_ID!, conversationId: "5215512345678", responderAgentId: process.env.AGENT_ID!, template: { ...current.api_example, language: current.language, params: ["Ana", "A-1024"] }, }); console.log(sent.messageId, sent.status);Send the order_ready template to 5215512345678 from my WhatsApp number, with the name Ana and the order number A-1024. Have the Sales agent handle the replies.
Tool:
send_template_message.paramsmust match exactly the number of variables in the template.channelIdandresponderAgentIdare independent: the first decides which number sends, the second which agent handles the replies. WithoutresponderAgentId, a new conversation has no agent and, when the contact replies, a person has to take it.To send later, use
delay(3 seconds to 24 hours, in milliseconds) orscheduleTime(ISO 8601, up to 30 days ahead), never both. Then you can check, reschedule or cancel it bymessageId.ImportantThe message reaches the selected number. Check the Meta fees that apply to the template. Send your first one to your own number.
Check it worked
Check messageId and status in the response. After the message is sent, find the conversation in the inbox. If you scheduled it, wait for the send date.
Use Template analytics to see sent, delivered, read, clicked and cost, by period and day.
curl "https://api.platic.ai/v1/whatsapp/templates/order_ready/analytics?days=7" \
-H "Authorization: Bearer $PLATIC_API_KEY" With the SDK, platic.whatsapp.templates.analytics("order_ready", { days: 7 }). Your assistant uses get_whatsapp_template_analytics.
To change a template later, use Update a template; to remove it, Delete a template. Meta reviews every new or edited template again.
Next steps
- Send a campaign to reach a whole audience with an approved template.
- Receive webhooks to learn when a template is approved and when a contact replies.
- WhatsApp templates: list, create, update and delete.