0

我正在使用 slack Bolt API 构建一个 slack 应用程序,并且我想在单击主页上的按钮时从我的应用程序主页打开模式。

这是连接到按钮的动作侦听器的相关位:

app.action("follow-users-button", async ({ ack, payload, client }) => {

                await ack();
                console.log("app_home opening keyusermodal");
                // await block_actions.unfollowKeyuser(action);
                console.log("payload = " + JSON.stringify(payload));
                await client.views.open({
                    trigger_id: payload.trigger_id,

这是我单击该按钮时在终端上得到的内容:

payload = {"action_id":"follow-users-button","block_id":"2JW","text":{"type":"plain_text","text":"Users","emoji":true},"value":"click_me_123","type":"button","action_ts":"1642280065.631917"}
[ERROR]  bolt-app missing required field: trigger_id

那里的 JSON 是操作有效负载。

然而,根据 Slack 文档,这个有效载荷应该更大。这是来自 Slack 的 Block Kit Builder 的示例负载:

{
    "type": "block_actions",
    "user": {
        "id": "U02NF0A8D9T",
        "username": "person",
        "name": "person",
        "team_id": "T02NTJ0UDP3"
    },
    "api_app_id": "A02",
    "token": "Shh_its_a_seekrit",
    "container": {
        "type": "message",
        "text": "The contents of the original message where the action originated"
    },
    "trigger_id": "12466734323.1395872398",
    "team": {
        "id": "T02NTJ0UDK3",
        "domain": "4most-r637660"
    },
    "enterprise": null,
    "is_enterprise_install": false,
    "state": {
        "values": {}
    },
    "response_url": "https://www.postresponsestome.com/T123567/1509734234",
    "actions": [
        {
            "type": "button",
            "block_id": "QdL",
            "action_id": "button-action",
            "text": {
                "type": "plain_text",
                "text": "Click Me",
                "emoji": true
            },
            "value": "click_me_123",
            "action_ts": "1642279809.506518"
        }
    ]
}

如您所见,我只在我的有效负载中接收操作元素。剩下的在哪里?怎么还不过来?我需要 trigger_id 来打开一个模式(没有它会导致错误),并且获取 user_id 之类的东西对我的应用程序非常有帮助。

提前致谢!

4

1 回答 1

0

使用Bolt JS框架时,解析操作负载以获取触发器 id 的预期方法是body.trigger_id.

于 2022-01-18T17:52:41.747 回答