Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I post a bulleted list using the slack api

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?

like image 209
Arnab Datta Avatar asked Nov 16 '25 03:11

Arnab Datta


2 Answers

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

like image 171
Suyash Gaur Avatar answered Nov 18 '25 20:11

Suyash Gaur


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.

like image 24
Sri Harsha Chilakapati Avatar answered Nov 18 '25 18:11

Sri Harsha Chilakapati



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!