Support widget
The support widget is a chat panel inside your product. A signed-in customer writes to your team, and your team answers from the Support view in Intray. The widget has no framework dependency and no runtime dependencies.
npm install @intray/supportThe package has two entries. The browser entry never imports the server entry, so the key stays out of your browser bundle.
| Entry | Runs in | Exports |
|---|---|---|
@intray/support | Browser | createSupportWidget, types, SupportError |
@intray/support/server | Your backend | createSupportClient, types, SupportError |
How the parts connect
widget (browser) -> your transport -> your server route -> createSupportClient -> Intray POST /v1/support/chatThe browser never sends identity and never holds the key. Your server route reads the signed-in user from its own session, builds the identity, and calls Intray. A customer can read and write only the conversations that belong to the identity your server verified.
Intray has no browser CORS endpoint and no anonymous mode. The widget works only behind your login.
Turn chat on
Open the connected application
In Intray open Settings, then Applications. Use the application whose origin matches your product. Create one if none exists.
Turn on Chat
Switch on Chat for that application. Chat and live watching have separate switches on the same application.
Store the key on your server
The widget uses the application's key, which starts with ilw_. It is the
same key live watching uses. Intray shows it once. Rotating the key stops
the old one at once.
Your server needs three values.
INTRAY_SUPPORT_URLstringRequiredThe full endpoint URL. It ends in /v1/support/chat. It must use HTTPS,
except on localhost.
INTRAY_LIVE_KEYstringRequiredThe application key. Server secrets only.
SITE_URLstringRequiredYour product's origin, for example https://app.example.com. It must match
the origin on the connected application.
Server client
Create the client once. Call forIdentity on every request, with values from your own session.
import { createSupportClient } from "@intray/support/server";
export const support = createSupportClient({
url: process.env.INTRAY_SUPPORT_URL!,
key: process.env.INTRAY_LIVE_KEY!,
});forIdentity(identity) returns an object with the same five methods the widget calls. It copies the four fields below and drops anything else.
userIdstringRequiredYour ID for the signed-in user. 1 to 128 characters.
accountIdstringRequiredYour ID for the account or workspace the user is acting in. 1 to 128 characters.
displayNamestringRequiredThe name your team sees. 1 to 200 characters after trimming.
originstringRequiredAn exact origin such as https://app.example.com. No path and no trailing
slash.
Identity comes from your session
Never let the browser choose userId, accountId, origin, or the key.
Check that the user belongs to the account on every request. Intray trusts the
identity your server sends.
Connect the widget to your server
One server route is enough. The browser sends an operation name and its arguments. The route picks the matching method and adds the identity.
import { SupportError } from "@intray/support/server";
import { support } from "./intray-support";
export async function POST(request: Request) {
// Your own auth. Both values come from the session, not the request body.
const { user, account } = await requireSession(request);
const customer = support.forIdentity({
userId: user.id,
accountId: account.id,
displayName: user.name,
origin: process.env.SITE_URL!,
});
const { operation, ...args } = await request.json();
try {
switch (operation) {
case "list":
return Response.json({ data: await customer.listConversations(args) });
case "create":
return Response.json({ data: await customer.createConversation(args) });
case "messages":
return Response.json({ data: await customer.listMessages(args) });
case "send":
return Response.json({ data: await customer.sendMessage(args) });
case "read":
return Response.json({ data: await customer.markRead(args) });
default:
return Response.json({ error: "Unknown operation" }, { status: 400 });
}
} catch (error) {
if (error instanceof SupportError && error.code === "invalid_input")
return Response.json({ error: error.message }, { status: 400 });
const status =
error instanceof SupportError && error.status ? error.status : 502;
return Response.json({ error: "Support request failed" }, { status });
}
}The server client validates every argument before it sends anything, so a bad argument from the browser fails with invalid_input. It also rejects redirects, stops reading a response after 2 MiB, and gives up after 8 seconds.
The five transport callbacks
The widget calls these. Each returns a promise. A promise that does not settle within 15 seconds fails with a SupportError of code timeout, and the widget drops a result that arrives later.
listConversations
cursorstringOptionalOptional. Pass nextCursor from the previous page to load older
conversations. The whole argument may be omitted.
Returns { conversations, nextCursor, hasUnread, brand? }. conversations holds up to 20 items, newest first. nextCursor is a string or null. hasUnread covers every conversation of the customer, not only this page. brand is { name, logoUrl? }, the application's name and logo from Settings > Applications.
Each conversation is { id, subject, status, updatedAt, preview, unread, responder? }. status is "open" or "closed". responder is { name, avatarUrl? } for the operator who replied last, and is absent before the first reply.
createConversation
bodystringRequiredThe first message. 1 to 4,000 characters after trimming.
requestIdstringRequired1 to 128 letters, digits, underscores, or hyphens. The widget uses a UUID.
subjectstringOptionalOptional, up to 120 characters. The widget never asks the customer for one. Intray names the conversation from the first line of the first message.
Returns the new conversation. The conversation and its first message are stored together.
listMessages
conversationIdstringRequiredThe conversation to read.
cursorstringOptionalOptional. Pass nextCursor to load the page before the current one.
Returns { messages, nextCursor }. messages holds up to 50 items, oldest first. Each message is { id, author, body, createdAt, authorName?, authorAvatarUrl? }. author is "customer" or "operator". Fetching messages never marks them read.
sendMessage
conversationIdstringRequiredThe conversation to write to. A message to a closed conversation reopens it.
bodystringRequired1 to 4,000 characters after trimming. Plain text.
requestIdstringRequiredSame rules as in createConversation.
Returns the stored message.
markRead
conversationIdstringRequiredThe conversation on screen.
messageIdstringRequiredThe newest operator message the customer has on screen.
Returns { hasUnread }, the state across every conversation of the customer after the call. Intray clears unread only when messageId is still the newest operator message, so a reply that arrives during the call stays unread.
The widget calls markRead only after it rendered messages in an open thread on a visible tab. A closed panel or a hidden tab never counts as read.
Widget options
transportSupportTransportRequiredThe five callbacks above.
titlestringOptionalThe panel title.
placement"floating" | "side"Optional"floating" is the default, a round launcher at the bottom right with the
panel above it. "side" docks a full-height panel to the right edge. Below
360px of width the panel fills the screen.
launcherContainerHTMLElementOptionalPuts the launcher inside your own toolbar. destroy() leaves your element
in place.
greetingstringOptionalFirst line of the Home tab. Defaults to "Hi there".
introstringOptionalSecond line of the Home tab. Defaults to "How can we help?".
teamSupportTeamMember[]OptionalUp to four { name, avatarUrl? } to show on Home. Photos load over HTTPS
only. Without it, Home shows the operators who replied recently.
replyTimestringOptionalYour own wording for the expected reply time. Hidden when empty.
notificationsbooleanOptionalDefaults to true. The closed launcher shows a dot for unread replies. With
false, the closed widget makes no requests.
onOpenChange(open: boolean) => voidOptionalRuns after the panel opens or closes. With placement: "side", use it to
give the panel 360px of your layout.
onError(error: unknown) => voidOptionalReceives every transport error. The widget shows its own fixed wording to the customer.
Methods and lifecycle
createSupportWidget mounts one host element and returns four members.
open(target?)(target?: "messages") => voidOptionalWithout a target, the first open continues the open conversation when the
widget knows of one, and shows Home otherwise. open("messages") shows the
conversation list.
close()() => voidOptionalCloses the panel. Polling of the open thread stops.
destroy()() => voidOptionalRemoves the widget and stops every request.
controlsContainerHTMLElementOptionalA mount point for the live watching consent prompt. Pass it as
controlsContainer to createLiveWatch so the prompt appears above the
launcher.
Call destroy() on sign out and on every account switch, then create a new widget. Never reuse one widget across identities. Its state lives in memory only.
How the widget talks to your server:
- While the panel is open and the tab is visible, it polls the newest page every 5 seconds.
- While the panel is closed and the tab is visible, it checks
hasUnreadevery 15 seconds. - A hidden tab makes no requests. Failed requests back off to 60 seconds.
- Enter sends. Shift+Enter adds a line.
- A failed send keeps the draft. The retry reuses the same
requestId, so Intray stores the message once. - The widget keeps at most 500 messages and 20 history pages of one conversation in memory.
Limits
| Limit | Value |
|---|---|
| Message body | 1 to 4,000 characters, plain text, trimmed |
| Subject | Up to 120 characters |
requestId | 1 to 128 letters, digits, underscores, or hyphens |
userId, accountId, IDs | Up to 128 characters |
| Request body to Intray | 64 KB |
| Reads per customer | 240 per minute |
| Writes per customer | 30 per minute |
| New conversations | 20 per customer per day |
| Server client timeout | 8 seconds |
| Widget callback timeout | 15 seconds |
A create or send with a requestId Intray already saw for that identity returns the first result and stores nothing new. It does not count as another write. Reusing a requestId with a different payload is rejected.
Intray answers { "data": ... } on success and { "error": "..." } with an HTTP status on failure. The server client turns a failure into a SupportError with a code. error.retryable is true for network, timeout, and HTTP 408, 429, and 5xx.
Privacy
The widget is excluded from session recordings. Its host element carries data-private, data-live-block, rr-block, and ph-no-capture, and its content sits in a closed shadow root. Live watching, rrweb, and PostHog all skip it.
Operator photos and your application logo load from Intray over HTTPS, without a referrer. A photo that fails to load falls back to initials.
Where your team answers
Chat conversations appear in the Support view in Intray. An operator can also open Chat beside a customer's session in the Live view. Chat is separate from email today. A chat conversation does not appear in the inbox and sends no email.
Workspace owners can read and answer by default. Other members need access on the connected application. When Chat is switched off, your team can still read past conversations, and Intray refuses new customer messages and operator replies.
Intray keeps chat conversations until the workspace is deleted. There is no retention setting yet.