#Sessions and channels
#On the web
Render the token onto the widget's script tag. Signed-out visitors simply get no token, and the agent answers with its public tools.
<script src="https://cdn.vatio.ai/v1/widget.js" data-workspace="acme" data-token="vatpub_..." <%= "data-visitor-token=\"#{visitor_jwt}\"".html_safe if current_user %>></script>To sign someone in without reloading the page:
window.VatioWidget.identify(newToken); // null to sign outThe browser SDK takes the same token as visitorToken, the iOS SDK as
VatioChat(vatio, visitorToken:) and the Android SDK as
VatioChat(vatio, visitorToken = ...).
#Signing in mid-conversation
A visitor asks something, the agent tells them to sign in, they do, and they
come back. The conversation survives. Whether they signed in through
identify() or by navigating away and reloading the page with a token, the
chat they already had is carried over and now has a name on it — so the agent
can answer the question that prompted the login without them retyping it.
| Before | After | What happens |
|---|---|---|
| anonymous | signed in | Same conversation, now identified |
| user A | user A, newer token | Same conversation, token refreshed |
| user A | user B | New conversation |
| signed in | signed out | New conversation |
The last two are the shared-laptop case: a conversation that belonged to one
sub is never handed to another, so signing in as someone else looks exactly
like arriving for the first time. Vatio enforces that server-side — the page
cannot opt out of it.
Refreshing is also how a web session stays alive: render a fresh token on each
page load and a long-running conversation keeps working past the first token's
exp.
#On WhatsApp and Instagram
A WhatsApp or Instagram chat has no page to render a token onto. Vatio gets one in two ways, in this order:
- Ask your backend by number (
identify_url, WhatsApp only). When someone writes, Vatio asks your API who that number is. If it is one of your users, the conversation starts signed in and they never see a button. - Send them to sign in (
sign_in_url). When nobody answered for the number and a private tool needs to know who they are, the contact gets a Sign in button. This is the fallback, and the only way on Instagram.
Both are fields of set_auth, next to the public key
(Set it up):
{ "workspace": "acme", "identify_url": "https://api.acme.com/vatio/identify", "sign_in_url": "https://acme.com/vatio/sign-in"}identify_url is asked first, and sign_in_url is the fallback. get_agent
shows both under auth.
Either works on its own; with both, most of your users are recognized without doing anything, and anyone the first one misses can still sign in.
#Recognizing a number: identify_url
You do not upload your users to Vatio. Vatio asks about the people who write, when they write: the first time a WhatsApp number writes, and again once their token has expired, Vatio sends your backend one request before the agent answers.
POST https://api.acme.com/vatio/identifyContent-Type: application/jsonVatio-Event: contact.identifyVatio-Signature: t=1696262400,v1=5257a8...
{ "event": "contact.identify", "channel": "whatsapp", "phone": "+56911111111", "workspace": "acme", "environment": "live" }Answer with one of two things:
| Response | Meaning | What Vatio does |
|---|---|---|
200 { "identity": "<jwt>" } | This number is my user | The contact is signed in, exactly as if they had used the sign-in button |
404 | I do not know this number | The contact stays anonymous; the sign-in button is still there for a private tool |
The identity is the same JWT you put on the widget: signed with your key, aud
your workspace slug, sub your user's id. It must carry a phone_number
claim equal to the phone in the request; one that does not is refused. Its
name claim is how the agent greets them, and its exp how long they stay
signed in (a week, as for the sign-in button, is a good default).
Verify the request before you answer it. Whatever your endpoint returns is
a key to that user's account, so it must only ever answer Vatio. The request is
signed exactly like a webhook, with the same secret:
the whsec_ of your webhook endpoint for the same conversations (a live
endpoint for your customers', live in the request's environment, or a test
one for your team's on Vatio's shared number, preview). You already have it
if you receive webhooks; if not, create an endpoint once in the inbox under
Settings → Webhooks and keep the secret it shows. The MCP cannot create
one: the secret is shown once, to a person, and a chat transcript is no place
for it (Webhooks).
Vatio-Signature is t=<unix time>,v1=<hex HMAC-SHA256 of "<t>.<raw body>">,
with one v1 per endpoint that hears those conversations, so whichever secret
you hold verifies it. Reject a request where none matches or whose t is more than five
minutes old.
There is no separate secret to manage: it is the one Vatio already uses for
everything it sends your backend, and an endpoint for your team's
conversations signs the requests about your team's phones, so staging
verifies with its own. Without a webhook endpoint Vatio
never calls identify_url, and set_auth warns about it.
In Rails, with vatio-sdk, the same webhook_secret your webhook
receiver uses:
class VatioIdentifyController < ActionController::API def create # Checks Vatio-Signature and its age, then returns the parsed body. request_body = Vatio::Server::Webhook.verify!(payload: request.raw_post, signature: request.headers["Vatio-Signature"], secret: Vatio::Server.config.webhook_secret)
user = User.find_by(phone: request_body["phone"], phone_verified: true) return head :not_found unless user
render json: { identity: Vatio::Identity.token_for( subject: user.id, expires_in: 7.days.to_i, claims: { name: user.name, phone_number: user.phone } ) } rescue Vatio::Server::Webhook::InvalidSignature head :unauthorized endendOnly answer for a number you have verified yourself. Vatio vouches for one
thing: Meta delivered the message from that number. Whether that number is
enough to be the account is your decision, and it is only as good as how the
number got into your database. Answer 200 for users who confirmed their phone
with you (a code by SMS or WhatsApp, for example); for anyone else, and for
accounts where the phone alone should not be enough, answer 404 and let the
sign-in button do it. A 404 is always safe.
It never holds up a reply. Your endpoint has 2 seconds to connect and 3 to
answer. A timeout, an error or a token that does not verify leaves the contact
anonymous for that conversation, and the agent answers as usual. A 404 is
remembered for a day and an error for ten minutes, so a number you do not know
is not asked about on every message. A contact with no number (someone who
adopted a WhatsApp username) is not asked about at all; the sign-in button
still works for them.
#The sign-in button
When a private tool runs for a contact who is not signed in, the agent answers first, and Vatio sends a message with a Sign in button right after it, as a separate message. The inbox shows it with the button under it:
- The button opens
sign_in_url?code=.... The code works once, for 10 minutes. If they write again without having signed in, the next private tool sends a new button. - Your page signs them in the way your site already does. If they are already signed in on that phone, there is nothing to type.
- It redirects to
https://vatio.ai/connect/<code>?token=<jwt>, with the same JWT you put on the widget. - Vatio verifies it, and the conversation picks up where it left off: the agent runs the tool it was waiting on.
With vatio-sdk the page is one redirect:
redirect_to Vatio::Identity.sign_in_redirect_url( code: params[:code], subject: current_user.id, claims: { name: current_user.name, phone_number: current_user.phone }), allow_other_host: trueWithout it, sign the JWT as you do for the web and redirect to
https://vatio.ai/connect/${code}?token=${jwt}. Always to that host, never to
one taken from the request.
That redirect has to be a full page load. When the contact was not signed
in, your login sends them back to this page and this page on to vatio.ai. If
your login form submits with fetch (Turbo, the Rails default, does), the
browser cannot follow a redirect to another site from it: the login page just
sits there and the conversation never hears about it. In Rails, answer Turbo's
request with a reload (vatio-sdk
shows how); in a single-page app, send the browser to this page with
window.location.assign, not a router push.
The token stays with the contact, so later conversations start signed in until
its exp, and then the button goes out again. Give it a longer exp than a web
token (the gem uses a week): the web gets a fresh one on every page load,
WhatsApp only when the contact signs in.
Confirming the number. A link can be forwarded: someone could ask for a
button on their own WhatsApp and send it to one of your users, whose account
would then answer on the wrong phone. So Vatio shows what is being connected
(•••• 5678 on WhatsApp, @handle on Instagram) and asks the person to
confirm. On WhatsApp, put a phone_number claim in the token and, when it
matches the WhatsApp number, that step is skipped. Instagram has no number to
match, so there it is always asked.
Your API sees nothing new: a private tool sends the same $auth.token, and you
verify it the same way.