Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack WebApi block section, don't wrap line of text

My type: section block looks pretty standard.

{
  "type": "section",
  "text": {
    "type": "mrkdwn",
    "text": "A message *with some bold text* and _some italicized text_."
  }
}

I realized that Slack wraps lines longer than ~85 characters (I didn't bother to figure out the exact number). This is however not true for any messages I write myself into Slack (not via WebApi, no sure if it's treated as a block internally).

enter image description here

My question is: Can I stop Slack from wrapping lines that early? It looks ugly if there are lengthy lines of text conversations going on and suddenly there's a cropped bot message spreading over multiple lines - especially on large screens.

like image 669
lapsus Avatar asked Nov 11 '19 07:11

lapsus


People also ask

How do I create a code block in Slack?

From your desktop, click the plus icon next to the message field. Search for and select Create a text snippet from the menu. Enter a title if you'd like, then choose a file type from the drop-down menu. Type or paste your snippet in the Content field.

What is attachments in Slack?

Message attachments allow you to add richer formatting to messages, as well as interactive buttons and menus.

How do I send attachments in Slack API?

You must provide either a file or content parameter. The content of the file can either be posted using an enctype of multipart/form-data (with the file parameter named file ), in the usual way that files are uploaded via the browser, or the content of the file can be sent as a POST var called content .


1 Answers

No. Slack makes it own decision on when to wrap lines, mostly depending on the current client and platform.

There are no configuration options or markups to change that behavior like white-space: nowrap; with CSS.

But of course your can force line breaks with \n in your text strings.

Further clarification

The reason why you have different line breaks in your example is that Slack is handling simple text posts differently then blocks and attachments.

If you post a simple message the text will use the full width of your screen. That is the same behavior as when you make a post manually.

Example:

{
    "channel": "blueberry",
    "text": "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."
}

However, if you post a layout blocks or attachments those are always formatted to a certain max width. My guess is that Slack does that, so all blocks nicely line up with each other, but I do not know this for sure. Anyways, as said before this behavior can not be configured.

{
    "channel": "blueberry",
    "blocks": 
    [
        {
            "type": "section",
            "text": 
            {
                "type": "mrkdwn",
                "text": "    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."
            }
        }
    ]
}

So, if you want your post to use the full length of the screen, just don't use blocks and post as a normal message instead.

like image 186
Erik Kalkoken Avatar answered Sep 22 '22 07:09

Erik Kalkoken