【发布时间】:2022-12-12 13:04:40
【问题描述】:
我一直在开发 Slack 机器人来帮助我的团队处理紧急情况。它工作得很好,但所有配置都在 JSON 文件中,是时候让它“更具交互性”了。
前几天,我们遇到了一场电子邮件风暴,一次又一次地触发了机器人,所以我认为从“更具交互性”开始的一个很好且相对简单的地方是在我们的网站上添加一个“暂停”按钮机器人(而不是杀死正在运行的进程)。
我成功地显示了模式,并且 UI 功能正常,但我没有收到交互的有效负载。我希望我的 Flask 应用程序收到一个包含交互有效负载数据的 POST 请求,但我没有看到任何到达处理我与 Slack 的大部分交互的“/”端点或 /911_snooze 端点的任何请求直接连接到 Slash 命令。
我收到一个带有以下错误的小三角警告:
下面的 JSON 主要由 Block Kit Builder 创建,有一些手工切割,下拉列表是基于外部列表以编程方式创建的。 Block Kit Builder 报告没有错误。
{
"title": {
"type": "plain_text",
"text": "911 Snooze Alerts",
"emoji": true
},
"submit": {
"type": "plain_text",
"text": "Submit",
"emoji": true
},
"type": "modal",
"callback_id": "snooze_911_alerts",
"close": {
"type": "plain_text",
"text": "Cancel",
"emoji": true
},
"blocks": [
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Application to Snooze"
},
"accessory": {
"type": "static_select",
"placeholder": {
"type": "plain_text",
"text": "Application",
"emoji": true
},
"options": [
{
"text": {
"type": "plain_text",
"text": "APP1",
"emoji": true
},
"value": "BOE"
},
{
"text": {
"type": "plain_text",
"text": "APP2",
"emoji": true
},
"value": "IBOE"
},
{
"text": {
"type": "plain_text",
"text": "APP3",
"emoji": true
},
"value": "GBOE"
},
{
"text": {
"type": "plain_text",
"text": "APP4",
"emoji": true
},
"value": "Swift"
}
],
"action_id": "application_select_action"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "How long do you want to snooze for:"
},
"accessory": {
"type": "radio_buttons",
"options": [
{
"text": {
"type": "plain_text",
"text": "5 minutes",
"emoji": true
},
"value": "minutes-5"
},
{
"text": {
"type": "plain_text",
"text": "30 minutes",
"emoji": true
},
"value": "minutes-30"
},
{
"text": {
"type": "plain_text",
"text": "60 minutes",
"emoji": true
},
"value": "minutes-60"
},
{
"text": {
"type": "plain_text",
"text": "90 minutes",
"emoji": true
},
"value": "minutes-90"
}
],
"action_id": "radio_buttons-action"
}
}
]
}
【问题讨论】:
-
您是否在 Slack App 配置中为交互事件设置了请求 URL?然后您需要从那里解析事件有效负载,因为它会触发 block_action 事件以响应具有相应 action_id 的按钮单击。
-
@BradleyIW,是的,我知道。我的机器人能够正确响应各种交互。正是在这种模式下,我遇到了困难。
标签: python flask slack slack-api slack-block-kit