【问题标题】:How to make slack api block kit take up the entire width of the slack window?如何让 slack api block kit 占据整个 slack 窗口的宽度?
【发布时间】:2019-08-09 23:16:14
【问题描述】:

我正在为一些自动通知创建一个 slackbot,我收到了一个请求,让通知占据整个 slack 窗口的宽度,这看起来更干净。我发现块似乎占据了一个指定的宽度,并且不会水平延伸超过该点。我想知道是否有解决方法来删除似乎正在发生的最大宽度

Current implementation: Seems to have a maximum width that isn't specified

Ideally it would end up looking like this

我使用这样的东西作为我的格式化块:

{
    "type": "section",
    "text": {
        "type": "mrkdwn",
        "text": "Testing if a longer message will force the update box to be wider Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    },
    "accessory": {
        "type": "button",
        "text": {
            "type": "plain_text",
            "text": "Button",
            "emoji": true
        },
        "value": "click_me_123"
    }
}

这是 block kit/slack api 的限制吗?或者有没有办法消除这个宽度限制?

Block Kit Builder site if anyone wants to play with formatting

【问题讨论】:

  • 你解决过这个问题吗?

标签: slack-api


【解决方案1】:

Slack 似乎有一种名为 rich_text 的块类型并没有特别详细地记录在案,它确实填满了 Slack 消息面板的宽度。

{
  "blocks": [
    {
      "type": "rich_text",
      "elements": [
        {
          "type": "rich_text_preformatted",
          "elements": [
            {
              "type": "text",
              "text": "+---------+---------+---------+---------+---------+---------+---------+---------+\n
| column1 | column2 | column3 | column4 | column5 | column6 | column7 | column8 |\n
+---------+---------+---------+---------+---------+---------+---------+---------+\n
| row1c1  | row1c2  | row1c3  | row1c4  | row1c5  | row1c6  | row1c7  | row1c8  |\n
+---------+---------+---------+---------+---------+---------+---------+---------+"
            }
          ]
        }
      ]
    }
  ]
}

【讨论】:

  • 当我尝试这个时,我只是得到一个错误返回“unsupported_type:rich_text”。我正在使用 node.js WebClient。
  • 使用 webhook api 对我来说效果很好
  • 不适用于 api-call postMessage (2021-10)
【解决方案2】:

不,您无法定义 Slack 消息/块的确切宽度。宽度是每个消息元素预定义的,并且取决于您的消息呈现的客户端。这是设计使然,因为 Slack 旨在独立于客户端。

【讨论】:

  • 他们“按设计”决定将块的宽度限制为总宽度的 50%,而没有任何方法可以改变它?
  • 是的。但是,请记住,每个平台的具体情况都不同,并且可能会发生变化。
【解决方案3】:

您可以尝试使用下面的块。提到的代码帮助我发送通知并使用整个页面,而不是一半。

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "```{8}```"
            }
        }
    ]
}

这里是链接,你可以查看它。

https://app.slack.com/block-kit-builder/T025QN6JG#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22%60%60%60%7B8%7D%60%60%60%22%7D%7D%5D%7D

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-11
    • 1970-01-01
    • 1970-01-01
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多