Developers · Raha chat

Tell Raha who your signed-in customer is.

Raha chat is anonymous by default. If your site has customer accounts, your server can sign the customer's ID, and the same customer then keeps one conversation on every phone and laptop. The browser never holds a secret.

  • Optional
  • HMAC-SHA256
  • Server-side signature
  • Business and Pro plans

How it works

Identity verification is optional. Without it, every visitor is an anonymous visitor, and a conversation belongs to one browser.

  1. Your server

    Knows who is signed in. Signs the user's ID with the identity secret and renders the result into the page.

  2. The page

    Forwards the finished user object to the chat with RahaChat.setUser. It holds no secret.

  3. Raha

    Checks the signature with the same secret. A correct one makes the visitor that user; a wrong one leaves them anonymous.

  • One customer, one conversation. A signed user's conversation follows them across devices and browsers. The Inbox shows their name.
  • An anonymous chat is kept. If an anonymous visitor signs in and the signed user has no conversation yet, that conversation becomes theirs. If the user already has one, the chat continues there and the anonymous one stays as a separate conversation in the Inbox. Raha never merges two conversations.
  • A wrong signature is not an error. The visitor simply stays anonymous, and the chat works as before.
  • It is off until the owner turns it on. In the Raha app: Channels, Website chat, Raha chat, settings, "Verify signed-in visitors".

Get the identity secret

  1. Create the chat in the Raha app

    Channels, Website chat, Raha chat. When the chat is created, the app shows the chat key (wk_…, public) and the identity secret (wis_…) once. Copy the secret to your server's secret manager at once: it is never shown again.

  2. Turn on "Verify signed-in visitors"

    In the chat's settings. While it is off, Raha ignores any identity your page sends.

  3. Give your server the key and the secret

    As two environment variables (the examples below use RAHA_CHAT_KEY_ID and RAHA_CHAT_IDENTITY_SECRET).

Key and secret
ValueLooks likeWhere it lives
Chat keywk_ and 22 letters or digitsPublic. It is in your snippet and in every signature.
Identity secretwis_ and 43 charactersYour server only. Shown once at creation and once after each rotation.

Sign the user on your server

Your server computes one HMAC-SHA256 per signed-in customer and per page load.

signature = hex(HMAC-SHA256(identity_secret, "v1\n" + key_id + "\n" + user_id + "\n" + issued_at))

The string that is signed
v1
wk_9mXq2LrT7vKd4HsEw1ZbPa
user_8421
1792843200
The user object
FieldRequiredRule
user_idRequiredYour stable ID for the customer: 1 to 100 characters of A-Z a-z 0-9 . _ @ + -. Never a value the browser can choose.
issued_atRequiredUnix time in seconds when your server signed. It is valid for up to 7 days after it, and up to 5 minutes ahead of Raha's clock. Sign on every page load.
signatureRequiredLower-case hexadecimal, 64 characters, of the HMAC above.
nameOptionalShown in the Inbox. Up to 128 characters. It is not part of the signature.
emailOptionalKept on the customer's profile. Up to 254 characters. It is not part of the signature.

Examples#

const crypto = require("node:crypto")

const KEY_ID = process.env.RAHA_CHAT_KEY_ID // wk_… (public, also in your snippet)
const IDENTITY_SECRET = process.env.RAHA_CHAT_IDENTITY_SECRET // wis_… (server only)

function signWidgetUser(user, issuedAt = Math.floor(Date.now() / 1000)) {
  const base = ["v1", KEY_ID, user.id, String(issuedAt)].join("\n")
  const signature = crypto.createHmac("sha256", IDENTITY_SECRET).update(base).digest("hex")
  return { user_id: user.id, name: user.name, email: user.email, issued_at: issuedAt, signature }
}

// for example in an Express route that renders the page for a signed-in customer:
//   res.render("page", { raha: JSON.stringify(signWidgetUser(req.user)) })
module.exports = { signWidgetUser }

Pass it to the chat

Render the signed object into the page and call RahaChat.setUser once, after the snippet. If you use the queue stub from the help page, you can call it before the script has loaded.

Pass it to the page
<script>
  // "user" was rendered by YOUR server, already signed. The secret is not in this page.
  var user = {{ signed_user_json }};
  RahaChat.setUser(user);
  // user = {
  //   user_id: "user_8421", name: "Ali Rezaei", email: "[email protected]",
  //   issued_at: 1792843200, signature: "de375ae3b1a1…"
  // }
</script>
  • Call setUser again after sign-in on a single-page app, with a fresh signature.
  • To sign out, reload the page without calling setUser: the visitor is anonymous again.
  • A bad or expired signature, or a chat whose verification is off, leaves the visitor anonymous and shows no error.
Never do this
// WRONG: the secret is now in every visitor's browser, and anyone can sign any user.
RahaChat.setUser({ user_id: "user_8421", issued_at: now, signature: hmac(IDENTITY_SECRET, base) })

Test vector

Check your code against this fixed example before you go live. These are not real credentials.

Test vector
InputValue
Chat keywk_9mXq2LrT7vKd4HsEw1ZbPa
Identity secretwis_Zk3Qv8Nw2Lr7Tx5Yp1Hd9Cm4Bf6Js0Ga8Ue3Oi2RqWz
user_iduser_8421
issued_at1792843200
Signature (hex)de375ae3b1a111a79cb694be05de195d93b7ac0197feb721d22d915247313764

With the previous secret wis_Pq7Lw2Xe9Rt4Yu6Io1As3Df5Gh8Jk0Zc2Vb4Nm7QaS9 the same input gives f17e8ae22a173a0e2c576fc2e417b8a7e96d0c04f0528f87a5ea33de9b03010a. After a rotation Raha accepts both for 24 hours.

Rotating the secret

  • In the Raha app: Channels, Website chat, Raha chat, settings, "Rotate secret". Raha shows the new secret once.
  • The previous secret keeps working for 24 hours, so you can deploy without a gap. The settings page shows when it stops.
  • The chat key never changes, and neither does anything visitors see: only the secret your server signs with.
Change the secret on your server
# after "Rotate secret" in the Raha app: the new secret is shown once.
# The previous one keeps working for 24 hours, so deploy this within a day.
export RAHA_CHAT_IDENTITY_SECRET='wis_…'

Security notes

  • Your server decides who the customer is. Derive user_id from your own session. Never accept it from a request parameter.
  • Sign on the server for each page load. A signature older than 7 days is ignored.
  • Sync your server's clock. A signature more than 5 minutes ahead of Raha's clock is ignored.
  • Do not log signatures or the secret. Log the user ID and the time instead.
  • Send only what helps. name and email are optional.
  • Disconnecting the chat in the app makes its key stop working at once.

If the visitor stays anonymous

Troubleshooting
CheckWhy
Is "Verify signed-in visitors" on?While it is off, Raha ignores setUser.
Does the key in the signature match the snippet's data-key?The key is part of the signed string.
Is issued_at in seconds, and between 7 days ago and 5 minutes ahead?Milliseconds, or a stale or future time, are ignored.
Is the base string exactly v1, key, user ID, time, joined by line feeds?Any extra space or a trailing newline gives another signature.
Did you use the current secret, or the previous one within 24 hours of a rotation?An older secret is refused.
Does the test vector give the same signature in your code?It separates a wrong signature from a wrong setting.

Questions about identity verification? Write to [email protected]. To add the chat to a site first, start with Add Raha chat to your website.