Slack API invalid_block

Ben*_*ers 13 slack-api

我正在构建一个简单的 Slack 机器人,并且正在使用该checkboxes元素。

当我从 API 以 JSON 响应返回以下内容到斜杠命令时,我收到错误failed with the error "invalid_blocks",但是,当我将其放入block-kit-builder中时,它可以正常工作(包括“发送到 slack”按钮)

当我运行斜杠命令时,有什么想法会失败吗?是否可以从 slack 中看到更详细的错误消息?

{
  "blocks": [
    {
      "elements": [
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Create new TODO list",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        },
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Help",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        }
      ],
      "type": "actions"
    },
    {
      "text": {
        "text": "Today",
        "type": "mrkdwn"
      },
      "type": "section"
    },
    {
      "elements": [
        {
          "initial_options": [
            {
              "text": {
                "text": "Get Into the garden",
                "type": "mrkdwn"
              },
              "value": "foo"
            }
          ],
          "options": [
            {
              "text": {
                "text": "Get Into the garden",
                "type": "mrkdwn"
              },
              "value": "foo"
            }
          ],
          "type": "checkboxes"
        },
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Add new Task",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        }
      ],
      "type": "actions"
    }
  ],
  "type": "home"
}
Run Code Online (Sandbox Code Playgroud)

小智 6

在 Block Kit Builder 中,数据是带有blocks键的 JSON。在 Slack API 中,blocks参数只是对象list的类型JSON

blocks = [
    {
        "text": {
            "text": "Its the list of your blocks",
            "type": "mrkdwn"
        },
        "type": "section"
    }
]
text = 'Alternative data in text'
client.chat_postMessage(channel=channel_id, blocks=blocks, text=text)
Run Code Online (Sandbox Code Playgroud)


jil*_*ate 2

在api中,“blocks”参数需要是字符串类型。您是否将其转换为字符串或将其用作 JSON ? https://api.slack.com/methods/chat.postMessage 在此输入图像描述