If your website has customer accounts, identity verification lets the messenger know who each signed-in customer is. Your server signs a token with a secret only you know, so nobody can pretend to be another customer. Your team sees each signed-in customer as one contact with their name and email, whichever device they use, and your agent can run actions that need a verified customer. Each device keeps its own chat history: a chat started on one device isn't shown on another yet.
Before you start
You need a developer who can change your website's server code.
1. Create a secret
- Open your agent and go to Install.
- Open Advanced at the bottom of the page. Under Identity verification, click Create secret.
- Copy it into your server's environment now, for example as
ASKMAVIS_IDENTITY_SECRET. It won't be shown again. Never put it in browser code.
Rotate secret creates a new one. Tokens signed with the old secret stop working, so every visitor is signed out until your server uses the new one.
2. Sign a token on your server
After a customer signs in, sign an HS256 JWT with the secret. Include:
user_id(orsub): required, your customer's stable IDemailandname: recommendedexp: required, an expiry a few hours ahead at most. Tokens withoutexpare refused.
// Node.js, using the jsonwebtoken package
const token = jwt.sign(
{
user_id: user.id,
email: user.email,
name: user.name,
exp: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour
},
process.env.ASKMAVIS_IDENTITY_SECRET,
{ algorithm: 'HS256' },
);
3. Pass the token to the messenger
On the page, after the install code:
window.AskMavisMessenger.push({ command: 'identify', token });
When the customer signs out:
window.AskMavisMessenger.push({ command: 'resetUser' });
4. Choose how strict to be
Under Verification, pick:
- Off: everyone chats as an anonymous visitor. Tokens are ignored.
- Verify when sent: signed-in customers are recognised from their token. Visitors without a valid token chat anonymously.
- Require sign-in: only visitors with a valid token can chat. Use this when the widget lives inside your logged-in app.
Test it
In the Playground, use Chat as user to see how your agent answers a signed-in customer.