AskMavis
HelpChangelogRoadmapFeedback
  • Getting started
  • Your AI agent
  • Actions and procedures
  • Install your agent
    • Add the messenger to your website
    • Share a chat page link
    • Sign in your visitors (identity verification)
    • Add your agent to a Next.js site on Vercel
  • Helpdesk
  • Contacts
  • Help center and boards
  • Workspace and account
  • FAQ
Install your agent

Sign in your visitors (identity verification)

Let your agent recognise signed-in customers securely, so nobody can pretend to be someone else.

AT
Written by AskMavis Team
Published 41m ago

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

  1. Open your agent and go to Install.
  2. Open Advanced at the bottom of the page. Under Identity verification, click Create secret.
  3. 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 (or sub): required, your customer's stable ID
  • email and name: recommended
  • exp: required, an expiry a few hours ahead at most. Tokens without exp are 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.

Related

  • Custom actions
  • Add the messenger to your website

Was this article helpful?

Contact support

Related articles

  • Add the messenger to your websitePaste one snippet to put your AI agent on any website, with steps for popular site builders.
  • Share a chat page linkGive your AI agent its own page, with the chat already open, to share in emails, social profiles or a QR code.
  • Add your agent to a Next.js site on VercelLoad the messenger in a Next.js or Vercel project using an environment variable.
← Back to Help Center

On this page

  • Before you start
  • 1. Create a secret
  • 2. Sign a token on your server
  • 3. Pass the token to the messenger
  • 4. Choose how strict to be
  • Test it
  • Related
Powered by AskMavis