Guide
Identify widget visitors
Sign a short token on your server so chat conversations carry the signed-in person, and nobody can pretend to be them.
By default a chat in the widget is anonymous until the visitor leaves an email. When people are signed in to your app, your server can vouch for who they are with a signed identity token. The conversation then carries their name and email and joins their contact.
#1. Get the secret
Settings → Widget → Install → Recognize signed-in people → Copy the secret. Owners and admins can copy it again any time; the page never shows it, and its last four characters let you check which secret your server holds. Put it in your server's environment as HELPWELL_IDENTITY_SECRET. It is a different secret from your API key, and it never goes to the browser.
#2. Sign a token for the signed-in person
The token is a JWT signed with HMAC-SHA256 (HS256). sub is required: your user id as a string, the same value you send as externalId in the API, so the chat and the contact meet. Add email and name, and an exp an hour away. avatarUrl, createdAt, locale and timezone are optional; any other claim becomes a contact field.
import { createHmac } from 'node:crypto';
export function helpwellToken(user) {
const b64 = (value) => Buffer.from(JSON.stringify(value)).toString('base64url');
const now = Math.floor(Date.now() / 1000);
const body = `${b64({ alg: 'HS256', typ: 'JWT' })}.${b64({
sub: String(user.id), email: user.email, name: user.name, iat: now, exp: now + 3600,
})}`;
const signature = createHmac('sha256', process.env.HELPWELL_IDENTITY_SECRET).update(body).digest('base64url');
return `${body}.${signature}`;
}import os, time, jwt
def helpwell_token(user):
now = int(time.time())
return jwt.encode(
{"sub": str(user.id), "email": user.email, "name": user.name, "iat": now, "exp": now + 3600},
os.environ["HELPWELL_IDENTITY_SECRET"],
algorithm="HS256",
)require "jwt"
def helpwell_token(user)
now = Time.now.to_i
JWT.encode({ sub: user.id.to_s, email: user.email, name: user.name, iat: now, exp: now + 3600 },
ENV.fetch("HELPWELL_IDENTITY_SECRET"), "HS256")
enduse Firebase\JWT\JWT;
function helpwell_token($user) {
$now = time();
return JWT::encode(
['sub' => (string) $user->id, 'email' => $user->email, 'name' => $user->name, 'iat' => $now, 'exp' => $now + 3600],
getenv('HELPWELL_IDENTITY_SECRET'),
'HS256'
);
}import (
"os"
"time"
"github.com/golang-jwt/jwt/v5"
)
func HelpWellToken(id, email, name string) (string, error) {
now := time.Now()
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": id, "email": email, "name": name, "iat": now.Unix(), "exp": now.Add(time.Hour).Unix(),
})
return token.SignedString([]byte(os.Getenv("HELPWELL_IDENTITY_SECRET")))
}#3. Hand it to the widget
Either put it on the script tag your page already has:
<script src="…loader.js" data-api="…" data-token="TOKEN_FROM_YOUR_SERVER" defer></script>
or pass it after sign-in, and clear it on sign-out:
helpwell('identify', tokenFromYourServer);
// …
helpwell('reset'); // on sign-out
#Check it
Signed in to your app, open the widget and send a message. In HelpWell's inbox the conversation shows your name and email. Decode a token at jwt.io (header and payload only, never the secret): alg is HS256 and sub is your user id.
Then send the same person's fields and events with the API (Send signups from your app).