WoztellWebchat.js
You can use WoztellWebchat.js to create different interactions between your website and the web chat.
init
Initialize the web chat plugin with the provided parameters.
WoztellWebchat.init({version: "1.0", token: "TOKEN"}, {options})
Parameters
| Name | Type | Description |
|---|---|---|
version | string | Version of the Web Chat Integration |
token | string | Unique token for each Web Chat Integration |
options | object | optional |
Options
| Name | Type | Description |
|---|---|---|
| Default Open | boolean | Control if the messenger frame should be opened when web chat successfully initializes. Default is false. |
| ref | string | For passing custom data when the user starts a conversation with the chatbot for the first time. |
| Greetings | string | Custom text displayed next to the icon before the icon is clicked. |
| Default Locale | string | Set the initial locale of the user. This should be one of the locale group names you created in the Web Chat integration. |
| Not Ready Icon URL | string | Image URL to customize the icon shown when there is a network connection issue with the Web Chat server. |
| Not Ready Text | string | Custom text when there is a network connection issue with the web chat server. |
| Load Delay | integer | Default: 3000 ms. Time to wait until the not ready icon shows up. During the waiting time, the system checks if the Web Chat is ready every 300 ms. |
| Welcome Message | string | Message shown when the web chat opens (for example, a greeting before the user sends the first message). |
Example
const loadWoztell = async () => {
WoztellWebchat.init(
{
version: "1.0",
token: "",
},
{
defaultOpen: true,
notReadyText: "Loading...",
loadDelay: 1000,
welcomeMessage:
"Welcome. How can I help you?",
}
);
};
subscribe
Use subscribe to listen to certain web chat events.
WoztellWebchat.subscribe(EVENT_NAME, callback)
Parameters
| Name | Type | Description |
|---|---|---|
EVENT_NAME | string | Can be one of: WEB_ACTION, READY, OPEN_WEBCHAT, CLOSE_WEBCHAT |
callback | function | Callback function with the event object as a parameter |
WEB_ACTION
The WEB_ACTION event is sent when the chatbot sends a WEB_ACTION response.
event properties:
| Name | Type | Description |
|---|---|---|
event | string | WEB_ACTION |
data | object | All custom properties defined in your WOZTELL response |
from | string | Bot ID. In web chat, this is usually the channel ID |
to | string | User ID |
timestamp | number | Time of update (epoch time in milliseconds) |
READY
Sent when initialization of the webchat plugin has completed.
| Name | Type | Description |
|---|---|---|
event | string | READY |
OPEN_WEBCHAT
Sent when the messenger frame has been opened.
| Name | Type | Description |
|---|---|---|
event | string | OPEN_WEBCHAT |
CLOSE_WEBCHAT
Sent when the messenger frame has been closed.
| Name | Type | Description |
|---|---|---|
event | string | CLOSE_WEBCHAT |
sendEvent
When the user performs actions on your website, use sendEvent to interact with the web chat plugin (open/close chat or send events to WOZTELL to trigger a chatbot flow).
WoztellWebchat.sendEvent(EVENT_NAME, data, options)
Parameters
| Name | Type | Description |
|---|---|---|
EVENT_NAME | string | Can be one of: WEB_EVENT, OPEN_WEBCHAT, CLOSE_WEBCHAT |
data | string / object | optional |
options | object | optional |
WEB_EVENT
WEB_EVENT sends custom data to WOZTELL to trigger a chatbot conversation.
WoztellWebchat.sendEvent(
"WEB_EVENT",
{
payload: "SOME_PAYLOAD",
selectedOption: "OPTION_A",
},
{
openMessenger: true,
}
);
| Name | Type | Description |
|---|---|---|
data | string / object | Custom JSON data to send to WOZTELL |
options | object | optional |
Options:
| Name | Type | Description |
|---|---|---|
openMessenger | boolean | Whether the messenger frame should open when sending the event. Default is false. |
OPEN_WEBCHAT
Event for opening the messenger frame.
WoztellWebchat.sendEvent("OPEN_WEBCHAT")
CLOSE_WEBCHAT
Event for closing the messenger frame.
WoztellWebchat.sendEvent("CLOSE_WEBCHAT")