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

Slack API - get values of other components from the same message when clicking a button

我有这条互动消息:

 [
    {
        "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
                }
            }
        ]
    }
]

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

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

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

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

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

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