# WhatsApp

Before you publish, test from the **WhatsApp** tab of the inbox's **Test**
page. Your own number is connected in **Channels → WhatsApp**, once you
publish (`vatio whatsapp` prints the link). What that page opens depends on the
environment the inbox shows, picked at the top of its rail: on **preview**, the
shared preview number and your test phones; on **live**, your own number.
Before you publish, the link `vatio whatsapp` prints opens preview.

## Test with the shared preview

You do not need your own Meta account.

1. Open **Test → WhatsApp**. A phone you already verified on another
   workspace you own is listed under **You already verified these numbers**:
   choose **Use on preview** and it is connected, with no code.
2. Otherwise, under **Connect your phone**, scan the QR code with your phone.
   WhatsApp opens on the shared preview number with a message already written
   that carries a 6-character code of letters and digits; send it. With no
   camera at hand, send that code to the preview number yourself: the page
   shows both. That message is what proves the phone is yours. Vatio confirms
   it on WhatsApp right away, and the page updates by itself.
3. Write to the agent from that phone, and read the conversation in the
   inbox's **Conversations**, on preview. Under each of the agent's replies is
   what it did: the tools it called and what they returned, and the knowledge
   it read.

To start over, send `/new`. The next message begins a new
conversation, signed out, instead of continuing the current one until it has
been quiet for eight hours. It works only on the shared preview number.

To test from more phones, choose **Add another number** under the list; it
shows a new QR code.

A test phone reaches `preview`, never live: that is your own number.

You can register up to five test phones per workspace. A code lasts 15 minutes
and works once; the QR code on the page renews itself. A verified phone can
route to only one workspace at a time: sending another workspace's code from
it, or choosing **Use on …** there, moves it to that workspace.

## Connect your business number

For live traffic, open **Channels → WhatsApp** on live and choose
**Connect WhatsApp**. Complete Meta's signup in the window that opens.
**Publish to live** on the **Test** page publishes through the same checks
as [`vatio publish`](https://vatio.ai/docs/deployments#publishing); after the first publish,
**Published. Next: put it in your app** starts the same signup.

A newly connected number is paused: it keeps working exactly as before until
you switch **Live** on, which is what starts replies from your live
deployment — publish your agent first. The same page says whether Meta is
delivering the number's messages; **Verify** runs that check again and
resubscribes the number. Switching **Live** off pauses replies; deleting the
integration removes the connection. **Renew access token** reconnects the same
number. Delete the integration first to change numbers.

### Who the agent answers

By default the agent answers everyone who writes to your number. To have it
answer only some numbers, while you answer the rest yourself, list them under
**The agent answers** on the same page, one per line with the country code, or
run `vatio whatsapp only +56912345678`. Everyone else's messages still arrive
in [the inbox](https://vatio.ai/docs/channels/inbox); the agent just does not answer them. The
numbers of your [Claude Code routines](https://vatio.ai/docs/integrations/claude-routines) always
count. Empty the list, or run `vatio whatsapp everyone`, to answer everyone
again.

Set the list before you switch **Live** on, and the agent never answers
anyone else.

### When your client has the number

The number is often your client's, under a Facebook account you do not have.
Under **Does your client have the number?** on the same page, enter their
email and choose **Invite to connect**. They join the workspace as a
supervisor and get an email linking to a page where they complete Meta's
signup from their own account; the same page renews the access token later.
Below the form, the page shows how far each person you invited has got:
invite sent, email link opened, connect page reached (which means signed in),
in Meta's signup, left it without finishing (and at which step), or
connected, with the full history a click away. You get an email once
the number is connected. It still arrives paused, and
switching **Live** on, **Verify** and deleting the integration stay in
**Channels → WhatsApp**. The link under the form opens that page for anyone already on your
team, and for nobody else.

The connection flow supports keeping your WhatsApp Business phone app.
A reply sent from that app starts human takeover on the conversation; release
the chat in [the inbox](https://vatio.ai/docs/channels/inbox) when the agent should resume.

An edit, by the contact or from that app, within WhatsApp's 15 minutes,
rewrites the message in place: the inbox marks it **Edited** and the agent reads
the new text from then on. It is not a new message, so the agent does not answer
it and it starts no takeover. A message deleted for everyone, by the contact
within WhatsApp's two days or from that app, is deleted from Vatio too: it
leaves the inbox and the agent's history.

A forwarded message keeps WhatsApp's label: the inbox marks it **Forwarded**, or
**Forwarded many times** past five forwards. The agent knows the words came
from another chat, so it takes them as something the contact is showing it
rather than their own request, and does not vouch for what a chain message
claims.

A private tool needs the contact signed in. With `auth.sign_in_url` set, Vatio
sends them a **Sign in** button that opens your site, and the conversation
carries on once they are back. See [On WhatsApp and Instagram](https://vatio.ai/docs/authentication/sessions#on-whatsapp).

When a conversation wraps up, Vatio asks the contact how it went: a few
seconds after the agent's last message, a question in the agent's own words
with three buttons, **Good**, **So-so** and **Bad**. It asks once per
conversation, and not if the contact writes again first. The answer lands in
[the inbox](https://vatio.ai/docs/channels/inbox), next to the
[widget's](https://vatio.ai/docs/channels/widget#visitor-feedback), and never reaches the agent.

## Send from your backend

Your backend can also write first: it calls
[`POST /api/server/v1/:slug/messages`](https://vatio.ai/docs/api/messages) with a number and a
brief, such as "order #1042 shipped today", or with your own `text`. If the
person wrote in the last 24 hours, your text goes out as is, or the agent
writes the message from the brief. Otherwise WhatsApp only delivers an approved
template, so send one along and Vatio uses it; create it with
[`vatio templates create`](https://vatio.ai/docs/cli/webhooks#templates). When the person answers, the
agent has the brief in front of it, and your backend hears about it through a
webhook.
