Skip to content

JavaScript API

The loader defines a global Feedbot function. Add this stub before your first call so calls made before the loader finishes are queued:

window.Feedbot = window.Feedbot || function () { (Feedbot.q = Feedbot.q || []).push(arguments) };
Command Example Description
open Feedbot("open") Open the chat.
close Feedbot("close") Close the chat.
toggle Feedbot("toggle") Toggle the chat.
identify Feedbot("identify", { userId, email, name, hash, metadata }) See Identify users.
reset Feedbot("reset") Forget the visitor (call on logout).
setMetadata Feedbot("setMetadata", { plan: "pro" }) Attach extra context to the conversation.
sendMessage Feedbot("sendMessage", "I need help with billing") Open the chat and send a message as the visitor.
registerAction see below Let the bot call a function on your page.
on Feedbot("on", "message", cb) Subscribe to ready, open, close, message. Returns an unsubscribe function.
off Feedbot("off", "message", cb) Remove a listener.

Once the loader has run, you can also call commands as methods: Feedbot.open(), Feedbot.identify({ ... }). sendMessage returns a promise. close does nothing in inline mode.

<button onclick="Feedbot('open')">Chat with us</button>

A client action runs in the visitor’s browser, inside their signed-in session. The bot decides when to call it, the widget runs your handler and sends the result back to the bot. No API keys leave your site.

Feedbot("registerAction", {
name: "get_order_status",
description: "Returns the status of the current user's latest order",
parameters: {
type: "object",
properties: { orderId: { type: "string", description: "Order id, if the user gave one" } },
},
handler: async ({ orderId }) => {
const res = await fetch(`/api/orders/${orderId ?? "latest"}`);
return await res.json();
},
});

The definition has a name (letters, digits, _ and -, starting with a letter, up to 64 characters), a description that tells the bot when to use it, optional parameters as JSON Schema, and a handler. The handler may return a value or a promise and has 30 seconds to finish. You can register up to 10 client actions. Names must not clash with your HTTP actions or the built-in tools (show_buttons, save_contact, request_human, create_task).

Actions (client and HTTP) are available on Pro and Business.

const off = Feedbot("on", "message", (message) => {
console.log(message.role, message.content);
});
Event Payload
ready { botId, visitorId, config }. Fires right away if the widget is already ready.
open none
close none
message { id, role, author, content, buttons, createdAt }. role is user, assistant or operator (a human replying from Telegram).