Chat and knowledge

Signed-in users

Tell the chat who is logged in, signed by your server, so your team sees verified names and lookups can fetch the customer's own data.

If your app has logged-in users, you can pass who they are to the chat. Your server signs the user's email and ID with a secret only it knows, and PandaDesk checks the signature, so nobody can pretend to be someone else.

What it gets you

  • Your team sees the customer's real name and email, marked Verified, instead of a visitor tag like Visitor 4F2A.
  • A signed-in customer keeps the same conversations on every device and browser.
  • Lookups, which fetch the customer's own data from your backend, only work for verified customers.

How it works

  1. Copy the identity secret from Settings → Security. Store it in your server's environment as PANDADESK_IDENTITY_SECRET. Never put it in browser code or commit it.
  2. On each page load, your server builds a signature for the logged-in user.
  3. The page passes the result to the chat with PandaDesk('identify', …).
  4. On logout, call PandaDesk('reset').

The payload

The signature is an HMAC-SHA256, in lowercase hex, of these five lines joined with \n:

pandadesk-identity:v1
<your workspace public key, pk_…>
<email, trimmed and lowercased>
<user ID, trimmed>
<issuedAt: Unix time in seconds>
  • Send at least an email or a user ID. Use an empty string for the one you don't have.
  • A signature is valid for one hour after issuedAt (and up to 2 minutes ahead, for clock drift). Make a fresh one per page load.
  • The identity object you pass to the chat is { email, userId, name, issuedAt, signature }. name isn't signed; it's only a display name.

Server examples

Node.js

import { createHmac } from "node:crypto";

export function pandadeskIdentity(user) {
  const email = (user.email ?? "").trim().toLowerCase();
  const userId = String(user.id ?? "").trim();
  const issuedAt = Math.floor(Date.now() / 1000);
  const payload = ["pandadesk-identity:v1", "pk_YOUR_KEY", email, userId, issuedAt].join("\n");
  const signature = createHmac("sha256", process.env.PANDADESK_IDENTITY_SECRET).update(payload).digest("hex");
  return { email, userId, name: user.name, issuedAt, signature };
}

Python

import hashlib, hmac, os, time

def pandadesk_identity(user):
    email = (user.email or "").strip().lower()
    user_id = str(user.id or "").strip()
    issued_at = int(time.time())
    payload = "\n".join(["pandadesk-identity:v1", "pk_YOUR_KEY", email, user_id, str(issued_at)])
    signature = hmac.new(os.environ["PANDADESK_IDENTITY_SECRET"].encode(), payload.encode(), hashlib.sha256).hexdigest()
    return {"email": email, "userId": user_id, "name": user.name, "issuedAt": issued_at, "signature": signature}

PHP

function pandadesk_identity($user) {
    $email = strtolower(trim($user->email ?? ''));
    $userId = trim((string) ($user->id ?? ''));
    $issuedAt = time();
    $payload = implode("\n", ['pandadesk-identity:v1', 'pk_YOUR_KEY', $email, $userId, (string) $issuedAt]);
    $signature = hash_hmac('sha256', $payload, getenv('PANDADESK_IDENTITY_SECRET'));
    return ['email' => $email, 'userId' => $userId, 'name' => $user->name, 'issuedAt' => $issuedAt, 'signature' => $signature];
}

Ruby

require "openssl"

def pandadesk_identity(user)
  email = user.email.to_s.strip.downcase
  user_id = user.id.to_s.strip
  issued_at = Time.now.to_i
  payload = ["pandadesk-identity:v1", "pk_YOUR_KEY", email, user_id, issued_at.to_s].join("\n")
  signature = OpenSSL::HMAC.hexdigest("SHA256", ENV.fetch("PANDADESK_IDENTITY_SECRET"), payload)
  { email: email, userId: user_id, name: user.name, issuedAt: issued_at, signature: signature }
end

In the page

Render the object your server returned into the page and pass it to the chat:

<script>
  window.PandaDesk = window.PandaDesk || function () { (window.PandaDesk.q = window.PandaDesk.q || []).push(arguments) };
  PandaDesk('identify', identityFromYourServer);
</script>

Call PandaDesk('reset') when the user logs out, so the next person on that browser starts a fresh chat.

Identity modes

Choose under Settings → Security:

Mode What happens to an unsigned or invalid identity
Report only (default) The name and email are kept but shown to your team as Unverified. They never give access to anyone else's conversations.
Enforced Unsigned names and emails are dropped. Only signed identities are used.

Rotating the secret

Rotate the secret under Settings → Security if it may have leaked. The old secret stops verifying immediately, so update your server's environment straight away.

With your coding agent

Ask your agent to "wire up PandaDesk signed identity". It uses get_embed_code (its signedInUsers section has browser, Node and Python code) and get_identity_secret to put the secret in your server's environment. update_security switches between report-only and enforced: npx pandadesk update_security --identity-mode enforced.

View as Markdown