Skip to content
← Developer Hub

Developer Hub

Live Chat SDK

Embed the chat widget, control it with window.raiaChat commands, and prototype with SDK Studio (sdk.raia.run).

Featured tool

SDK Studio — sdk.raia.run

Use this hosted tool to configure and test the Live Chat widget. Generate your embed snippet, preview commands live, and copy the code into your app.

Launch SDK Studio

Get your embed code from SDK Studio

  1. Open sdk.raia.run.
  2. In Agent, paste your Live Chat key into API Key. Leave Script URL as it is unless you were told to change it.
SDK Studio → Agent, with a placeholder key (not connected).
  1. Highlight 1: API Key: paste your Live Chat key here. This screenshot shows the placeholder YOUR_LIVE_CHAT_KEY.
  2. Highlight 2: Script URL: the widget script the snippet loads.
  3. Highlight 3: Inline embed (data-inline), Dev console (data-console-enabled) and Disable auto-open add options to the snippet. Disable auto-open isn't verified to work in the widget; use Auto-open mode no instead.
  1. Adjust Launcher, Behavior and Suggestions if you want to.
  2. In Generated code, choose HTML, Vanilla JS, React or Next.js, then click Copy.
SDK Studio → Generated code for the settings above.
  1. Highlight 1: Pick the code style for your site: HTML, Vanilla JS, React or Next.js.
  2. Highlight 2: data-api-key holds your key. Replace the placeholder with your own key.
  3. Highlight 3: Click Copy, then paste the code into your page.

Expected result: with a valid key, the live preview shows your widget. These screenshots use the placeholder YOUR_LIVE_CHAT_KEY, so the preview is blank. If your preview stays blank, check the key you pasted.

Live Chat SDK command surface diagram

Command overview: use the SDK Studio command picker below to choose a supported command and inspect its settings.

01

Overview

The raia Live Chat SDK embeds the agent widget into your web app and lets you control it programmatically from JavaScript.

Embedding in a Zoho Desk Help Center?

Zoho Desk blocks the standard embed tag through its Content Security Policy, so the widget must be injected from the portal's JS Function block instead. Read the Zoho Desk Help Center guide →
02

Installation

Paste this script just before the closing </body> tag of your page. Copy the current snippet for your agent from its Live Chat settings rather than retyping it, and keep the script URL and version it gives you consistent across your pages. The example below uses the current widget script URL with a placeholder.

html
<script
  src="https://raiabot.raia2.com/assets/raia-chatbot-widget.js"
  data-api-key="{your-public-agent-id}"
  defer>
</script>

Security note

Anything you put in the page, including the values in this snippet, is visible to visitors. Keep admin and server secrets out of the browser. If you use a Live Chat Security Key, follow the Live Chat Security Key section below.
03

The window.raiaChat object

Once the script loads, the SDK exposes a global window.raiaChat object. You interact with the widget exclusively by sending commands through it.

javascript
window.raiaChat.sendCommand(COMMAND_TYPE, payload);

SDK Studio's SDK commands list shows each command's friendly name next to the type you pass to sendCommand.

SDK Studio → SDK commands list. Nothing was added or run.
  1. Highlight 1: Each entry shows the friendly name and the command type to pass to sendCommand, for example openChat → OPEN_CHAT.
  2. Highlight 2: Add queues the command and runs it on the live preview when it is connected.
  3. Highlight 3: Read the note: commands run on the live preview and appear in the generated code.

Add runs the command

When the preview is connected, Add runs the selected command on the live preview, not only adds it to the code. SEND_MESSAGE sends a real message to your agent and DELETE_CHAT deletes the chat. Don't use them to test unless that is what you want.
04

Widget control commands

CommandPayloadDescription
OPEN_CHAT{ page?: string }Opens the chat window. Optionally navigates to a specific internal page.
CLOSE_CHATNoneCloses the chat window, minimizing it to the launcher button.
DESTROYNoneCompletely removes the widget from the DOM and cleans up event listeners.
05

User & context commands

CommandPayloadDescription
SET_USER{ user: UserInfo }Passes user identity (name, email, customData) to the agent.
CLEAR_USERNoneRemoves the current user identity.
SET_CONTEXT{ context: string }Sets global context that persists across the session.
CLEAR_CONTEXTNoneClears the global context.
06

Conversation management commands

CommandPayloadDescription
SEND_MESSAGE{ message: string }Sends a message to the agent on behalf of the user.
RESET_CONVERSATIONNoneClears the current chat history and starts a fresh conversation.
DELETE_CHATNoneAsks the widget to delete the current chat. This does not by itself prove that every stored copy or log is permanently removed; retention depends on your account's policies.
SET_WELCOME_MESSAGE{ message: string }Overrides the default welcome message dynamically.
07

Example: identifying a signed-in user

A common use of the SDK is identifying a user after your own app has signed them in. Passing their details via SET_USER lets the agent address them by name and use their account context.

SET_USER is not sign-in

SET_USER sends details from the browser. It does not authenticate anyone or prove who they are — any visitor could send different values. Sign users in with your own app first, and don't let the agent treat these details as verified identity.
javascript
// After successful login
const userData = {
  firstName: "Jane",
  lastName: "Doe",
  email: "jane@example.com",
  customData: {
    accountId: "12345",
    planType: "enterprise"
  }
};

window.raiaChat.sendCommand('SET_USER', { user: userData });
08

Iframe setup

Use the Iframe SDK when you need to manage the chat container placement yourself. You embed the chat inside an <iframe> that you manage.

html
<div class="raia-chat-wrapper">
  <iframe
    id="raia-chat-iframe"
    class="raia-chat-iframe"
    src="https://raiabot.raia2.com/YOUR_AGENT_ID/chat"
    allow="camera; microphone;"
  ></iframe>
</div>

<script src="https://raiabot.raia2.com/assets/raia-chatbot-iframe.js"></script>

<script>
  const raiaIframeChat = new window.RaiaIframeChat({
    iframeId: "raia-chat-iframe",
    isSecurityKeyRequired: true, // set to false if you don't use an API key
  });

  window.addEventListener("DOMContentLoaded", () => {
    raiaIframeChat.sendCommand("INIT", {
      apiKey: "YOUR_API_KEY",
    });
  });
</script>

Add Raia Live Chat to a Windows desktop app — Show your Live Chat agent beside your app's screens in a VB.NET WinForms or PxPlus app, using a hosted HTTPS page in an embedded browser.

09

SDK Command Reference (Iframe)

A plain iframe on its own has no command API. The Iframe SDK script shown above wraps it: create it with new window.RaiaIframeChat({ iframeId, isSecurityKeyRequired }), send INIT with { apiKey }, then use sendCommand. It waits for the chat to say it's ready, checks the message origin, and reports each command as accepted or rejected. It handles most Embed JS SDK commands, but CLOSE_CHAT, DESTROY and SET_VIEW_MODE are listed and not handled by the iframe wrapper, so don't rely on them there. Copy the iframe snippet from your agent's Live Chat settings so the page and script match. You send commands via the raiaIframeChat instance you created.

javascript
raiaIframeChat.sendCommand("OPEN_CHAT", { page: "chat" });
raiaIframeChat.sendCommand("SEND_MESSAGE", { message: "Hello!" });
10

CSS Customization (Iframe)

With the Iframe SDK, you can style the <iframe> and its container. The internal chat UI is styled via your Live Chat Design settings.

css
/* Outer wrapper for the iframe */
.raia-chat-wrapper {
  position: relative; /* or absolute/fixed */
  width: 420px;
  height: 600px;
  max-height: 80vh;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.45);
}

/* The iframe itself */
.raia-chat-iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}
11

Live Chat Security Key

Generate a Security Key in Live Chat settings to restrict access. Once enabled, the widget won't load unless you pass the key during initialization.

Generate a key, then add it to your widget initialization code.

Step 1: Generate a Security Key

First, you need to generate the key from your admin panel.

  1. Navigate to Live Chat > Security.
  2. In the Security Key and Origins section, click Generate Security Key.
  3. Copy the generated key immediately. You will need it for your code.
  4. Click Save to activate the key.

Widget blocked until initialized

Once saved, your live chat widget will be blocked on your website until you complete the next step.

Step 2: Add the Security Key to your embed

To unblock the chat, you must pass the security key when the widget loads. This is done by using the onload attribute on your script tag to call a function that sends the INIT command.

The Code Logic

  • The standard chat widget script is loaded with the async attribute.
  • The data-api-key attribute still contains your Agent ID.
  • The onload="onRaiaChatLoaded()" attribute is added to the script tag. This tells the browser to execute the onRaiaChatLoaded function as soon as the script is finished loading.
  • Inside the onRaiaChatLoaded function, you use the SDK command raiaChat.sendCommand().
  • You send the INIT command and pass an object containing the apiKey field.

Important note

The apiKey field inside the INIT command must contain your Security Key, not your Agent ID. Because this runs in the browser, the key is visible in your page source: it is a widget deployment key, not a server secret. These docs don't describe any signed-token (HMAC or JWT) setup.

Code Implementation

Add the example below to your website, replacing the placeholder values with your Agent ID and Security Key.

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Live Chat with Security Key</title>

    <script>
      // This function is called automatically when the chat widget script has loaded
      async function onRaiaChatLoaded() {
        // Send the INIT command with the Security Key
        raiaChat.sendCommand("INIT", {
          apiKey: "YOUR_SECURITY_KEY_HERE", // Paste the key you generated here
        });
      }
    </script>
  </head>

  <body>
    <h1>Your Page Content</h1>

    <!-- The Raia Chatbot Widget Script -->
    <script
      async
      src="https://raiabot.raia2.com/assets/raia-chatbot-widget.js"
      data-api-key="YOUR_AGENT_ID_HERE"
      onload="onRaiaChatLoaded()"
    ></script>
  </body>
</html>

Summary of Placeholders

PlaceholderYour Value
YOUR_SECURITY_KEY_HEREThe Security Key you generated in the admin panel.
YOUR_AGENT_ID_HEREThe Agent ID from your Live Chat settings.
12

Frequently asked questions

Can I open the chat when a user clicks a specific button on my site?

Yes — attach a click listener that calls window.raiaChat.sendCommand('OPEN_CHAT').

How do I style the widget to match my brand?

Basic styling (colors, launcher icon, positioning) is configured in raia CX under the Live Chat Skill. For advanced dynamic styling, use the UPDATE_RAIA_CHAT_THEME command.

Does SET_USER create a new conversation?

No — it just updates the context for the current session. The agent picks up the new information on the very next message.