Embed SDK is available only to paid plans.

Overview

Our Embed SDK lets you interact with TeamAI chatbots embedded on your web pages. It provides methods to update context and retrieve current context, giving you full control over your embedded chatbots.

If you embedded your chatbot before September 29, 2024, you may need to update the embed code on your website. The new embed code now includes the Embed SDK automatically.

To use the Embed SDK, ensure that you have the correct assistant ID and the appropriate plan.

Methods

Initialize Embed SDK

The SDK automatically initializes when the chatbot is embedded on your page. You don’t need to call an explicit init function.

Get Chatbot Instance

Retrieves an instance of the chatbot for interaction.

const chatbotInstance = tai.getInstance("YOUR_ASSISTANT_ID");
assistantId
string
required

The unique identifier for your chatbot instance.

This method returns a chatbot instance that you can use to interact with your embedded chatbot.

Wait for Chatbot Ready State

window.addEventListener("teamAIChatbotReady", function () {
  const chatbotInstance = tai.getInstance("YOUR_ASSISTANT_ID");
  // Your code here
});

Update Chatbot Context

Updates the context for your chatbot.

chatbotInstance.updateContext({ userEmail: "user@example.com" });
newContext
object
required

The new context data to update the chatbot with.

This method allows you to update the context for the chatbot dynamically. You can use these context variables in your assistant’s instructions like so: {{userEmail}}.

Get Chatbot Context

Retrieves the current context of the chatbot.

const currentContext = chatbotInstance.getContext();

This method returns the current context of the chatbot.

Example: Updating Context

In this example, we’re setting up the chatbot and updating the context with the user’s email and name.

Example: Updating Context

window.addEventListener("teamAIChatbotReady", function () {
  console.log('The TeamAI Chatbot is ready!');

  const chatbotInstance = tai.getInstance("YOUR_ASSISTANT_ID");

  // Update context with user's email and name
  chatbotInstance.updateContext({
    "userEmail": "user@example.com",
    "userName": "John Doe"
  });
});

This example demonstrates how to set up the chatbot, log its readiness, and update its context programmatically.

Debug Mode

To enable debug mode in TeamAI, add ?teamAIDebug=true to your app’s URL.

For example, if you’ve embedded your TeamAI instance in your app hosted at https://example.com, you can activate debug mode by changing the URL to:

https://example.com?teamAIDebug=true

After adding this parameter, refresh the page and open your browser’s developer console (usually by pressing F12 or right-clicking and selecting “Inspect” then navigating to the “Console” tab).

Was this page helpful?