In this section (24)

Identify signed-in users in the messenger

Sign your logged-in customers in to the messenger with a JWT so their history follows them.

1 min read

Available on Starter, Growth, Pro, Enterprise. Compare plans

By default, messenger visitors are anonymous. If your customers sign in to your website or app, you can pass who they are to the messenger. Their conversations then belong to their ChaosDesk profile and follow them across devices.

How it works

  1. Your server signs a short token (a JWT) for the signed-in customer.
  2. Your page passes it to the messenger with zE('messenger', 'loginUser', ...).
  3. ChaosDesk checks the signature and links the visitor to the customer with that external id, or that verified email address, or creates a new customer. An anonymous conversation they already started moves over.

Never sign the token in the browser: the secret must stay on your server.

Set up signing

  1. Open Admin Center, Channels, Messenger and choose Edit settings for the brand.
  2. Open Authenticated customers (JWT).
  3. Choose the Signing method:
    • HS256 shared secret: enter a Shared secret that your server also knows.
    • RS256 with a JWKS URL: sign with your own key pair and enter the URL where your public keys are published.
  4. Note the Key id. Your token header must carry it as kid.
  5. Save.

The token

Claims:

  • scope: "user";
  • external_id: your user id (required);
  • name, email and email_verified;
  • exp (optional): when the token expires.

Call the messenger

zE('messenger', 'loginUser', function (callback) {
  fetch('/my-app/chaosdesk-jwt').then((r) => r.text()).then(callback);
});

When the customer signs out of your site, call zE('messenger', 'logoutUser'). The next conversation starts anonymous.

Full details are in the messenger SDK reference.

Was this article helpful?