Radiate.js
你可以利用Radiate.js,在你的网络和网络聊天之间建立不同的互动关系。
init
用提供的参数初始化网络聊天插件。
Radiate.init(CHANNEL_ID, CHANNEL_TOKEN, options)
Parameters
| Name | Type | Description |
|---|---|---|
| CHANNEL_ID | string | Can be found in the Stella channel |
| CHANNEL_TOKEN | string | Can be found in the Stella channel |
| options | object | optional |
Options
| Name | Type | Description |
|---|---|---|
| notReadyIconUrl | string | Image URL to customise the icon shown when there is network connction issue with our web chat server |
| notReadyText | string | Custom text when there is network connction issue with our web chat server |
| locale | string | Set the initial locale of the user, this should be one of your locale group name on Stella |
| greetings | string | Custome text displayed next to the icon before the icon is clicked |
| defaultOpen | boolean | Control if the messenger frame should be opened when web chat successfully initilized. Default is false |
| ref | string | For passing custom data with the GET_STARTED payload when user click the Get Started Button and talk to the chat bot for the first time |
Example
Radiate.init("CHANNEL_ID", "CHANNEL_TOKEN", {
notReadyIconUrl: "https://s3-ap-southeast-1.amazonaws.com/daydaybot-sanuker/sanuker-bot/sanuker-logo-only-s.png",
notReadyText: "Working hard now...",
locale: "english",
greetings: "Chat with us!",
defaultOpen: true
})
Example Greetings
subscribe
你可以使用subscribe来监听某些网络聊天事件。
Radiate.subscribe(EVENT_NAME, callback)
Parameters
| Name | Type | Description |
|---|---|---|
| EVENT_NAME | string | Can be one of the following values: WEB_ACTION, READY, OPEN_WEBCHAT, CLOSE_WEBCHAT |
| callback | function | Callback function with the event object as a parameter |
WEB_ACTION
当聊天机器人发出WEB_ACTION响应时,会发出WEB_ACTION事件。
event properties
| Name | Type | Description |
|---|---|---|
| event | string | WEB_ACTION |
| data | object | all the custom properties that you defined in your Stella 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
READY事件将在网络聊天插件的初始化完成后发送。
event properties
| Name | Type | Description |
|---|---|---|
| event | string | READY |
OPEN_WEBCHAT
当信使框架被打开时,OPEN_WEBCHAT事件将被发送。
event properties
| Name | Type | Description |
|---|---|---|
| event | string | OPEN_WEBCHAT |
CLOSE_WEBCHAT
CLOSE_WEBCHAT事件将在信使框架被关闭时发送。
event properties
| Name | Type | Description |
|---|---|---|
| event | string | CLOSE_WEBCHAT |
sendEvent
当用户在您的网页上做任何动作时,您可以利用sendEvent与网页聊天插件互动,如打开或关闭网页聊天,或向Stella发送事件以触发聊天机器人流程。
Radiate.sendEvent(EVENT_NAME, data, options)
Parameters
| Name | Type | Description |
|---|---|---|
| EVENT_NAME | string | Can be one of the following values: WEB_EVENT, OPEN_WEBCHAT, CLOSE_WEBCHAT |
| data | string / object | optional |
| options | object | optional |
WEB_EVENT
WEB_EVENT 可用于向Stella发送自定义数据以触发聊天机器人对话。
例子
Radiate.sendEvent("WEB_EVENT", {
payload: "SOME_PAYLOAD",
selectedOption: "OPTION_A"
}, {
openMessenger: true
})
Parameters
| Name | Type | Description |
|---|---|---|
| data | string / object | Custom defined JSON data to send to Stella |
| options | object | optional |
Options
| Name | Type | Description |
|---|---|---|
| openMessenger | boolean | To control whether the messenger frame should be opened upon sending the event. Default is false |
OPEN_WEBCHAT
打开信使框架的事件。
例子
Radiate.sendEvent("OPEN_WEBCHAT")
CLOSE_WEBCHAT
Event for closing the messenger frame.
Example
Radiate.sendEvent("CLOSE_WEBCHAT")

