What it does:
Removes the widget completely and cleans up everything it was using.
Useful when you want to stop or remove the widget from the page.
Example:
widget.destroy();
What it does:
Lets you “listen” for things happening inside the widget (called events).
For example: when a message arrives, when the chat is ready, etc.
Example:
widget.on("event-name", () => {});
What it does:
Stops listening to a specific event you previously subscribed to.
Example:
widget.off("event-name", listener);
What it does:
Sends a custom event to the widget.
Good for triggering actions inside the widget.
Example:
widget.emit("event-name", data);
(Basic version only)
What it does:
Starts a new chat conversation automatically.
Example:
widget.startConversation({ initialMessage: "Hello!" });
(Works only if the widget is used as an actual widget, not standalone)
What it does:
Makes the widget visible.
Example:
widget.show(); // will use path = "/" (home page)widget.show('/conversations');
(Works only for widget type)
What it does:
Hides the widget from view.
Example:
widget.hide();
Events are “signals” the widget sends when something important happens.
You can use widget.on(...) to react to these events or for emit data using widget.emit(...).
(on() action only)
The widget is fully ready to use.
widget.on("instance:ready", () => console.log("Widget is ready!"));
(on() action only)
The widget has been removed.
widget.on("instance:destroy", () => console.log("Widget was removed!"));
(on() action only)
The chat inside the widget is ready.
widget.on("chat:ready", () => console.log("Chat is ready!"));
(on() action only)
The chat has been closed or removed.
widget.on("chat:destroy", () => console.log("Chat was destroyed!"));
add new chat message when was received .
Needs:
widget.emit("chat:message-received", { content: message.content, role: message.role, conversationId: conv.id,});
widget.on("chat:message-received", () => {console.log('New meessage received.')});
The conversation has ended.
widget.emit("chat:conversation-finished", { conversationId: conv.id });
widget.on("chat:conversation-finished", () => {console.log('Conversation finished')});
(on() action only)
A completely new conversation has started.
(on() action only)
The widget was opened.
(on() action only)
The widget was closed.
(This is something you send TO the widget using emit())
Tells the widget to switch to a specific screen or page.
widget.emit("router:navigate", ({ path, query }))
(This is something you send TO the widget using emit())
The widget switched to a new screen or page.
widget.emit("router:route-changed", ({ path, query }))
(on() action only)
The internal navigation system (router) is ready.
(on() action only)
The router has been removed.
The widget received external parameters (for example: extra data passed from outside).
widget.emit("external-params:received", ({params: {code: code}}))
widget.on("external-params:received", ({params}) => {console.log('Params received')});