Can I send richly-formatted Slack messages as a Bot and not as a Webhook?
<p>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:</p>

<pre><code>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")
</code></pre>

<p>where <code>my_message = json.dumps({'attachments': [{...}]})</code></p>

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

<p>Both API (method chat.postMessage) and incoming webhook offer the same options for formatting your messages including markup and attachments.</p>

<p>Hint: if you want to use markup in your attachments, make sure to add the field "mrkdwn_in" and name the field your want to use it in or it will be ignored by Slack.</p>

<p>Example:</p>

<pre><code>{
    "attachments": [
        {
            "title": "Title",
            "pretext": "Pretext _supports_ mrkdwn",
            "text": "Testing *right now!*",
            "mrkdwn_in": ["text", "pretext"]
        }
    ]
}
</code></pre>

<p>See <a href="https://api.slack.com/docs/message-formatting" rel="nofollow">here</a> for full documentation.</p>

python slack-api slack