Chatbots
A chatbot is a chat bubble on your website. Visitors open it, get instant answers to the questions you’ve set up, and can write to your team: their messages land in your Inbox right away, and your replies show up in their chat. The bot also asks for their email, so you can still reach them once they’re gone. Everyone who leaves their email becomes a contact and can join your lists.
The bot is scripted, not generative: it only ever says what you wrote. There is nothing to train and nothing that can go off-script.
How a conversation goes
- The visitor opens the chat (or a greeting popup invites them to).
- The bot greets them and offers your quick replies: buttons such as “Pricing” or “Shipping times” that answer instantly, with an optional link.
- When the visitor types a message, it reaches your Inbox right away. The bot asks for their email (and, if you want, their name) so you can reach them if they step away, then confirms: “We’ll get back to you at …”. Leaving it is optional: they can keep chatting either way.
- You get an email about it and answer in the Inbox: your reply shows up in their chat, and if they’ve left their email but don’t see it there within 10 minutes, it’s emailed to them. Later messages from the same browser join the same conversation. Either of you can send pictures too.
Add it to your site
Create a chatbot under Chatbots, then open Install and copy the snippet. It looks like this:
<script src="https://use.letter.app/chat.js" data-chatbot="AbC123xYz789" async></script>
Paste it right before </body> on every page where the chat should appear.
Any site builder that accepts custom code works (Webflow, WordPress, Framer,
Shopify…). The script loads asynchronously and never blocks your page.
You can install the snippet before you publish: a draft chatbot stays hidden, and it appears on your site the moment you publish it.
Next.js and React
Add it once, in your root layout:
import Script from "next/script";
<Script
src="https://use.letter.app/chat.js"
data-chatbot="AbC123xYz789"
strategy="afterInteractive"
/>
The chat survives client-side navigation and keeps the conversation (and whether it was open) as visitors move between pages.
Above or below your own layers
The chat sits on top of everything on the page by default. To keep your
cookie banner or modals above it, give the script tag a data-z-index:
<script src="https://use.letter.app/chat.js" data-chatbot="AbC123xYz789" data-z-index="40" async></script>
It applies to the whole chat (launcher, greeting popup and panel). Only whole numbers are accepted; anything else keeps the default, with a warning in the browser console. Set it per site: the same chatbot can sit at a different level on each site it’s on.
Open it from your own buttons
Add data-letter-chat-open to any element:
<a href="#" data-letter-chat-open>Contact us</a>
Or use the JavaScript API, available on window once the script has loaded:
LetterChat.open(); // open the chat
LetterChat.close(); // close it
LetterChat.toggle(); // open or close
LetterChat.identify({ token }); // your signed-in user (see below)
LetterChat.reset(); // forget the user and this browser's conversation (on sign-out)
Signed-in users
If your site has accounts, tell the chat who’s signed in. Your users are never asked for their email, their conversation is the same in every browser and on every device they use, and your Inbox shows who they are, with the details you choose to pass (plan, credits, team…).
Install > Signed-in users walks you through it with your chatbot’s code filled in. It takes two steps:
-
On your server, get a token for the signed-in user. The simplest way is to ask Letter for one with the Node SDK, using the API key your server already has: there’s no other secret to keep.
const token = await letter.chatToken({ chatbot: "AbC123xYz789", // data-chatbot in the chat's install snippet userId: user.id, email: user.email, name: user.name, data: { plan: user.plan }, });You can also sign the token yourself with the chatbot’s identity secret.
-
In the page, pass it to the chat once the script has loaded, on every page load (and again when the user or their details change). On the pages where a user is signed in, the script tag can do it, with the token rendered in place of
THEIR_TOKEN:
<script src="https://use.letter.app/chat.js" data-chatbot="AbC123xYz789" async
onload="LetterChat.identify({ token: 'THEIR_TOKEN' })"></script>
From your own code, once the script has loaded:
LetterChat.identify({ token });
When the user signs out, call LetterChat.reset(): the chat goes back to an
anonymous visitor and forgets their conversation in this browser. It stays in
your Inbox, and comes back the next time they’re identified.
In Next.js, get the token in the server layout signed-in users see, and pass
it to a small client component that loads the chat and identifies them.
onReady runs again whenever the layout mounts, so client-side navigation
keeps them signed in:
"use client";
import Script from "next/script";
declare global {
interface Window {
LetterChat?: { identify(o: { token: string }): void; reset(): void };
}
}
export function LetterChat({ token }: { token: string }) {
return (
<Script
src="https://use.letter.app/chat.js"
data-chatbot="AbC123xYz789"
onReady={() => window.LetterChat?.identify({ token })}
/>
);
}
Call window.LetterChat?.reset() where they sign out.
Tokens from Letter
letter.chatToken() asks Letter to sign the token with the chatbot’s
identity secret, so the secret never leaves Letter. Tokens last an hour, and
the SDK reuses each user’s until five minutes before it expires, so most page
views make no request. It never throws over the network: when Letter doesn’t
answer within 3 seconds, or refuses (a claim it won’t sign, an unknown
chatbot), it resolves to null and reports why to the client’s onError.
The chat then stays anonymous, and your page renders as usual.
chatbot is the chatbot’s public id. You can leave it out when the project
has a single chatbot, or a single published one, but the snippets Letter
gives you always pass it, so adding a chatbot later never breaks them.
On other stacks, call the endpoint behind it with the same project API key (see the API):
curl https://api.letter.app/v1/chat/token \
-H "Authorization: Bearer $LETTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "chatbot": "AbC123xYz789", "userId": "42", "email": "ada@example.com", "name": "Ada Lovelace" }'
{ "token": "eyJhbGciOiJIUzI1NiIs...", "expiresAt": "2026-10-20T13:00:00.000Z", "expiresIn": 3600, "chatbot": "AbC123xYz789" }
Reuse each user’s token until shortly before expiresAt.
The token’s claims
Whether Letter signs the token or your server does, it carries the same
claims. chatToken() and the endpoint take them as userId, email, name,
avatar, company and data, and set iat and exp themselves.
| Claim | ||
|---|---|---|
sub | required | The user’s id in your app, as a string (userId when Letter signs it). Their conversation is keyed on it, and so is their contact (the same id as in identify calls from the SDK). |
iat, exp | required | When the token was issued and when it expires, in seconds since 1970. Expired tokens are refused, with a minute of leeway for clock differences. An hour is plenty. |
email | optional | Makes them a contact, and the address replies they haven’t seen are emailed to. |
name | optional | Shown in the Inbox; also fills the contact’s name trait if it has none. |
avatar | optional | An http(s) URL to their picture. |
company | optional | { "name": "Acme", "url": "https://acme.com" } |
data | optional | A flat object of strings, numbers and booleans shown next to the chat, e.g. { "plan": "pro", "credits": 120 }. Up to 50 keys of at most 64 characters; strings longer than 256 characters are cut. |
Sign the token yourself
Every chatbot has its own identity secret from the moment it’s created.
Owners and admins can reveal it under Install > Signed-in users (choose
Sign it yourself) or Delivery > Signed-in users. Keep it on your
server as LETTER_CHAT_SECRET, like an API key, and sign a short-lived JWT
(HS256) for the signed-in user with it.
Signing it in Node, with no dependencies:
import { createHmac } from "node:crypto";
export function letterChatToken(user) {
const part = (v) => Buffer.from(JSON.stringify(v)).toString("base64url");
const now = Math.floor(Date.now() / 1000);
const body = part({ alg: "HS256", typ: "JWT" }) + "." + part({
sub: String(user.id),
email: user.email,
name: user.name,
data: { plan: user.plan },
iat: now,
exp: now + 3600,
});
const signature = createHmac("sha256", process.env.LETTER_CHAT_SECRET)
.update(body)
.digest("base64url");
return body + "." + signature;
}
Or with jose:
import { SignJWT } from "jose";
const token = await new SignJWT({ email: user.email, name: user.name, data: { plan: user.plan } })
.setProtectedHeader({ alg: "HS256" })
.setSubject(String(user.id))
.setIssuedAt()
.setExpirationTime("1h")
.sign(new TextEncoder().encode(process.env.LETTER_CHAT_SECRET));
Good to know
- Letter verifies the token before trusting any of it: the signature, the
algorithm (HS256 only),
exp, andsub. A token that doesn’t verify leaves the chat anonymous, with a warning in the browser console saying why, and nothing else changes. - Identify as early as you can. When
identify()comes before the chat appears, the chat waits for Letter’s answer, so a signed-in user never sees the anonymous chat first. - Switching accounts without a page load works: identify the new user and
the previous one’s chat is cleared from the browser before anything else
shows. Calling
identify()again for the same user just updates their details (the latest token wins). - If they chatted anonymously before signing in, that conversation stays in your Inbox as it was; it isn’t merged into theirs.
- With Ask before adding them to lists on, signed-in users don’t join the chatbot’s lists (they never see the checkbox); with it off, they join like anyone who leaves an email.
- Regenerating the secret stops every token signed with the old one at once,
and users chat anonymously until they get new ones. Tokens from Letter come
signed with the new secret: the SDK’s cached ones are replaced within the
hour, or right away when your server restarts. If you sign tokens yourself,
update
LETTER_CHAT_SECRET. Either way, their conversations are untouched.
Customize it
Everything is set in the editor, with a live preview you can click through (nothing is sent from the preview).
| Setting | What it does |
|---|---|
| Brand color | The launcher, the header, and the visitor’s messages. Text on it switches between white and dark automatically so it stays readable. |
| Theme | Light, dark, or auto (follows each visitor’s system setting). |
| Header | A solid header in your brand color, or a minimal white one. |
| Position | Bottom right or bottom left, with the distance from the edges. |
| Launcher | A chat, help, or sparkle icon, and an optional label (“Chat with us”). |
| Avatar | Your logo or a team photo, shown in the header and next to the bot’s messages. |
| Title, subtitle | The header text, e.g. your company and “We typically reply within a few hours”. |
| Welcome message | The greeting. A blank line between paragraphs sends them as separate bubbles. |
| Quick replies | Up to 6 buttons with an instant answer and an optional link. A quick reply with no answer and no link is sent to your team like a typed message (good for “Talk to sales”). |
| Greeting popup | A small bubble above the launcher, shown once to each visitor until they open the chat. |
| Collecting emails | What the bot says when it asks for the email, whether it also asks for a name, and the confirmation it sends. |
On phones the chat opens full screen. It respects reduced-motion settings and works with a keyboard and screen readers.
Contacts, lists, and consent
Everyone who leaves their email becomes a contact with the source Chatbot,
so you can filter and segment them (source is Chatbot). If they typed a name,
it’s saved as the name and first_name traits, unless the contact already has
one.
Pick the lists visitors join under Delivery. With Ask before adding them to lists on (recommended), the email step shows a checkbox, and only visitors who tick it join the lists. Everyone still gets a reply either way.
When a visitor leaves their email, a chat_started event fires on their
contact, with the chatbot and the page the chat started on in its properties.
Use it as an event trigger to start a sequence, and
list_entered fires as usual when a visitor joins a list.
Notifications and replies
Every chat lands in your Inbox with the visitor’s first message, next to the form submissions you send there. Until a visitor leaves their email, the chat is anonymous: it shows up under an animal name like “Zippy Zebra”, with no contact behind it yet. The chatbot’s Conversations tab opens the Inbox filtered to that chatbot.
Replies you write in the Inbox show up in the visitor’s chat, and the launcher shows a badge if the chat is closed. A reply counts as seen once it’s on screen with the chat open and the tab in view. If the visitor has left their email and hasn’t seen a reply 10 minutes later, it’s emailed to them from your project’s sending address, together with any other replies they missed, laid out like the chat with a button to continue it. That’s at most one email per conversation every 10 minutes, and replies they read in the chat are never emailed. If an anonymous visitor leaves their email later, the replies they haven’t seen go out 10 minutes after that. The Inbox marks each reply Seen, Not seen yet (with when the email goes out), or Emailed.
Their answers to that email go to your project’s Reply-To, or without one, to whoever on your team wrote the latest reply. Mark a conversation done once it’s handled; it reopens if the visitor writes again.
New messages are also emailed to your team, at most one email per conversation a minute. Each teammate picks their own under Settings > Notifications: everyone gets Chats emails until they turn them off, for every chatbot in the project, at the address they sign in with. The chatbot’s Delivery tab shows whether you get them. Once the visitor has left their email, the email’s Reply-To is the visitor, so you can also answer by hitting Reply in your own mail app. Each email links to the conversation in the Inbox.
To get new chats in a Slack channel too, and answer them from their threads, connect Slack.
Pictures
Visitors can send pictures, a screenshot of an error, say: with the picture button next to the message box, by pasting one into it, or by dropping it on the chat. You can send them too, from the Inbox: the same button in the reply box, paste, or drop, up to 4 per reply, with or without text.
- PNG, JPG, GIF and WebP, up to 8 MB. Photos are shrunk to 2048 pixels on their longest side before they’re sent, and JPGs are re-saved, which strips their camera data (including GPS location). GIFs keep their animation.
- Pictures show in the chat, the Inbox, your team’s notification emails, the visitor’s reply email, and Slack threads. Click one to open it full size.
- Each picture is stored at a long, random, unlisted address: anyone with the link can open it, so they’re as private as the link.
- The Management API lists each message’s
pictures as
attachments.
Allowed websites
By default the chatbot runs on any site that has the snippet. To lock it to your
own domains, list them under Delivery > Allowed websites, one per line.
Subdomains are included: acme.com also allows www.acme.com and
shop.acme.com.
Privacy and performance
- The widget is a single small script with no dependencies. It renders in an isolated shadow DOM, so your site’s CSS can’t break it and it can’t touch yours.
- It sets no cookies. The visitor’s own conversation is kept in their browser’s
local storage so it carries over between pages. A signed-in user’s comes
from Letter instead, after each
identify(), and only ever to them. - Messages are rate limited per visitor, and long messages are trimmed. Pictures have their own, lower limit.
- If your site sends a Content Security Policy, allow the Letter host in
script-srcandconnect-src, andhttps://assets.letter.app(where pictures and team photos are stored) andblob:inimg-src.
Managing chatbots from the Management API
Everything above maps onto REST endpoints under your project (see the Management API for auth and conventions), and each one is also an MCP tool:
| Method | Path | What it does |
|---|---|---|
GET | /v1/projects/{slug}/chatbots | List chatbots (with conversation counts). |
POST | /v1/projects/{slug}/chatbots | Create a draft chatbot. |
GET | /v1/projects/{slug}/chatbots/{id} | Get one chatbot’s full config and its embed_code. |
PATCH | /v1/projects/{slug}/chatbots/{id} | Update it; set status: "published" to publish. |
DELETE | /v1/projects/{slug}/chatbots/{id} | Delete a chatbot and its conversations. |
POST | /v1/projects/{slug}/chatbots/{id}/duplicate | Copy it into a new draft, with its own embed_code. |
GET | /v1/projects/{slug}/chatbots/{id}/conversations | List its conversations. |
GET | /v1/projects/{slug}/chatbots/{id}/conversations/{conversationId} | Read one, with its messages. |
Patch bodies take name, status, config, target_list_ids, and
hide_badge (paid plans only). config uses the
editor’s camelCase keys (accentColor, welcomeMessage, quickReplies,
…): the keys you send replace the stored ones, and the rest stay as they
are. To reply to a conversation or mark it done, use the
Inbox endpoints.