WhatsApp API overview

How to send approved WhatsApp template messages to customers with the Askocto API v2, and how replies continue in the same conversation.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

The WhatsApp endpoints let your system start a conversation with a customer on WhatsApp. You list the message templates of an agent, then send one to a phone number. When the customer replies, the answer lands in the conversation that the send call returned, and the agent responds as usual.

Why templates

WhatsApp only lets a business start a conversation with an approved template message. Free text can follow once the customer has replied. So the API sends templates, and the agent handles everything after the first reply. Templates are created and approved in the dashboard, see WhatsApp templates.

Before you call the API

  • Connect a WhatsApp number to the agent. See WhatsApp.
  • Create a template and wait until it is approved.
  • Use an API key of the workspace, see Authentication.

The flow

  1. Call List whatsapp templates to find the name, language and number of variables of the template.
  2. Call Send a whatsapp template message with the recipient and the values for the variables.
  3. Keep the returned conversationId. The customer's reply is added to that conversation, and you can read it with List conversation messages.
const base = "https://api.askocto.co/v2/agents/agt_8f3k2m"
const headers = {
  Authorization: `Bearer ${process.env.OCTO_API_KEY}`,
  "Content-Type": "application/json",
}

const sent = await fetch(`${base}/whatsapp/messages`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    to: "+15555550123",
    template: "order_update",
    language: "en",
    variables: { "1": "Dana", "2": "A-1042" },
  }),
})

const { conversationId } = await sent.json()
console.log("Follow the replies in", conversationId)

Variables

A template body has numbered placeholders such as {{1}} and {{2}}. Send one value for each number in the variables object, with the number as the key. A missing value returns a 400 error before anything is sent.

Phone numbers

Send numbers in international format with a leading plus sign and the country code, for example +15555550123. Check that you have the customer's permission to message them. That is your responsibility and not legal advice.

Endpoints

The same two actions are available in the terminal with octo whatsapp. The dashboard setup of outbound messages is covered in Outbound WhatsApp.

Something unclear or missing? Tell us and we will fix the page.