Search code examples
pythonslack-apislack

Can I send richly-formatted Slack messages as a Bot and not as a Webhook?


I started writing a Slack bot in Python and came to a halt when I couldn't find a way to send richly-formatted messages using the either of the two methods:

sc.rtm_send_message("channel_name", my_message)

sc.api_call("chat.postMessage", channel="channel_name", text=my_message, username="username", icon_url="icon_url")

where my_message = json.dumps({'attachments': [{...}]})

I now know that I can do this using the webhook approach but is it possible with the above method?


Solution

  • I found out where I was going wrong.

    I was passing my message to the wrong argument in the sc.api_call method.

    I should've been passing it to sc.api_call(attachments=...) argument, not the text argument.