node.js - Slack API - 单击按钮时从同一消息中获取其他组件的值

标签 node.js express slack slack-api

我有这个互动消息:

 [
    {
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "The number of items you want to see (Top X)"
        },
        "accessory": {
            "type": "static_select",
            "placeholder": {
                "type": "plain_text",
                "text": "X",
                "emoji": true
            },
            "options": [
                {
                    "text": {
                        "type": "plain_text",
                        "text": "1",
                        "emoji": true
                    },
                    "value": "1"
                }
            ]
        }
    },
    {
        "type": "section",
        "text": {
            "type": "mrkdwn",
            "text": "The criteria you want to group by"
        },
        "accessory": {
            "type": "static_select",
            "placeholder": {
                "type": "plain_text",
                "text": "Select a criteria",
                "emoji": true
            },
            "options": [
                {
                    "text": {
                        "type": "plain_text",
                        "text": "criteria1",
                        "emoji": true
                    },
                    "value": "criteria1"
                }
            ]
        }
    },
    {
        "type": "actions",
        "elements": [
            {
                "type": "button",
                "text": {
                    "type": "plain_text",
                    "text": "Fetch P&L",
                    "emoji": false
                }
            }
        ]
    }
]

the message

当用户单击按钮时,如何获取用户在 2 个下拉菜单中选择的值?

它不在我从 Slack 获得的事件负载中。我正在使用 NodeJS 库与 express 应用程序中的 Slack 进行通信,并且希望有一个也使用这些库的解决方案。

最佳答案

Slack UI 的工作方式与标准 HTTP 表单略有不同。

每个交互式组件(例如选择或按钮)都是独立的,当用户单击它时,Slack 会向您的应用发送仅包含该组件信息的请求。

要组合多个交互式组件,您有两种选择:

  • 您可以分多个步骤进行查询。因此,您首先发送一条消息询问商品数量。然后用户做出选择,您的应用程序会收到来自 Slack 的请求。然后您的应用程序会替换该消息并询问标准。等等。
  • 或者您可以使用 Slack Dialog 。这将显示为模态窗口,并允许您一步查询最多 5 个元素。

关于node.js - Slack API - 单击按钮时从同一消息中获取其他组件的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56070104/

相关文章:

javascript - 推特 API : media/upload 400 Bad Request: media type unrecognized

node.js - 使用 node.js 检索用于 mongo 查询的副本实例

node.js - Socket.IO连接轮询,提示未找到错误404

node.js - 如何使用mongoose插入嵌套文档帖子有很多评论,评论有很多回复

bash - 为 slack bot 创建 jq json

slack - 通过传入的 webhook 发送消息时出现 channel_not_found 异常

javascript - 通过 nodejs 服务器 + socket.io 从 mp3 文件同步流式传输音乐

javascript - 如何显示宽度为 :100% in Chrome 的表格

node.js - 从开发环境将 React 应用程序部署到 Heroku 后,Fetch 请求中断 - 所有 GET 请求返回 index.html - 其他为 404

bash - 从 slack 运行 bash 命令