Signed-in customers
When a visitor is logged in on your website (a customer portal, an account page), your server can tell Sarthi who they are. The chat then:
- skips the form and greets them by name;
- shows your team "Priya Nair (gold)" instead of "a visitor";
- can use your signed-in roles, knowledge and routing rules (by plan, by any attribute you send);
- can answer from your database about this customer only, and run actions on their account, because Sarthi knows which rows are theirs.
How it works
- Your server signs a short token that says who the user is, using the SDK secret from Widget & SDK. The secret never leaves your server.
- The page starts the widget with a function that fetches that token from your server.
- The widget sends the token when the chat opens. Sarthi checks the signature, that the token is fresh (15 minutes at most) and that it hasn't been used before.
Visitor's browser ──GET /sarthi-token (your login cookie)──▶ Your server
Visitor's browser ◀──{ token } signed with your SDK secret──── Your server
Visitor's browser ──start the chat with the token───────────▶ Sarthi
Visitor's browser ◀──"Welcome back, Priya"────────────────── Sarthi
The page
Load the script without data-site-key, then call init with getEndUserToken:
Pages where your customer is signed in
<script src="https://api.mysarthi.tech/widget/v1.js" async></script>
<script>
window.addEventListener('load', () => {
window.Sarthi.init({
siteKey: 'ws_acme_7f3a9c',
// Each token works once, for 15 minutes: the widget asks for a fresh one when it needs it.
getEndUserToken: () =>
fetch('/sarthi-token', { credentials: 'same-origin' })
.then((r) => r.json())
.then((d) => d.token),
});
});
</script>
getEndUserTokenis called when the widget needs a token: when the chat starts, and again if the visitor starts a new chat later. Return a fresh token every time; each one works once.- On pages where nobody is logged in, call
init({ siteKey })without a token, or use the plain snippet. Don't send a token for a logged-out visitor. - When the user logs out on your site, call
window.Sarthi.destroy()andinitagain (or just reload). A chat started by one person is never shown to another: the widget compares the signed-in id before continuing a stored chat.
The server
The token is a standard JWT (HS256). With the Node.js helper it's one line; any language with a JWT library works the same. See Signing the token on your server.
Testing
Widget & SDK → Test a token takes a token your server made and tells you exactly what's wrong with it, if anything (expired, bad signature, missing user_id…). Testing doesn't use the token up. More in Testing tokens.
What the token unlocks
| In the console | With the token |
|---|---|
| Front desk routing | Rules on plan and on any attrs value you send (if the plan is gold → Priority support). |
| Knowledge | Sources scoped to signed-in chats (a dealer manual, a price list) are only used when there is a token. |
| Databases | Tables with a row filter (customer_id = {token.user_id}) are only read for signed-in visitors, and only their rows. |
| Actions | Signed-in actions fill {user.user_id}, {user.email}… from the token, never from what the visitor typed. |
| Leads | The lead is matched by the signed-in id first, so returning customers are one lead. |
WhatsApp
A phone number isn't proof of identity, so WhatsApp chats are always anonymous: no per-customer database answers there.