Skip to main content

WoztellWebchat.js

You can make use of WoztellWebchat.js to create different interactions between your web and the web chat.

init

Initialize the web chat plugin with the provided parameters

WoztellWebchat.init({version: "1.0", token: "TOKEN"}, {options})

Parameters

NameTypeDescription
versionstringVersion of the Web Chat Integration
tokenstringUnique token for each Web Chat Integration
optionsobjectoptional

Options

NameTypeDescription
Default OpenbooleanControl if the messenger frame should be opened when web chat successfully initialize. Default is false
refstringFor passing custom data when user start a conversation with the chatbot for the first time
GreetingsstringCustom text displayed next to the icon before the icon is clicked
Default LocalestringSet the initial locale of the user, this should be one of the locale group name you created in the Web Chat integration
Not Ready Icon URLstringImage URL to customize the icon shown when there is network connection issue with our Web Chat server
Not Ready TextstringCustom text when there is network connection issue with our web chat server
Load DelayIntegerDefault: 3000ms; the time to wait until the not ready icon shows up, during the waiting time the system will check if the Web Chat is ready every 300ms

Example:

WoztellWebchat.init(
{version: "1.0", token: "TOKEN"},
{"defaultOpen":false,
"ref":"test_parma",
"greetings":"Hi there, free feel to talk to us!",
"locale":"English",
"notReadyIconUrl":"https://picsum.photos/123/321",
"notReadyText":"Preparing...",
"loadDelay":2500}
)

Example Greetings
Example Greetings

subscribe

You could use subscribe to listen to certain web chat events.

WoztellWebchat.subscribe(EVENT_NAME, callback)

Parameters

NameTypeDescription
EVENT_NAMEstringCan be one of the following values: WEB_ACTION, READY, OPEN_WEBCHAT, CLOSE_WEBCHAT
callbackfunctionCallback function with the event object as a parameter

WEB_ACTION

The WEB_ACTION event is sent when the chatbot sent out the WEB_ACTION response. event properties

NameTypeDescription
eventstringWEB_ACTION
dataobjectall the custom properties that you defined in your WOZTELL response
fromstringBot ID, in web chat, this is usually the channel ID
tostringUser ID
timestampnumberTime of update (epoch time in milliseconds)

READY

The READY event will be sent when the initialization of the webchat plugin has completed.

event properties

NameTypeDescription
eventstringREADY

OPEN_WEBCHAT

The OPEN_WEBCHAT event will be sent when the messenger frame has been opened.

event properties

NameTypeDescription
eventstringOPEN_WEBCHAT

CLOSE_WEBCHAT

The CLOSE_WEBCHAT event will be sent when the messenger frame has been closed.

event properties

NameTypeDescription
eventstringCLOSE_WEBCHAT

sendEvent

When the user does any actions on your web, you can make use of sendEvent to interact with the web chat plugin, like opening or closing the web chat or send events to WOZTELL to trigger a chatbot flow.

WoztellWebchat.sendEvent(EVENT_NAME, data, options)

Parameters

NameTypeDescription
EVENT_NAMEstringCan be one of the following values: WEB_EVENT, OPEN_WEBCHAT, CLOSE_WEBCHAT
datastring / objectoptional
optionsobjectoptional

WEB_EVENT

WEB_EVENT can be used to send custom data to WOZTELL to trigger a chatbot conversation.

Example

WoztellWebchat.sendEvent("WEB_EVENT", {
payload: "SOME_PAYLOAD",
selectedOption: "OPTION_A"
}, {
openMessenger: true
})

Parameters

NameTypeDescription
datastring / objectCustom defined JSON data to send to WOZTELL
optionsobjectoptional

Options

NameTypeDescription
openMessengerbooleanTo control whether the messenger frame should be opened upon sending the event. Default is false

OPEN_WEBCHAT

Event for opening the messenger frame.

Example

WoztellWebchat.sendEvent("OPEN_WEBCHAT")

CLOSE_WEBCHAT

Event for closing the messenger frame.

Example

WoztellWebchat.sendEvent("CLOSE_WEBCHAT")