Synology Chat 中的自定义整合功能使您可以配置传入和发出的 webhook、机器人和斜杠命令。请单击右上角的配置文件照片图标并选择整合以启用这些功能。
传入的 webhook 将把来自外部源的消息张贴到 Synology Chat。它利用了带 JSON 有效载荷的一般 HTTP 请求,及其它可选设置。
有两种方式可将数据发送到 webhook URL:
payload
参数的 JSON 字符串。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 将注意 Synology Chat 消息中的触发词。这些触发词将向外部 URL 发送相关数据。只有符合以下一项或两项条件时,才会触发发出的 webhook:
如果已指定频道,则触发词为可选项。如果未选择频道,则触发词为必填项。但如果两个条件均已定义,则只有两个条件同时满足时,发出的 webhook 才会发生。
当收到的消息符合触发条件时,POST 将被递送到指定的 URL。数据栏描述如下:
token: bot tokenchannel_idchannel_nameuser_id用户名post_id时间戳文本trigger_word: which trigger word is matched
如果外部目的地要在 Synology Chat 频道中作出响应,则 JSON 需在响应的正文中返回。支持的栏与传入的 webhook JSON 相同。
斜杠命令可让您通过在文本栏中键入"/"来轻松触发外发 webhook。只有您会看到回复,因而其他用户可避免收到无关的消息。
斜杠命令可在整合中自定义。您可单击右上角的"配置文件照片"来访问整合。
在任何频道或会话的文本栏中键入前斜杠"/",系统将会显示您和您的团队所创建的命令列表,供您选择。例如,如果键入"/"并选择"/lunch",webhook 将会向您推荐食物。
机器人可以启动与您之间的一对一会话、张贴从外部来源发送的消息以及侦听用户在会话中发送的消息。
勾选在聊天机器人列表中隐藏选项会阻止用户在机器人列表中查看和添加此机器人。
在机器人配置栏中输入了传出 URL 之后,Synology Chat 会在用户向机器人发送消息时向该 URL 发送请求。数据栏描述如下:
token: bot tokenuser_id用户名post_id时间戳文本
可以在 POST 请求中通过有效载荷参数分配接收者和消息。例如:
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 的用户。
在与机器人的会话中,机器人可以发送文本和文件,还可以附加特定数据(附件)和交互式对象(操作)。当前为交互式对象提供了按钮。可以在有效载荷中将要附加的消息添加到附件栏。例如:
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"}]}]}
Synology 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 数据以修改原始 POST。除了user_id,支持的格式与有效载荷的格式相同。
例如:
{"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 tokenchannel_id = channel_id is intended for browsingnext_count = the number of messages that comes after a postprev_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 tokenpost_id = post_id is intended for browsing