我怎样才能让 slack app home 中的复选框默认选中

How can i make check boxes in slack app home selected be default

Slack 让您可以使用 block kit builder 非常轻松地构建 UI,包括添加复选框:如何让所有复选框默认选中(使用 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
      }
  }
]
}

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

initial_options

An array of option objects that exactly matches one or more of the options within options. These options will be selected when the checkbox group initially loads.

样本

"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"
                }
            ],

示例:

{
    "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
            }
        }
    ]
}