JavaScript Embed Features
Client-Side Custom Actions
Server-side actions go through the API. Client-side actions run in the browser — useful for navigating the user, opening a modal, prefilling a form, applying a coupon.
What it does
Reach for client-side actions when the work happens entirely in the browser:
- Navigate the user to a specific section of the site
- Open a modal (signup, video tour)
- Apply a coupon or discount in your cart UI
- Trigger a third-party SDK (analytics, support takeover)
Registering tools
Define an action in the dashboard (Actions → Create action → Custom action, type: Client) and register a handler before the embed loads. Action name in dashboard must exactly match the handler key.
js
window.chatmount("registerTools", {
get_weather: async (args, user) => {
const { location } = args;
const res = await fetch(`/api/weather?location=${location}`);
const data = await res.json();
return {
status: "success",
data: { temperature: data.temp, condition: data.cond },
};
},
});Function signature
Each handler receives two arguments:
args— object with the parameters the agent collected from the user, matching the schema you defined in the dashboarduser— anonymous identifiers when no identity is verified, oruser_id+ metadata once identity verification ships
Response shape
Return one of two shapes; the agent uses the result to compose its next message:
js
// Success
return { status: "success", data: { /* anything serializable */ } };
// Error
return { status: "error", error: "Could not look up weather right now" };Related