Skip to main content
The Voltai.load() function returns an instance with methods to control the widget from your code.
const voltai = Voltai.load({
  apiKey: 'your-api-key'
});

// Now you can use voltai.open(), voltai.close(), voltai.login(), etc.

Widget visibility

open()

Opens the chat panel.
voltai.open();

close()

Closes the chat panel.
voltai.close();

toggle()

Toggles the chat panel open or closed.
voltai.toggle();
Use these methods to integrate the widget with your own UI. For example, open the chat when a user clicks a “Need help?” button.

Sending messages

sendChat(query, options)

Sends a chat message programmatically. This lets you start conversations from your own code, like a search box or help button.
await voltai.sendChat('How do I reset my password?', {
  topics: ['Support']
});
Parameters:
NameTypeDescription
querystringThe message to send
optionsobjectRequired settings (see below)
Options:
PropertyTypeRequiredDescription
topicsstring[]YesTopics to associate with the message
newChatbooleanNoStart a new conversation (default: false)
Returns: Promise<void>

Example: Basic usage

await voltai.sendChat('Show me getting started guides', {
  topics: ['Documentation', 'Tutorials']
});

Example: Start a new chat

await voltai.sendChat('I have a billing question', {
  topics: ['Billing'],
  newChat: true
});

Example: Combined with open

// Open the widget and send a message
voltai.open();
await voltai.sendChat('What are your pricing plans?', {
  topics: ['Sales'],
  newChat: true
});
The widget must be initialized and authenticated before calling sendChat(). If authentication hasn’t completed, the method will throw an error.

Authentication

login()

Opens the login popup for users to sign in.
await voltai.login();

logout()

Logs out the current user and clears their session.
await voltai.logout();

Cleanup

destroy()

Removes the widget from the page and cleans up all resources.
voltai.destroy();
Use this when:
  • Navigating away in a single-page app
  • Conditionally removing the widget
  • Reinitializing with different settings

Complete example

Here’s a page with custom buttons to control the widget:
<button id="open-btn">Open Chat</button>
<button id="close-btn">Close Chat</button>
<button id="ask-btn">Ask a Question</button>
<button id="login-btn">Sign In</button>
<button id="logout-btn">Sign Out</button>

<script src="https://cdn.voltai.ai/widget@latest/voltai-widget.js"></script>
<script>
  const voltai = Voltai.load({
    apiKey: 'your-api-key',
    enableGuestUser: true
  });

  document.getElementById('open-btn').onclick = () => {
    voltai.open();
  };

  document.getElementById('close-btn').onclick = () => {
    voltai.close();
  };

  document.getElementById('ask-btn').onclick = async () => {
    voltai.open();
    await voltai.sendChat('How do I get started?', {
      topics: ['Getting Started']
    });
  };

  document.getElementById('login-btn').onclick = async () => {
    await voltai.login();
  };

  document.getElementById('logout-btn').onclick = async () => {
    await voltai.logout();
  };
</script>