Skip to main content

setConfig

setConfig(config: ChatBotConfig): void;

The setConfig method dynamically updates the ChatBot widget configuration. This method changes various properties of the widget such as the active chat, the agent responding to the user, message rendering format, and other UI elements.

Properties

  • activeAgent: Optional. ID of the agent who will respond to the user's messages.
  • activeChat: Optional. ID of the active (selected) chat.
  • agents: Optional. List of agents for the chat.
  • chats: Optional. List of chats previously created by the current user.
  • focus: Optional. Controls the auto-focus ability of the chat. Default is true.
  • format: Optional. Format for messages in the chat. Can be "text" or "markdown".
  • messages: Optional. Initial messages in the chat.
  • readonly: Optional. Allows or denies data changes. Default is false.
  • render: Optional. Specifies the template for rendering messages. Can be "blocks", "cards", "bubbles", or "flow".
  • sidebar: Optional. Controls the visibility of the sidebar. Default is true.
  • user: Optional. Information about the current user.
  • withCache: Optional. Determines if the chat stores user messages locally. Otherwise, it depends on the server-side.

Use-Cases

Activate a Specific Chat

{widget}.setConfig({ activeChat: 12 });

This configuration sets the active chat to the one with ID 12.

Set Chat Format to Markdown

{widget}.setConfig({ format: "markdown" });

This configures the widget to use Markdown format for messages.

Focus Chat Automatically

{widget}.setConfig({ focus: true });

This ensures the chat input box automatically gets focus when the widget is rendered.

Initialize with a List of Agents

{widget}.setConfig({ agents: [{ id: 1, name: 'Agent 1' }, { id: 2, name: 'Agent 2' }] });

This populates the chat with a list of agents available to respond to the user.

Set User Information

{widget}.setConfig({ user: { id: 123, name: 'John Doe' } });

This sets the current user information in the chat widget.

Enable Read-Only Chat

{widget}.setConfig({ readonly: true });

This makes the chat read-only, disallowing any data changes.

Render Messages as Cards

{widget}.setConfig({ render: "cards" });

This configures the chat to render messages using the "cards" template.

Disable Sidebar

{widget}.setConfig({ sidebar: false });

This hides the sidebar in the chat widget.

Use Local Cache for Messages

{widget}.setConfig({ withCache: true });

This enables storing user messages locally instead of relying on the server side.