copilot widget demo

The chat widget enables you to interact with the Copilot from your dashboard and see the changes in real-time. Open is a React web app that you can embed in your web app.

There are several ways you can integrate the Copilot Chat widget into your application/webpage.

Using simple js script

  1. By using CDN script into your html file.

    <script src="https://unpkg.com/@openchatai/widget@latest/dist-embed/pilot.js"></script>
    

    this will automatically register a new function called initAiCoPilot on the global window object.

  2. Init the copilot (when document fully loads) by calling the initAiCoPilot function and passing the required options. There are plenty of options that you can pass to the copilot, you can find them here

    <script>
      const options = {
         apiUrl: "https://api-v2.opencopilot.so/backend",
         socketUrl: "https://api-v2.opencopilot.so",
         initialMessage: "Hey! happy to help.", 
         token: "your_copilot_token_goes_here", // you can get your token from the dashboard
       }
       window.addEventListener("DOMContentLoaded", ()=>initAiCoPilot(options)); // window.onload
    </script>
    

As a React Component

  1. Install the widget from npm.

     npm install @openchatai/widget 
    
  2. Use the Component inside your application

import { CopilotWidget,Root } from "@openchatai/widget"; 
const options = {
  apiUrl: "https://api-v2.opencopilot.so/backend",
  socketUrl: "https://api-v2.opencopilot.so", 
  initialMessage: "Hey! happy to help.",
  token: "your_copilot_token_goes_here", // you can get your token from the dashboard
}
function Widget(){
  return (
    <Root options={options}>
    <CopilotWidget />
    </Root>
  )
}

Available options

The chat widget is highly customizable, here is a list of all the available options:

Options
Object

Identifying chat users/contacts

One of the helpful options in the chat widget is the ability to identify the user/contact of the chat. This is useful if you want to track the usage of the chat widget.

To start identifying the user/contact, you can pass the user object as an option to the chat widget, for example:

const options = {
  apiUrl: "https://api-v2.opencopilot.so/backend",
  socketUrl: "https://api-v2.opencopilot.so",
  initialMessage: "Hey! happy to help.", 
  token: "your_copilot_token_goes_here",
  user: {
    name: "your_user_name",
    email: "your_user_email",
    avatar: "your_user_avatar_url",
    phone: "your_user_phone",
    customData: {
      // any custom data you want to send to the copilot backend 
      "key1": "value1",
    }
  },
}

Read more about the contact APIs here

FAQ