在 Synology Chat 中使用整合功能

Synology Chat 中的自定义整合功能使您可以配置传入和传出的 webhook、机器人和斜杠命令。请单击右上角的配置文件照片图标并选择整合以启用这些功能。

传入的 Webhook

传入的 webhook 将把来自外部源的消息张贴到 Chat。它利用了带 JSON 有效载荷的一般 HTTP 请求,及其他可选设置。

若要发送消息:

有两种方式可将数据发送到 webhook URL:

JSON 有效载荷可包含 text 属性,该属性可张贴到指定频道。例如:

payload={"text": "First line of message to post in the channel.\nAlso you can have a second line of message."}

若要添加链接:

若要添加链接,您可将其链接直接输入到 text。例如:

payload={"text": "<https://www.synology.com>"}

其他示例:

payload={"text": "Check this!! <https://www.synology.com|Click here> for details!"}

若要上传文件:

您还可上传传入文章中的文件。若要上传文件,您的 JSON 有效载荷必须含有 file_url 属性,而且还要有可选文本属性。我们将下载您的 URL 并将其按用户文件上传文章处理。例如:

payload={"text": "a fun image", "file_url": "http://imgur.com/xxxxx"}

注意:

传出的 Webhook

传出的 webhook 将注意 Chat 消息中的触发词。这些触发词将向外部 URL 发送相关数据。只有符合以下一项或两项条件时,才会触发传出的 webhook:

如果已指定频道,则触发词为可选项。如果未选择频道,则触发词为必填项。但如果两个条件均已定义,则只有两个条件同时满足时,传出的 webhook 才会发生。

传出数据:

当收到的消息符合触发条件时,POST 将被递送到指定的 URL。数据字段描述如下:

token: bot token
channel_id
channel_name
user_id
username
post_id
timestamp
text
trigger_word: which trigger word is matched

响应:

如果外部目的地要在 Chat 频道中作出响应,则需在响应的正文中传回 JSON。支持的字段与传入的 webhook JSON 相同。

斜杠命令

斜杠命令可让您通过在文本字段中键入“/”来轻松触发外发 webhook。只有您会看到回复,以避免其他用户收到无关消息。

若要创建斜杠命令:

斜杠命令可在整合中自定义。您可单击右上角的“配置文件照片”来访问整合

若要使用斜杠命令:

在任何频道或对话的文本字段中键入前斜杠“/”,系统将会显示您和您的团队所创建的命令列表,供您选择。例如,如果键入“/”并选择“/lunch”,webhook 将会向您推荐食物。

机器人

机器人能够与用户建立一对一对话、在对话中张贴外部传入的消息并聆听用户在对话中发出的消息。

若要禁止用户启动与机器人之间的活动对话:

勾选在聊天机器人列表中隐藏选项会阻止用户在机器人列表中查看和添加此机器人。

若要发送传出数据:

在机器人配置字段中输入了传出 URL 之后,当用户向机器人发送消息时,Chat 会向该 URL 发送请求。数据字段描述如下:

token: bot token
user_id
username
post_id
timestamp
text

注意:

若要发送传入消息:

您可以通过 POST request 中的 payload 参数来分配接收者和消息。例如:

payload={"text": "First line of message to post in the channel.\nAlso you can have a second line of message.", "user_ids": [5] }

这表示消息 First line of message to post in the channel.\nAlso you can have a second line of message.> 发送到 user_id 为 5 的用户。

若要将消息附加到传入消息:

在与机器人的对话中,机器人可以发送文本和文件,还可以附加特定数据 (attachment) 和交互式对象 (action)。当前为交互式对象提供了按钮。可以在 payload 中将要附加的消息添加到 attachment 字段。例如:

attachments: array of attachment object

attachment object: {
  callback_id: string[2], which refers to the string self-defined by the bot service.This will be sent to you when a user triggers an event attached with data.
  text: string
  actions: array of action object
}

action object: {
  type: "button"
  text: string
  name: string
  value: string
  style: string, where green, grey, red, orange, blue, and teal are the feasible values
}

例如:

payload={"text": "Hello World", "user_ids": [3], "attachments":
[{"callback_id": "abc", "text": "attachment", "actions":
[{"type": "button", "name": "resp", "value": "ok", "text": "OK", "style": "green"}]}]}

若要接收用户触发的交互式数据:

当用户触发交互式对象时,Chat 会向机器人的传出 URL 发送请求。数据字段描述如下:

payload = {
  "actions": array of action object, which refers to the action triggered by the user
  "callback_id": string, which refers to the callback_id of the attachment where the action triggered by the user is located
  "post_id"
  "token"
  "user": {
  "user_id"
  "username"
  }
}

机器人收到请求之后,可以发送回 JSON 数据以修改原始文章。除了 user_id,支持的格式与 payload 的格式相同。

例如:

{"text": "Got your response!"}

若要列出机器人可见的对话:

可以向以下 URL 发送请求:
[Chat URL]/webapi/entry.cgi?api=SYNO.Chat.External&method=channel_list&version=2

并且可以包含以下参数:
token = bot token

若要列出机器人可见的用户:

可以向以下 URL 发送请求:
{Chat URL}/webapi/entry.cgi?api=SYNO.Chat.External&method=user_list&version=2

并且可以包含以下参数:
token = bot token

若要列出机器人可见的消息

可以向以下 URL 发送请求:
{Chat URL}/webapi/entry.cgi?api=SYNO.Chat.External&method=post_list&version=2

并且可以包含以下参数:
token = bot token
channel_id = channel_id is intended for browsing
next_count = the number of messages that comes after a post
prev_count = the number of messages that comes before a post, with 1 as the minimum
(optional)post_id = post_id is intended for browsing, the unfilled post_id refers to the newest message

若要下载文件的数据:

可以向以下 URL 发送请求:
{Chat URL}/webapi/entry.cgi?api=SYNO.Chat.External&method=post_file_get&version=2&post_id={post id}&token="{bot token}"

并且可以包含以下参数:
token = bot token
post_id = post_id is intended for browsing

注意: