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.
<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();
},
});

Actions that change data should be marked as requiring confirmation in the dashboard. The visitor then confirms with a button in the chat before the handler runs.

Actions are available on Pro and Business.

Feedbot("on", "message", (message) => {
console.log(message.role, message.content);
});