Skip to content
SDK Web

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:

example.js
<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.

After the Chatbot Web SDK script is loaded, the $yourgptChatbot variable becomes available. This variable provides methods to interact with the chatbot.

These are the commands that can be executed using the $yourgptChatbot.execute() function.

CommandDescription
widget:openOpens the chatbot.
widget:closeCloses the chatbot.
message:sendSends a message to the chatbot.
PropertyDescriptionTypeDefault
textThe message text.string
sendIndicates whether the message should be sent to the chatbot or not.booleanfalse
example.js
$yourgptChatbot.execute("widget:open");
example.js
$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.

example.js
$yourgptChatbot.execute("widget:close");

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 NameDescriptionArguments
initTriggered 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.js
$yourgptChatbot.on("init", function() {
console.log("Chatbot initialized");
});

To remove an event listener, you need to call the $yourgptChatbot.off(event,callback) function.

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.

TypeDescriptionPayload
visitor:dataSets the visitor data.object
session:dataSets the session data.object
example.js
$yourgptChatbot.set("visitor:data", {
customKey: "value",
});
example.js
$yourgptChatbot.set("session:data", {
customKey: "value",
});
TypeDescriptionPayload
contact:dataSets the contact data.objectCheck supported fields πŸ‘‡
FieldDescriptionTypeRequired
emailA valid email address.stringEither email or phone is required
phoneA valid phone number e.g. +1234567890.stringEither phone or email is required
nameName of the contact.stringNo
ext_user_idA unique identifier for the contact.stringNo
example.js
$yourgptChatbot.set("contact:data", {
phone: "+1234567890",
name: "Andrew",
ext_user_id: "123456",
});

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.

To set visitor data, append the VISITOR_DATA.keyName=value query parameter to your iframe URL.

example.html
<iframe src="<widgetUrl>?VISITOR_DATA.customKey=value"></iframe>

To set session data, append the SESSION_DATA.keyName=value query parameter to your iframe URL.

example.html
<iframe src="<widgetUrl>?SESSION_DATA.customKey=value"></iframe>

To set contact data, append the CONTACT.keyName=value query parameter to your iframe URL.

example.html
<iframe src="<widgetUrl>[email protected]"></iframe>
example.html
<iframe src="<widgetUrl>?VISITOR_DATA.customKey=value&SESSION_DATA.customKey=value&[email protected]"></iframe>
example.curl
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'