overview
To initialize the ChatBot widget, create an instance using the following code snippet:
const chat = new ChatBot(html_container, config);
This parameter specifies the container where the ChatBot widget will be rendered. It accepts the following types:
- HTMLElement: Directly pass an HTML element which will act as the container for the widget.
- CSS Locator String: Use a CSS selector string to specify the container. Only the first match will be used as the widget container.
#some
- Selects an element by its ID..some
- Selects an element by its class name.
This optional parameter is a configuration object that allows customizing the widget's behavior.
interface ChatBotConfig {
activeAgent?: TID; // Define which agent will respond to the user's messages
activeChat?: TID; // Define which chat is active (selected)
agents?: Agent[]; // Provide list of agents for the chat
chats?: Chat[]; // Provide list of chats previously created by current user
focus?: boolean; // Control auto-focus ability of chat, set as true by default
format?: "text" | "markdown"; // Use plain text or markdown format for messages
messages?: Message[]; // Define initial messages in the chat
readonly?: boolean; // Allow or deny data changes, set as false by default
render?: "blocks" | "cards" | "bubbles" | "flow"; // Render messages in chat with specified template
sidebar?: boolean; // Define will sidebar will be visible or hidden, set as true by default
user?: User; // Define information about current user
withCache?: boolean; // Define will chat store user's messages locally or depend on server side
}
ChatBot API overview
Methods
addChat | initializes a new chat within the ChatBot widget |
addMessage | adds a new message to the chat UI |
appendMessage | appends additional text to an existing message in the chat interface |
deleteChat | removes a chat session identified by its unique ID |
getConfig | dynamically updates the ChatBot widget configuration |
intercept | allows interception of specific widget events |
on | registers event listeners for chat-related events |
provideMessages | provides updated messages to the chat widget |
requestMessages | requests the messages for a specific chat identified by its unique ID |
selectChat | selects a specific chat session by its unique identifier and optionally specifies the agent |
setConfig | returns current configuration of the ChatBot widget |
typeMessage | changes the typing state for a given message |
Properties
activeAgent | agent response control |
activeChat | active chat control |
agents | configuration and management of chat agents |
chats | list of chats previously created by the current user |
focus | auto-focus functionality |
format | message display format control |
messages | |
readonly | chatbot widget's data modification control |
render | visual template configuration |
sidebar | visibility control |
user | information about the current user |
withCache | message storage configuration |
Actions
add_chat | new chat creation |
add_message | new message detection and interception |
append_message | event to detect text addition to existing message |
delete_chat | chat deletion event detection |
provide_messages | message provisioning |
request_messages | message retrieval action |
select_chat | new chat selection detection |
type_message | message typing state change |