How do I post a bulleted list using the slack api
Asked Answered
P

3

19

Background

I am trying to use the slack bolt jdk along with the following dependencies:

  // Slack bolt SDK
  implementation("com.slack.api:bolt:1.8.1")
  implementation("com.slack.api:bolt-servlet:1.8.1")
  implementation("com.slack.api:bolt-jetty:1.8.1")
  implementation("com.slack.api:slack-api-model-kotlin-extension:1.8.1")
  implementation("com.slack.api:slack-api-client-kotlin-extension:1.8.1")

What I want to achieve (in slack)

enter image description here

What I currently am getting (in slack)

enter image description here

What I've tried so far

fun SlashCommandContext.sendSectionAndAck(
  message: String,
): Response {
  slack.methods(botToken).chatPostMessage { req ->
    req
      .channel(channelId)
      .blocks {
        section {
          markdownText(message)
        }
      }
  }
  return ack()
}

It seems like the markdown is being formatted almost properly. The header and footer are both bold as intended, but for some reason, the bulleted list is not being formatted correctly. I have also tried replacing the * with - without any luck.

In my case, I can call the function with the following input:

val input = """
*Some header text in bold*
- item
- another item
*Some footer text also in bold*
"""
sendSectionAndAck(input)

What am I doing wrong?

Punak answered 22/7, 2021 at 9:57 Comment(0)
J
24

The easiest workaround for this would be using '•' character itself in the text.

Slack also uses following as part of the block kit message to reflect bullet points:

"text": "• test",

"blocks": [
    {
      "type": "rich_text",
      "block_id": "erY",
      "elements": [
        {
          "type": "rich_text_list",
          "elements": [
            {
              "type": "rich_text_section",
              "elements": [
                {
                  "type": "text",
                  "text": "test"
                }
              ]
            }
          ],
          "style": "bullet",
          "indent": 0
        }
      ]
    }

Another reference:
https://superuser.com/questions/1282510/how-do-i-make-a-bullet-point-in-a-slack-message

Joan answered 22/7, 2021 at 10:17 Comment(3)
Fair enough I guess.Punak
Any pointer to documentation on the rich_text block type? It's not in the Slack reference api.slack.com/reference/block-kit/blocksLigneous
Ah, found this: api.slack.com/changelog/…Ligneous
P
2

Use the rich text blocks. The best and easiest way would be to use the Block Kit Builder by Slack. You can edit in WYSIWYG and get the payload generated for you.

{
    "blocks": [
        {
            "type": "rich_text",
            "elements": [
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Hello, this is some regular text.\n\n"
                        }
                    ]
                },
                {
                    "type": "rich_text_list",
                    "style": "bullet",
                    "indent": 0,
                    "border": 0,
                    "elements": [
                        {
                            "type": "rich_text_section",
                            "elements": [
                                {
                                    "type": "text",
                                    "text": "SPOC 1 <"
                                },
                                {
                                    "type": "link",
                                    "url": "mailto:[email protected]",
                                    "text": "[email protected]"
                                },
                                {
                                    "type": "text",
                                    "text": ">"
                                }
                            ]
                        },
                        {
                            "type": "rich_text_section",
                            "elements": [
                                {
                                    "type": "text",
                                    "text": "SPOC 2 <"
                                },
                                {
                                    "type": "link",
                                    "url": "mailto:[email protected]",
                                    "text": "[email protected]"
                                },
                                {
                                    "type": "text",
                                    "text": ">"
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "\nAnd here is some more text, some "
                        },
                        {
                            "type": "text",
                            "text": "bold",
                            "style": {
                                "bold": true
                            }
                        },
                        {
                            "type": "text",
                            "text": " text, some "
                        },
                        {
                            "type": "text",
                            "text": "italic",
                            "style": {
                                "italic": true
                            }
                        },
                        {
                            "type": "text",
                            "text": " text too!"
                        }
                    ]
                }
            ]
        }
    ]
}

Generates the following output:

Output

Hope this helps.

Perfectionism answered 1/2 at 13:42 Comment(0)
S
1

A simple jq script to prefix a stream of lines read from stdin with bullets for the purposes of pasting into a slack message:

jq -rR '"\u2022 \(.)"'

Submit answered 8/8, 2022 at 0:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.