Docs / Build
The chat widget
One script tag adds Dezzi’s chat to any page: a button in the bottom-right corner that opens the person’s conversations, answers that stream in as they’re written, pictures, and the team’s replies once a conversation is handed to you. It draws itself in a shadow root, so your page’s CSS can’t change it, and it weighs about 25 KB.
Install
Add this before </body>, with your app’s public key (pk_…) from the dashboard:
<script src="https://YOUR-DEZZI-HOST/widget.js" data-app="pk_…" defer></script>
The widget talks to the Dezzi address it was loaded from. The public key isn’t a secret: it only names your app. If your site sends a
Content Security Policy, allow the Dezzi address in script-src, connect-src and img-src.
Tell it who the person is
For someone signed in to your app, your server signs a short token that says who they are, and the page hands the widget a function that fetches it. The widget swaps the token for a session of its own, kept in memory (no cookies), and asks for a new token before that session ends, about once an hour. Only then does the assistant get your app’s actions, always for this person.
The token is a JWT signed with HS256 and your app’s user token secret (ut_…), which stays on your server. sub
(your id for the person) and exp (at most a day ahead; ten minutes is plenty) are required; email,
name and up to 20 plain attributes are shown to the assistant. In Node, with nothing to install:
import { createHmac } from 'node:crypto';
const part = (value) => Buffer.from(JSON.stringify(value)).toString('base64url');
export function dezziToken(user) {
const header = part({ alg: 'HS256', typ: 'JWT' });
const claims = part({ sub: user.id, email: user.email, name: user.name, exp: Math.floor(Date.now() / 1000) + 600 });
const signature = createHmac('sha256', process.env.DEZZI_USER_TOKEN_SECRET).update(`${header}.${claims}`).digest('base64url');
return `${header}.${claims}.${signature}`;
}
// A route only signed-in people reach, for example with Express:
app.post('/api/dezzi-token', requireSignIn, (req, res) => res.json({ token: dezziToken(req.user) }));
Then, on the page:
<script>
function startDezzi() {
Dezzi.identify(async () => {
const response = await fetch('/api/dezzi-token', { method: 'POST' });
return (await response.json()).token;
});
}
if (window.Dezzi) startDezzi();
else window.addEventListener('dezzi:ready', startDezzi);
</script>
dezzi:ready fires on window as soon as window.Dezzi exists. When the person signs out, call
Dezzi.logout(): the widget forgets them, closes, and the next person starts afresh.
Visitors and allowed origins
Without identify, the button shows only if your app lets visitors chat (Visitor chat in your app’s settings). A visitor
gets your help content, can report a bug and can ask for the team, but never your app’s actions, since nobody vouched for them. The
widget starts a visitor’s session when they first open the chat, and this browser comes back to the same conversations for 90 days.
List the pages the widget runs on as origins, such as https://www.example.com, in your app’s allowed origins. Once the
list has any, a session is refused from a page that isn’t on it, signed in or not. Visitors need the list: with none, nobody can chat
as a visitor. A new visitor session is limited to 20 an hour from one network.
An app made from its website starts with both done: visitor chat on, and the site and its www. twin listed.
Chat options
A new conversation shows a few buttons, such as Billing and payments or Talk to a person. A press sends the button’s words as the person’s first message. Change them under Settings → Chat options: one a line, up to 6, 60 characters each. Leave the field empty to show none.
React
sdk/react.tsx wraps the same widget. Render <DezziChat> once near your app’s root; it adds the script a
single time. Pass getToken while someone is signed in and leave it out once they sign out, which logs the widget out.
When one person can switch to another without signing out, give it key={user.id}.
import { DezziChat, useDezzi } from './dezzi/react';
export function Root({ user }) {
return (
<>
<App />
<DezziChat
host="https://YOUR-DEZZI-HOST"
appKey="pk_…"
getToken={user ? () => fetch('/api/dezzi-token', { method: 'POST' }).then((r) => r.json()).then((d) => d.token) : undefined}
/>
</>
);
}
function HelpButton() {
const dezzi = useDezzi();
return <button onClick={dezzi.open} disabled={!dezzi.ready}>Contact support</button>;
}
Look
The accent colour is the one in your app’s settings, and the widget follows the person’s light or dark setting. To use another accent on one site, set it on the element:
dezzi-chat { --dezzi-accent: #0f766e; --dezzi-on-accent: #ffffff; }
Below 480 pixels wide the chat fills the screen. Escape closes it, and focus moves into the chat when it opens and back to its button when it closes. Apps on the Developer plan show “Powered by Dezzi” under the composer.
Calls and events
| Call | What it does |
|---|---|
Dezzi.identify(getToken) | The person is signed in; getToken returns a promise of your server’s token. |
Dezzi.open(), Dezzi.close() | Opens or closes the chat, for your own Help button. |
Dezzi.logout() | Forgets the person and this browser’s visitor. |
Dezzi.on(event, fn) | Calls fn(data) on each event; returns a function that stops it. |
| Event | When | data |
|---|---|---|
ready | The app’s settings loaded and the button can show | name |
open, close | The chat opened or closed | |
sent | The person sent a message | conversationId (null for a new conversation) |
message | An answer arrived, from the assistant or the team | conversationId, author (assistant or support), body |
handoff | The conversation went to your team | conversationId |
unread | The number of conversations with a reply from the team the person hasn’t opened changed | count |
error | The widget showed the person an error | message |