On this page

#SDK reference

Vatio.chat starts or resumes a conversation and waits for a subscription before resolving. Call it when the visitor sends their first message: with no conversation stored in the tab, or with fresh: true, it starts a new one, so a call on page load makes every visit a conversation. On load, Vatio.resumable says whether there is one to show. The SDK handles reconnects, history resync, and polling fallback. Messages include id, role, and content. Deduplicate history and event delivery by id.

MethodPurpose
Vatio.config({ workspace, token })Fetch public agent and widget configuration
Vatio.chat(options)Start, resume, or reopen a conversation
Vatio.conversations({ workspace, token, ... })List this browser visitor's conversations, newest first
Vatio.resumable({ workspace, ... })Check for a locally stored, unexpired conversation
Vatio.reset({ workspace, ... })Forget the locally stored conversation; does not delete server history
chat.send(text, { files })Send a message, optionally with files
chat.history({ limit })Fetch messages
chat.on(event, handler)Subscribe to message, typing, status, error, feedback, or update
chat.feedback()Fetch the feedback moment on offer, or null
chat.rate(rating, { comment })Answer it: good, neutral, or bad
chat.dismissFeedback()Decline it
chat.close()Disconnect the client

#Buttons

A reply can carry a link as a button: message.buttons lists them, each with type, title and url, and content still has the link as the agent wrote it, for a client that draws no buttons. To draw them, show textWithoutButtons(message), the content without those links, and a button per entry under it:

import { textWithoutButtons } from "@vatio-ai/sdk";
chat.on("message", (message) => {
showText(textWithoutButtons(message));
for (const button of message.buttons ?? []) {
if (button.type === "url") showButton(button.title, button.url);
}
});

type is "url" today; skip a type you do not know.

#Files and voice notes

Pass files — File or Blob objects, up to four — to attach images (JPEG, PNG, WebP, GIF, HEIC), PDFs, text files (plain, CSV, Markdown) or audio (M4A, MP3, OGG, WAV, AAC, FLAC). With files, text may be empty:

const input = document.querySelector("input[type=file]");
const { message } = await chat.send("Is this the right part?", { files: [...input.files] });

send resolves to the stored message. A voice note is transcribed in the background: the stored message comes back as "Audio", and a few seconds later an update event — { id, content, content_is_media_label } — carries the transcript for the message with that id; merge it in. The agent answers only once the transcript is in. A PDF holds the reply the same way while it is read, a minute or two for a long one, and what it says stays out of content (how much of it the agent gets: PDFs). Messages carry attachments — { id, filename, content_type, byte_size, kind, url }, where kind is image, audio, video or file, and url is absolute and loads without the chat credential. When the visitor sent only a file, content is a stand-in such as "Image" and content_is_media_label is true: draw the file instead.

An agent's message carries buttons, the links it sends as buttons, each { type, title, url } with type url. Each one is also in content, as a Markdown link: draw the button and take that link out of the text, or ignore buttons and render content as is. See Buttons.

To record in a browser, ask MediaRecorder for audio/mp4 (or audio/ogg) explicitly. Chrome defaults to WebM, which is not accepted.

#Visitor feedback

Vatio offers a feedback moment at most once per conversation, and once every 30 days per contact, when it ends: the visitor closes the topic, or goes quiet once the agent has given them what they asked for — see the widget guide. The feedback event delivers it, including one offered before the page connected:

chat.on("feedback", (feedback) => {
// { agentName, messageId, question, rating, submittedAt, dismissed }, or null
if (feedback && !feedback.rating && !feedback.dismissed) {
showRating(feedback.question ?? `How did ${feedback.agentName} do?`);
}
else hideRating();
});
await chat.rate("neutral", { comment: "Took a while" });

question is how the agent asks, written for that conversation; it is null when there is none, so keep your own wording as the fallback.

The event fires again with null when the visitor writes without answering, because the moment has passed. comment takes up to 2,000 characters and is meant for neutral and bad. rate rejects with feedback_unavailable once the moment is gone. Your backend hears each rating as a feedback.submitted webhook.

#Options

Vatio.chat accepts workspace and token, plus optional baseUrl, fresh, scope, visitorToken, replyStyle, conversation and attribution. fresh: true starts a new chat. conversation reopens an entry returned by Vatio.conversations.

A new conversation carries where the visit came from: the landing page, the referring site, the utm_* and the ad click ids, which the SDK reads from the page when it loads and keeps for the tab (SDK 3.7.0 and later; see Where conversations come from). Pass attribution to send your own instead, an object with any of landing_page, referrer, utm_source, utm_medium, utm_campaign, utm_content, utm_term, gclid and fbclid, or attribution: false to send none. Load the SDK on the page the visitor lands on, not only where the chat is, or the campaign on that page's URL is gone by the time they write.

Use a distinct scope when two chat UIs of the same workspace on one origin must not share a conversation, such as a support chat and a separate onboarding assistant. Pass the same scope and visitorToken to chat, conversations, resumable, and reset. Storage is separated by the visitor token's sub, not the whole token, so a new token for the same person keeps the conversation, and a token for a different person starts a new one. It does not merge contacts across devices.

#Storage

The SDK stores the current conversation per tab and a visitor reference in local storage. Chat credentials last 12 hours. Treat visitor references and chat credentials as private: the reference can retrieve that visitor's anonymous conversations and fresh chat credentials, so store the reference where the signed-in user cannot read another's, and never derive it from a public or predictable user ID. Issue a new reference when the signed-in user changes.

A conversation the visitor had signed in is listed only when the request also carries their signed token. Vatio.conversations sends the visitorToken you pass it in the Vatio-Visitor-Token header (SDK 3.5.1 and later; iOS 0.4.1, Android 0.2.1, Flutter 0.1.0). Without it, the list holds only what the visitor said anonymously, so a reference copied out of a browser does not open a signed-in customer's history.

The token alone is enough: it lists every conversation that person had signed in on this workspace, whatever device or reference it started on, so a signed-in visitor's history survives a cleared browser, a reinstall or a new phone (SDK 3.5.6; iOS 0.4.3, Android 0.2.4, Flutter 0.1.1). Earlier versions return an empty list when no reference is stored for the signed-in visitor.

Last updated:

Latest release: 0.144.0 · Changelog · The whole contract as Markdown: /docs/docs.md