pinecallDocs
Integrations / WhatsApp

WhatsApp

A WhatsApp Business number answered by the same agent, in writing.

Connect a WhatsApp Business number and the same agent that answers your phone answers it, in writing. Each contact is one conversation, and your team reads and joins it from the console like any call.

How it works#

A WhatsApp number is a number like any other: it belongs to your org and points at one agent, in the sandbox or production, with the channel whatsapp. When a contact writes:

Your agent's code does not change. The call's channel is whatsapp, which is written, not spoken, and the prompt tells the model how to write for it: Pinecall's own words, or yours with channelRules = { whatsapp: "…" } (The prompt).

Connect a number#

A WhatsApp number lives in a Meta app that you own. Connecting it takes three things from that app (the number's ID, a token, the app's secret) and one thing set in it: the webhook, which is where Meta delivers your contacts' messages. Without the webhook the agent can reply but never hears anybody.

What you need from Meta#

Create a Meta app with WhatsApp#

At developers.facebook.com create an app for your business and add the WhatsApp product to it. Meta asks for the business portfolio the app belongs to, and gives it a test number. To answer on your own number, add it under WhatsApp ▸ API Setup and verify it with the code Meta sends.

Copy the phone number ID#

On WhatsApp ▸ API Setup, pick your number under From and copy its Phone number ID: a long number such as 105512345678901, not the phone number itself. Note the WhatsApp Business Account ID beside it too. You only need it if messages do not arrive.

Make a token that does not expire#

The token shown on API Setup expires within a day. Make a permanent one in Business settings under Users ▸ System users:

  1. Add a system user with the Admin role.
  2. Under Assign assets, give it your app and your WhatsApp account, with full control.
  3. Generate token: choose your app, set the expiry to Never, and tick whatsapp_business_messaging and whatsapp_business_management.

Copy the token: Meta shows it once.

Copy the app secret#

In your app, open App settings ▸ Basic and show the App secret. Meta signs every message it delivers with it, and Pinecall checks that signature before it reads anything.

Add it in Pinecall#

Connect the number#

On production's console, open Numbers ▸ Add a number ▸ WhatsApp. Fill in the phone number ID, the access token and the app secret, then Connect WhatsApp. Pinecall asks Meta for that number with that token before it keeps anything, and stores the token and the secret encrypted.

Route it to an agent#

Pick the WhatsApp number and the agent that answers it, then Connect.

The same from a terminal. The token and the app secret are typed with nothing echoed, or piped one per line:

Terminal
$ pinecall carriers add whatsapp --phone-number-id 105512345678901 --label Clínica
WhatsApp access token:
Meta app secret (empty keeps the one given before):
kept: 105512345678901 · whatsapp · Clínica
  in your Meta app, WhatsApp ▸ Configuration ▸ Webhook:
    Callback URL   https://cloud.pinecall.io/v1/whatsapp/webhook
    Verify token   org_8f2c….3f9ac01d77b24e6a8c5d1f0b9e7a6c42
    then subscribe to the webhook field `messages`
$ pinecall numbers available --prod
$ pinecall numbers import +59829000000 --agent clinica-norte --channel whatsapp --prod

An ID or a token Meta does not open is refused in Meta's words, and nothing is kept.

When the org holds more than one carrier account (a Twilio account and this WhatsApp number, say), pinecall numbers import names the one the number comes through: --account 105512345678901, the phone number ID (Phone numbers).

Point Meta's webhook at Pinecall#

This is the step that makes the agent hear. The console shows the two values under the form, and pinecall carriers show <phone number ID> prints them again at any time.

Open the webhook settings#

In your Meta app, open WhatsApp ▸ Configuration and edit the Webhook.

Paste the callback URL and the verify token#

Field Value
Callback URL https://cloud.pinecall.io/v1/whatsapp/webhook
Verify token the one Pinecall gave your org, starting with your org's ID

Then Verify and save. Meta calls the URL at once, and Pinecall answers only the token it gave you.

Subscribe to messages#

Under Webhook fields, subscribe to messages. It is the only field Pinecall reads.

Put the app in Live mode#

Switch the app from Development to Live at the top of its dashboard. In development Meta only delivers messages from people who have a role on the app.

Now write to the number from another phone. The agent answers within a few seconds, and the conversation appears in the console under Calls (pick WhatsApp in Showing to see those alone).

If no message arrives#

Sending works on the token alone, so an agent that replies from the console but never answers a contact is always a webhook that is not delivering. Check these, in order:

  • The webhook is saved and messages is subscribed in WhatsApp ▸ Configuration.

  • The app secret in Pinecall is this app's. A message signed with another secret is answered 403 and dropped. Run pinecall carriers add whatsapp --phone-number-id <id> again and type the secret from App settings ▸ Basic.

  • The app is Live, not in Development.

  • The app is subscribed to the number's WhatsApp account. Meta subscribes the account the app made, and not always one you added later. Ask Meta, and subscribe it if the list is empty, with the WhatsApp Business Account ID from API Setup:

    Terminal
    curl -H "Authorization: Bearer $WA_TOKEN" https://graph.facebook.com/v21.0/<WABA_ID>/subscribed_apps
    curl -X POST -H "Authorization: Bearer $WA_TOKEN" https://graph.facebook.com/v21.0/<WABA_ID>/subscribed_apps
  • No other tool holds the number. A number still connected to another WhatsApp platform sends its messages there.

What the agent reads and what the contact sees#

The contact sends The agent gets
A text The text
A tap on a reply button or a row of a list The words on the button or the row
A voice note What it says, transcribed by the same ears your calls use, on the same keys
An image, a sticker, a document, a location Nothing. It is dropped, and the contact is not answered
  • Read receipts. A message is marked read the moment the agent takes it up, so the contact sees the two blue ticks.
  • Typing. While the model writes, the contact sees typing…. When a supervisor has taken the conversation over, the message is marked read and nothing is shown, because no reply is promised.
  • Long replies. WhatsApp takes 4,096 characters a message. A longer reply goes out as several, cut at a paragraph or a line when there is one.
  • Delivery status. WhatsApp says where each reply stands: sent, delivered to the contact's phone, read, or failed with the reason (the 24-hour window closed, a number that is not on WhatsApp). Each one is a message.status event on the conversation, with the message_id, the status, the contact it was written to and the error: your code can listen to it, and the call's log keeps it. A status that arrives after the conversation went quiet is not kept.

Conversations#

Messages are answered one at a time, in the order they arrive. A conversation that is quiet for two hours is over: the next message opens a new one. That keeps every reply inside Meta's 24-hour window for answering a customer.

A new conversation opens on what this contact and the agent last said to each other, on any channel of the same agent, and the agent does not greet them again.

If nobody is running the agent when a message arrives, the message waits. The moment a process holds the agent again, what waited is answered, oldest first. A message older than 24 hours is dropped, because Meta no longer lets a reply through.

Each message counts against your org's messages and llm_tokens limits. A message past them ends the conversation unanswered (Limits & provider keys).

The agent writes first#

Inside the 24 hours after a contact's last message the agent answers freely, and those messages cost nothing at Meta. To write to somebody first, or after those 24 hours, WhatsApp takes one thing only: a template, a message you wrote and Meta approved (WhatsApp Manager ▸ Message templates). A template is also the one message Meta charges for, on the account that owns the number.

Pinecall sends a template as the agent, from the number it answers WhatsApp at, with the account you connected. Name the template, the language it was approved in, and what fills its {{1}}, {{2}}…:

Terminal
pinecall template reminder visit_reminder --to +14155550142 --language en_US --var Ana --var "tomorrow at 9:30"
reminder would send visit_reminder to +14155550142 · sandbox · simulated: nothing was sent
  → --prod sends it: Meta charges the number's account for a template

The sandbox answers and sends nothing. With --prod the line ends with Meta's id of the message: reminder sent visit_reminder to +14155550142 from +14155550134 · production · wamid.HBgL….

From a flow it is a step, which answers { sent, simulated, messageId, from }:

const sent = await step.template(visit.phone, Reminder, "visit_reminder", {
  language: "en_US",
  variables: ["Ana", "tomorrow at 9:30"],
});
sent = await step.template(
    visit["phone"], Reminder, "visit_reminder", language="en_US", variables=["Ana", "tomorrow at 9:30"]
)
sent = step.template(visit[:phone], Reminder, "visit_reminder", language: "en_US", variables: ["Ana", "tomorrow at 9:30"])

An assistant connected over MCP has the same as the tool template, and any server with a key of your org asks POST /v1/agents/{agent}/template (WhatsApp API, "The agent writes first").

The sandbox never sends a template. There the answer is the same, marked simulated, and nothing reaches Meta or anybody's phone: no message is charged and the agent needs no WhatsApp number. So an agent's tests can hand conversations over, remind and notify as often as they run. Send your templates through Pinecall rather than with Meta's token in your own code: a token set among the sandbox's secrets sends, and bills, for real.

Put the message on the conversation#

Pinecall sends the template by its name: the words it says are kept at Meta. Pass them as text, and they become the first message of the contact's conversation:

Terminal
pinecall template reminder visit_reminder --to +14155550142 --language en_US --var Ana --var "tomorrow at 9:30" \
  --text "Hi Ana, your cleaning is tomorrow at 9:30. Reply here to change it." --prod
  • What the contact answers reaches the agent with those words before it: a "yes" is read as the answer to what you asked, not as a message from nowhere.
  • The message shows on the contact's thread in Calls, as the agent's.
  • metadata travels with the conversation (--metadata '{"visit": "v-812"}', or metadata in a flow's step), so the agent knows which visit, order or listing this is about.
  • A contact who is already talking to the agent is written on that conversation, and no template is sent: inside the 24 hours a plain message is free.

In a flow it is step.template(phone, Reminder, "visit_reminder", { language, variables, text, metadata }), and the answer carries call, the conversation. Somebody must be running the agent.

A contact who asked for no more messages is written to by nobody, in either environment. What Meta refuses, a template it does not know or a number that is not on WhatsApp, comes back in Meta's own words. With no text the template is shown on no thread: when they answer, that message opens a conversation as any other does.

Reading and joining#

Open Calls in the console and pick WhatsApp in Showing. A contact is one thread, with every conversation they had with the agent. While a conversation is open, a person with the talk scope can write into it, and the message goes to the contact as the agent. A person with the supervise scope can take it over: the contact's messages are kept and the model is not asked until the conversation is released.

Once a conversation went quiet it is sealed, and nobody can write into it: the contact's next message opens a new one. Past 24 hours since the contact last wrote, Meta lets no free message through at all: only a template does (The agent writes first).

A WhatsApp route receives messages and replies from the same number. The number can also answer the phone: that is a second route of the same number, added like any phone number, and each is let go on its own (pinecall numbers drop <number> --channel whatsapp).

Next steps#