-1

我创建了以下 BLOCK,但无法弄清楚如何在 /Command 中使用它。它在 ack({...}) 中使用时显示良好,但在我使用 say({...}) 时什么也不做。唯一的另一种方法是带有 type: modal 的 client.dialog ,但这不是我想要的。

我只需要知道如何使用我的 JSON 块工具包代码进行响应。任何帮助表示赞赏。

{
    "attachments": [
        {
            "blocks": [
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "plain_text",
                            "text": user_id + ", this was your question",
                            "emoji": True
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                                "text": question,
                                "emoji": True
                    }
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "plain_text",
                            "text": "Here's what I found",
                            "emoji": True
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": answer
                    }
                },
                {
                    "type": "divider"
                },
                {
                    "type": "section",
                    "text": {
                        "type": "plain_text",
                                "text": "Info",
                                "emoji": True
                    }
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Author:* " + author
                        }
                    ]
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Book:* " + booktitle
                        }
                    ]
                },
                {
                    "type": "context",
                    "elements": [
                        {
                            "type": "mrkdwn",
                            "text": "*Page:* " + str(page_num)
                        }
                    ]
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": content
                    }
                },
                {
                    "type": "divider"
                },
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": "Was this helpful?"
                    },
                    "accessory": {
                        "type": "static_select",
                        "placeholder": {
                            "type": "plain_text",
                            "text": "please select an answer from the drop-down",
                            "emoji": True
                        },
                        "options": [
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was spot on*",
                                            "emoji": True
                                },
                                "value": "1"
                            },
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was somewhat helpful*",
                                            "emoji": True
                                },
                                "value": "0"
                            },
                            {
                                "text": {
                                    "type": "plain_text",
                                            "text": "*This was not helpful*",
                                            "emoji": True
                                },
                                "value": "-1"
                            }
                        ],
                        "action_id": "static_select-action"
                    }
                }
            ]
        }
    ]
}

编辑这可以工作吗?

  client.chat_postMessage(
    channel=event['channel'],
    blocks=[
        {...})

编辑

@app.command("/q")
def q_command(client, event, ack, command):
ack("Gotcha! Let me take a look...")
user_id = event.get("user")
#...
client.chat_postMessage(
    channel=event['channel'],
    blocks=[
        { ... }])
4

1 回答 1

0

你提到的将起作用。
虽然,如果您只想响应调用命令的同一通道/dm,
您应该response_url事件 payload中使用 received 。
https://api.slack.com/interactivity/handling#message_responses

let res = await axios.post(rsp_url, {
      blocks: blocks
    });

进一步阅读: 您还可以查看以下文档。
SDK:https
://slack.dev/python-slack-sdk/webhook/index.html#response-url消息类型:https ://slack.dev/python-slack-sdk/web/index.html#messaging

于 2021-09-01T02:03:49.347 回答