Users & Data
Identity verification: securely identify signed-in users
Securely identify signed-in users in your chatbot: sign the user ID with HMAC-SHA256 on your server. Examples in Node.js, Python, PHP, Ruby, and Go.
When a signed-in user opens the chat, you can pass their ID along with a signature made on your server. Assistrio checks the signature, so nobody can pretend to be another user by editing the page. If the ID matches a contact, the agent knows that person's name, email, phone, and attributes — and can answer “What plan am I on?” without asking.
How it works
- 1
Get your secret key
Open the agent's Deploy page and copy the Secret key under Identity verification. Store it on your server as
ASSISTRIO_SECRET_KEY. - 2
Sign the user ID on your server
Compute
userHash= HMAC-SHA256 of the user ID (as a string), keyed with the secret key, as lowercase hex. - 3
Pass both to the widget
Add
userIdanduserHashtowindow.AssistrioChatConfig(orAssistrioCenterStageConfig), or append&userId=…&userHash=…to the iframesrc.
Server code
import crypto from "node:crypto";
const secret = process.env.ASSISTRIO_SECRET_KEY; // Your secret key
const user = await getSignedInUser(); // The signed-in user
const userHash = crypto
.createHmac("sha256", secret)
.update(String(user.id))
.digest("hex");import hashlib, hmac, os
secret = os.environ["ASSISTRIO_SECRET_KEY"].encode() # Your secret key
user = get_signed_in_user() # The signed-in user
user_hash = hmac.new(secret, str(user.id).encode(), hashlib.sha256).hexdigest()$secret = getenv('ASSISTRIO_SECRET_KEY'); // Your secret key
$user = getSignedInUser(); // The signed-in user
$userHash = hash_hmac('sha256', (string) $user->id, $secret);require 'openssl'
secret = ENV['ASSISTRIO_SECRET_KEY'] # Your secret key
user = current_user # The signed-in user
user_hash = OpenSSL::HMAC.hexdigest('SHA256', secret, user.id.to_s)import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"os"
)
secret := []byte(os.Getenv("ASSISTRIO_SECRET_KEY")) // Your secret key
user := getSignedInUser() // The signed-in user
mac := hmac.New(sha256.New, secret)
mac.Write([]byte(user.ID))
userHash := hex.EncodeToString(mac.Sum(nil))Page code
<script>
window.AssistrioChatConfig = {
agentId: "YOUR_AGENT_ID",
apiBaseUrl: "https://chat.assistrio.com",
position: "right",
userId: "<%= user.id %>",
userHash: "<%= user_hash %>"
};
</script>In Next.js, compute the hash in a Server Component (such as app/layout.tsx) or a Route Handler — never in a "use client" file.
Rules and errors
- Send both values or neither. A
userIdwithout auserHash, or a hash that doesn't match, is refused. userIdcan be up to 200 characters. Use a stable ID from your system, not an email address that can change. To match a contact, it must equal the contact'sexternal_id(up to 128 characters).- In a single-page app, call
window.AssistrioChat.mount({ userId, userHash })after sign-in to reload the chat as that user. - Visitors who aren't signed in can still chat as guests — just leave both fields out.
- If your secret key leaks, rotate it on the Deploy page and update the environment variable on your server.
Shopify and WooCommerce
The Deploy › Shopify and Deploy › WordPress panels have ready-made signed-in snippets — Liquid for Shopify, PHP for WooCommerce. They use IDs like shopify:<customer id> and woocommerce:<WordPress user id>.
Was this page helpful?
Need help? Contact support — we reply within one to two business days.
