Slack error: failed with the error "invalid_blocks"

Slack error: failed with the error "invalid_blocks"

我正在构建一个启动模式的内部 slack 应用程序,因此可以更有效地为技术请求提供票证。

当我在 JSON 对斜杠命令的响应中 return 来自我的 API 的以下内容时,我收到错误失败,错误为“invalid_blocks”,然而,当我把它放在 block-kit-builder 中时,它工作得很好(包括“发送到 slack”按钮)

知道为什么当我 运行 我的斜杠命令时失败了 - 是否可以从 slack 中看到更详细的错误消息?

return {
        statusCode: 200,
        body: JSON.stringify({
                "callback_id": "tech-support",
                "title": {
                    "type": "plain_text",
                    "text": "Tech Support Ticket",
                    "emoji": true
                },
                "submit": {
                    "type": "plain_text",
                    "text": "Submit",
                    "emoji": true
                },
                "type": "modal",
                "close": {
                    "type": "plain_text",
                    "text": "Cancel",
                    "emoji": true
                },
                "blocks": [
                    {
                        "type": "input",
                        "element": {
                            "type": "plain_text_input"
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Ticket Title",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "static_select",
                            "placeholder": {
                                "type": "plain_text",
                                "text": "Select an item",
                                "emoji": true
                            },
                            "options": [
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Website",
                                        "emoji": true
                                    },
                                    "value": "value-0"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Hubspot",
                                        "emoji": true
                                    },
                                    "value": "value-1"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Email",
                                        "emoji": true
                                    },
                                    "value": "value-2"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Other",
                                        "emoji": true
                                    },
                                    "value": "value-3"
                                }
                            ]
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Impacted Technology",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "checkboxes",
                            "options": [
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Security",
                                        "emoji": true
                                    },
                                    "value": "value-4"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Productivity",
                                        "emoji": true
                                    },
                                    "value": "value-5"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Data Accuracy",
                                        "emoji": true
                                    },
                                    "value": "value-6"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Feature Suggestion",
                                        "emoji": true
                                    },
                                    "value": "value-7"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Client Useability",
                                        "emoji": true
                                    },
                                    "value": "value-8"
                                }
                            ]
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Business Impacts",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "radio_buttons",
                            "options": [
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Yes",
                                        "emoji": true
                                    },
                                    "value": "value-9"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "No",
                                        "emoji": true
                                    },
                                    "value": "value-10"
                                }
                            ]
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Does the problem block you from your core deliverables",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "plain_text_input",
                            "multiline": true
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Give a detailed description of the problem",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "static_select",
                            "placeholder": {
                                "type": "plain_text",
                                "text": "Select an item",
                                "emoji": true
                            },
                            "options": [
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "High: Critical To Reach Operations",
                                        "emoji": true
                                    },
                                    "value": "value-11"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Medium: Multi-Person Technical Inconvenience",
                                        "emoji": true
                                    },
                                    "value": "value-12"
                                },
                                {
                                    "text": {
                                        "type": "plain_text",
                                        "text": "Low: Normal Technical Issue",
                                        "emoji": true
                                    },
                                    "value": "value-13"
                                }
                            ]
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Select a priority",
                            "emoji": true
                        }
                    },
                    {
                        "type": "divider"
                    },
                    {
                        "type": "input",
                        "element": {
                            "type": "multi_users_select",
                            "placeholder": {
                                "type": "plain_text",
                                "text": "Select users",
                                "emoji": true
                            }
                        },
                        "label": {
                            "type": "plain_text",
                            "text": "Does this impact other people as well?",
                            "emoji": true
                        }
                    }
                ]

        }),
    };```

从 Slash 命令获取负载时,发送的响应只能 return 一条消息。必须通过 views.open API 方法打开模式,将 JSON 传递给 view 参数,斜杠命令有效负载中的 trigger_id,以及用于验证您的请求的令牌。

使用 Bolt and the Block Builder JS 库,这看起来像这样:

const openMyView = async ({ body, context, client }) => {

  // Do some stuff and build viewParams object

  const view = callSomeMethod(viewParams); // Calls a method that uses Block Builder to build a modal

  await client.views.open({
    view: view.buildToJSON(); // Could also be just the JSON built from Slack's builder site
    token: context.botToken,
    trigger_id: body.trigger_id,
  });
};