如何使 slack app home 中的复选框默认选中

bil*_*ley 4 slack-api slack slack-block-kit

Slack 让您可以使用块套件构建器轻松构建 UI,包括添加复选框:How do I make all checkboxes select by default on (using JS)? 当用户打开应用程序主页时,是否可以选中 1 个复选框?如果我能做到其中一件事,那么剩下的事情就很容易了。

{
"type": "home",
"blocks": [
    {
    "type": "input",
    "element": {
        "type": "checkboxes",
        "options": [
            {
                "text": {
                    "type": "plain_text",
                    "text": "*this is plain_text text*",
                    "emoji": true
                },
                "value": "value-0"
            },
            {
                "text": {
                    "type": "plain_text",
                    "text": "*this is plain_text text*",
                    "emoji": true
                    },
                  "value": "value-1"
              }
          ],
          "action_id": "checkboxes-action"
      },
      "label": {
          "type": "plain_text",
          "text": "Label",
          "emoji": true
      }
  }
]
}
Run Code Online (Sandbox Code Playgroud)

小智 6

您需要initial_options在块套件代码中使用字段。
https://api.slack.com/reference/block-kit/block-elements#checkboxes__fields

initial_options

与选项中的一个或多个选项完全匹配的一组选项对象。最初加载复选框组时将选择这些选项。

样本

"initial_options": [
                {
                    "text": {
                        "type": "plain_text",
                        "text": "*this is plain_text text*",
                        "emoji": true
                    },
                    "value": "value-0"
                },
                {
                    "text": {
                        "type": "plain_text",
                        "text": "*this is plain_text text*",
                        "emoji": true
                    },
                    "value": "value-1"
                }
            ],
Run Code Online (Sandbox Code Playgroud)

例子:

{
    "type": "home",
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "checkboxes",
                "initial_options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-0"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-1"
                    }
                ],
                "options": [
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-0"
                    },
                    {
                        "text": {
                            "type": "plain_text",
                            "text": "*this is plain_text text*",
                            "emoji": true
                        },
                        "value": "value-1"
                    }
                ],
                "action_id": "checkboxes-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Label",
                "emoji": true
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)