Identity verification for the website chat
Tell the agent who a signed-in visitor is with identify and a userHash that your server signs with HMAC-SHA256 and the agent's identity secret.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
Identity verification lets you tell the agent that a visitor is a specific signed-in customer, and lets Askocto trust it. Conversations then follow the customer across devices, and your team sees their name and email in the Helpdesk. Your server signs the user id, so nobody can pretend to be someone else by editing page code.
How it works
- A customer signs in to your site.
- Your server creates a
userHash: an HMAC-SHA256 of the user id, using the agent's identity secret. - Your page passes the id and the hash to
window.askocto.identify. - Askocto recomputes the hash. If it matches, the visitor is treated as that customer.
Get the identity secret
- Open your agent and go to Settings > General.
- Find Identity verification and select Show secret.
- Copy the secret into an environment variable on your server.
- Switch on Require verified identity once your site sends hashes everywhere.
Warning: The identity secret must stay on your server. Never put it in page code, a mobile app or a public repository. Select Rotate secret in the same place if it leaks, then update your server.
Sign the user id on your server
import { createHmac } from "node:crypto"
export function userHashFor(userId) {
return createHmac("sha256", process.env.OCTO_IDENTITY_SECRET)
.update(String(userId))
.digest("hex")
}
Send the hash to the page when the customer signs in, for example in the session payload.
Identify the visitor
window.askocto.identify({
userId: session.userId,
userHash: session.octoHash,
name: session.name,
email: session.email,
metadata: { plan: "pro", country: "NL" },
})
| Field | Description |
|---|---|
userId |
Your own stable id for the customer. Required. |
userHash |
Hex HMAC-SHA256 of userId. Required when verification is on. |
name, email |
Optional. Shown on conversations and tickets. |
metadata |
Optional key and value pairs, saved as contact attributes. |
You should see the customer's name on their conversation in the Helpdesk, and the customer appears under Contacts.
Sign out
When a customer signs out, reload the page and do not call identify. The next visitor is then anonymous and does not see the earlier customer's history. When someone else signs in, call identify with their id and hash.
Troubleshooting
- The
errorevent fires with codeunauthorized. The hash does not match. Sign the exact string you pass asuserId, and use hex output. - The name does not appear. Call
identifybefore the visitor sends a message, or after thereadyevent. - Verification works on staging and not on production. The two environments use different secrets or different agents.
Related pages
- iOS user identity and Android user identity apply the same signing for apps.
- Chatbot event listeners shows how to catch the
errorevent. - Contacts explains how identified customers are stored.