Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack Bot - Python slack send markdown messages

I'm trying to send markdown messages in slack using SlackBot but I'm unable to find the documentation, All I got is this:

response = client.chat_postMessage( 
    ...:     channel='#testing-bot', 
    ...:     text="Hello world! <@USerID> \n\n - a \n-b" 
    ...:     
    ...:     )  

I want to send MArkdown MEssages, instead of the text one I tried:

    ...:     channel='#testing-bot', 
    ...:     mkdwn="Hello world! <@UNVD64N02> \n\n - a \n-b" 
    ...:     
    ...:     )  

but didn't work. Help

like image 876
Charanjit Singh Avatar asked May 19 '26 15:05

Charanjit Singh


1 Answers

You need to send in the channel id (it will be alpha-numeric string) in instead of channel name (#testing-bot).

Update: You can also use block kit which is a UI framework for slack apps. It comes with a block kit builder which can be used for real-time view of block code. Added the references below for both.

response = client.chat_postMessage(
    channel="", # channel ID
    text="",
    blocks=[
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Hello world! <@UNVD64N02> :tada: \n\n - a \n-b"
            }
        }
    ]
)

Output:
Blockkit

References:

  • https://api.slack.com/block-kit
  • https://api.slack.com/tools/block-kit-builder
like image 134
stud3nt Avatar answered May 21 '26 03:05

stud3nt