连接到自定义平台
介绍
Stella 允许您与自定义平台和自定义实时聊天系统集成。客户和代理可以留在自己的平台上,并通过实时聊天间接相互交谈。
入口:客户、顾客或用户可以与聊天机器人交互的平台。可选地,客户可以通过插座平台进入实时聊天。
出口:座席、客户服务团队或管理员可以回答客户实时聊天请求的平台。命令形式的聊天机器人交互可能最少。
对于自定义平台,用户需要自己托管网络聊天服务并构建自己的 UI。
它是如何运作的?
当来自 inlet 平台的客户端请求实时聊天时,我们将向 Livechat API 发送实时聊天请求。自定义实时聊天系统应处理实时聊天请求(例如创建新工单、将工单交付给特定组、为工单分配代理或其他适合系统的程序)。
要了解如何在 Stella 中请求实时聊天,请参阅以下示例代码:
return new Promise(async (resolve) => {
try {
const result = await this.createAssignment({
member: this.member,
assignmentDetails: {
summary: "summary",
groupName: "groupName",
},
createGroup: {},
history: true,
label: "Label",
meta: {}
})
console.log("Create Assignment result", result)
this.member.botMeta.liveChat = true;
this.member.group = result.groupId;
this.member.createAssignmentSuccess = true;
console.log("Create Assignment - Successfully created assignment");
} catch (err) {
console.log("Create Assignment - Fail to create assignment" + err);
this.member.createAssignmentSuccess = false;
}
resolve({ member: this.member })
})
实时聊天系统应该通过 Webhook API 向 Stella 发送任何管理员回复,并带有 sendToInlet
字段。 然后我们会将回复转发给入口平台中的客户端。
另一方面,当客户端向入口机器人发送消息时,我们将通过 Relay API 将消息中继到出口平台。
如果管理员正在触发聊天机器人流程,通常是通过键入命令,则应将请求发送到带有 sendToBot
字段的 Webhook API。 我们会将任何聊天机器人响应发送到 Send API。
Webhook API
Webhook API 是 Sanuker 聊天机器人服务的入口点。 当用户键入消息、单击按钮或以其他方式与机器人交互时,自定义平台应向 Webhook API 发送请求。 自定义平台应指定是将事件发送到机器人逻辑,还是将消息中继到其入口平台中的相应用户。
下面将列出请求 webhook API 的文档:
API Endpoint
Method | Path |
---|---|
POST | https://bot.stellabot.com/v2.4/customWebhook |
Query Params
Key | Value |
---|---|
accessToken | To be provided |
c | Channel ID (can be found in Channels page) |
a | Organisation ID (can be found in Settings page) |
Header
Key | Value |
---|---|
Content-type | application/json |
Body
Field | Type | Required | Description |
---|---|---|---|
profile | Object | Yes | User profile |
externalId | String | Yes | Unique ID for user in custom platform |
sendToBot | Object | No | Pass the message event to chatbot flow |
sendToInlet | Object | No | Relay the message from admin to user |
sendToBot
Field | Type | Required | Description |
---|---|---|---|
messageEvent | Object | Yes | Message Object |
messageEvent
Field | Type | Required | Description |
---|---|---|---|
from | String | Yes | Unique ID for user in custom platform |
to | String | No | Unique ID for conversation |
type | String | Yes | eg. “PAYLOAD”, “TEXT” |
data | Object | Yes | Message Object (Example fields are listed below. Additional fields can be added as needed.) |
timestamp | Number | Yes | Timestamp in ms |
data
Field | Type | Required | Description |
---|---|---|---|
text | String | No | Text of the message |
payload | String | No | Payload of the button |
sendToInlet
Field | Type | Required | Description |
---|---|---|---|
response | Object | Yes | Response Object |
memberId | String | Yes | Unique ID for inlet user ( member._id from Livechat API) |
Response
Code | Description |
---|---|
200 | A successful bot flow or the message is successfully relayed to inlet user |
500 | An error is encountered, with the Error object in body |
实时聊天 API
为 Stella 准备 API 以发送来自入口用户的实时聊天请求。 API 路径将保存在 channel.info.livechatApi
中。 当用户触发 livechat 事件时,我们会将以下正文作为 JSON 发送到 Livechat API(下面仅列出重要字段):
body
Field | Type | Description |
---|---|---|
member | Object | Member object of the user requesting livechat |
assignmentDetails | Object | Details of the livechat |
chatHistoryURL | String | (Optional) Link for the chat history of the user |
meta | Object | (Optional) Meta data of the livechat request |
member
Field | Type | Description |
---|---|---|
_id | String | Unique ID for user on Stella |
profile | Object | User profile |
meta | Object | Meta data of the user |
botMeta | Object | Bot-related meta data of the user |
assignmentDetails
Field | Type | Description |
---|---|---|
summary | String | (Optional) A summary of the livechat request that can be sent to the agent |
groupName | String | (Optional) A name that the outlet system will use to create the conversation group for admin |
Response
Code | Description |
---|---|
200 | Live chat request is successfully processed |
>= 400 | Encounter error when processing the live chat request |
中继API
为 Stella 准备 API 以将客户端消息中继到相应的实时聊天对话。 API 路径将保存在 channel.info.relayResponseApi
中。 当入口用户在触发实时聊天后发送消息时,我们会将以下正文作为 JSON 发送到 Relay API(以下仅列出重要字段):
body
Field | Type | Description |
---|---|---|
response | Object | Response object |
member | Object | Member object of the inlet user |
channel | Object | Channel object of the outlet channel that the message is relaying to |
For Response Object, you can refer to the message types.
member
Field | Type | Description |
---|---|---|
_id | String | Unique ID for user on Stella |
profile | Object | User profile |
meta | Object | Meta data of the user |
botMeta | Object | Bot-related meta data of the user |
botMeta
Field | Type | Description |
---|---|---|
tempData | Object | Temporary meta data of the user |
channel
Field | Type | Description |
---|---|---|
info | Object | Information of the channel |
Response
Code | Description |
---|---|
200 | Message is successfully relayed to the live chat |
>= 400 | Encounter error when sending the message to the live chat |
对于错误情况,Stella 会将原始消息发送到频道的实时聊天树,其中包含无法发送到实时聊天的消息的字段 relayMessageError
。 一个全局节点,带有一个条件为this.messageEvent.relayMessageError
的触发器,应该被添加到实时聊天树中以捕获这个错误。 如果需要,可以在实时聊天树中的节点中实施任何必要的操作或响应以处理错误。
发送 API
为 Stella 准备 API 以向特定用户或对话发送响应。 如果提供了 conversationId,则应将响应发送到对话,否则应将响应发送到成员。 API 路径将保存在 channel.info.sendResponseApi
中。 我们将以下正文作为 JSON 发送到 Send API(下面仅列出重要字段):
body
Field | Type | Description |
---|---|---|
response | Object | Response object |
member | Object | Member object that the response is sent to |
channel | Object | Channel object |
conversationId | String | (Optional) Unique ID for conversation that the response is sent to (same as messageEvent.to in Webhook API) |
For Response Object, you can refer to the message types.
member
Field | Type | Description |
---|---|---|
externalId | String | Unique ID for user in custom platform (same as messageEvent.from in Webhook API) |
profile | Object | User profile |
meta | Object | Meta data of the user |
botMeta | Object | Bot-related meta data of the user |
channel
Field | Type | Description |
---|---|---|
info | Object | Information of the channel |
Response
Code | Description |
---|---|
200 | Message is successfully relayed to the live chat |
>= 400 | Encounter error when sending the message to the live chat |
连接到自定义频道
- 在“频道”中,创建一个新频道。
- 在“平台”中,选择“自定义”作为部署平台。
- 然后,下面将显示“自定义信息”。
- 在“自定义信息”中输入端点 URL。