Introduction
Section titled β Introduction βThis documentation provides details on how to use the Chatbot Web SDK. The Chatbot Web SDK allows you to integrate a chatbot into your website.
To integrate the Chatbot Web SDK into your website, you need to inject the following script:
<script src="https://widget.yourgpt.ai/script.js" id="yourgpt-chatbot" data-widget="<YOUR_WIDGET_ID>"></script>
Replace YOUR_WIDGET_ID
with your actual widget ID. You can find your widget ID in the
Chatbot Dashboard.
$yourgptChatbot
Section titled β$yourgptChatbotβAfter the Chatbot Web SDK script is loaded, the $yourgptChatbot
variable becomes available. This variable provides methods to interact with the chatbot.
Execution Commands
Section titled β Execution Commands βThese are the commands that can be executed using the $yourgptChatbot.execute()
function.
Command | Description |
---|---|
widget:open | Opens the chatbot. |
widget:close | Closes the chatbot. |
message:send | Sends a message to the chatbot. |
message:send
payload
Section titled β message:send payload βmessage:send
payload Property | Description | Type | Default |
---|---|---|---|
text | The message text. | string | |
send | Indicates whether the message should be sent to the chatbot or not. | boolean | false |
Opening the chatbot
Section titled β Opening the chatbot β$yourgptChatbot.execute("widget:open");
Sending a message to the chatbot
Section titled β Sending a message to the chatbot β$yourgptChatbot.execute("message:send", { text: "Hello", send: true });
Here the text
is the message that you want to send to the chatbot. The send
parameter is a boolean value that indicates whether the message should be sent to the chatbot or not. If the send parameter is set to false, the message will be displayed in the chatbot but will not be sent to the chatbot.
Closing the chatbot
Section titled β Closing the chatbot β$yourgptChatbot.execute("widget:close");
Event Listeners
Section titled β Event Listeners βThe Chatbot Web SDK provides event listeners that you can use to listen to events that occur in the chatbot. To add an event listener, you need to call the $yourgptChatbot.on(event,callback)
function.
Event Name | Description | Arguments |
---|---|---|
init | Triggered when the chatbot is initialized. | |
widget:popup | Triggered when the chatbot popup opens or closes. It provides a boolean in the callback indicating the state (true for open, false for closed). | state:boolean |
Example: Listen to the init event
Section titled β Example: Listen to the init event β$yourgptChatbot.on("init", function() { console.log("Chatbot initialized");});
Removing an event listener
Section titled β Removing an event listener βTo remove an event listener, you need to call the $yourgptChatbot.off(event,callback)
function.
Set Command
Section titled β Set Command βThe Chatbot Web SDK provides a set command that you can use to set visitor, session and widget data. To set data, you need to call the $yourgptChatbot.set(type,data)
function.
Type | Description | Payload |
---|---|---|
visitor:data | Sets the visitor data. | object |
session:data | Sets the session data. | object |
Example: Set visitor data
Section titled β Example: Set visitor data β$yourgptChatbot.set("visitor:data", { customKey: "value",});
Example: Set session data
Section titled β Example: Set session data β$yourgptChatbot.set("session:data", { customKey: "value",});
Set Contact Data
Section titled β Set Contact Data βType | Description | Payload |
---|---|---|
contact:data | Sets the contact data. | objectCheck supported fields π |
Supported Contact payload fields for update
Section titled β Supported Contact payload fields for update βField | Description | Type | Required |
---|---|---|---|
A valid email address. | string | Either email or phone is required | |
phone | A valid phone number e.g. +1234567890. | string | Either phone or email is required |
name | Name of the contact. | string | No |
ext_user_id | A unique identifier for the contact. | string | No |
Example: Set contact data
Section titled β Example: Set contact data β$yourgptChatbot.set("contact:data", { phone: "+1234567890", name: "Andrew", ext_user_id: "123456",});
Configuring Data for Iframe Embeds
Section titled βConfiguring Data for Iframe Embeds βIf you are using the Chatbot Web SDK with an iframe embed, you can set the visitor, session, and contact data by passing the data in the query parameters of the iframe URL.
Visitor Data
Section titled β Visitor Data βTo set visitor data, append the VISITOR_DATA.keyName=value
query parameter to your iframe URL.
<iframe src="<widgetUrl>?VISITOR_DATA.customKey=value"></iframe>
Session Data
Section titled β Session Data βTo set session data, append the SESSION_DATA.keyName=value
query parameter to your iframe URL.
<iframe src="<widgetUrl>?SESSION_DATA.customKey=value"></iframe>
Contact Data
Section titled β Contact Data βTo set contact data, append the CONTACT.keyName=value
query parameter to your iframe URL.
<iframe src="<widgetUrl>?VISITOR_DATA.customKey=value&SESSION_DATA.customKey=value&[email protected]"></iframe>
curl --location 'https://api.yourgpt.ai/chatbot/v1/createSession' \\--header 'Content-Type: application/x-www-form-urlencoded' \\--header 'api-key: pks-3e0a221e3d0d78cf0ecd73be363a728e1dfa2a0ee01cc4ff8b8c99c21a45cff9' \\--data-urlencode 'widget_uid=8449240d-8454-4173-af6e-569477ac9013'