I'm using the Slack API to post automatic messages with various statuses. To mark the status, I use emoji icons. Sending works fine, and the right icon is set (I see it in the response), but subsequent posts are running together in the channel, so even if even if the icon is different, it does not show until there is a message from another user in between:
[red icon] BOT_USER msg #1 some info - status critical
msg #2 some info - status ok (should have green icon!)
msg #3 some info - status critical
[user icon] SOME_USER some message
[green icon] BOT_USER msg #4 some info - status ok
(sorry, not enough rep to post a screenshot)
Is there a way to split the messages, ensuring the icon is always displayed? If not, is there a way to e.g. change a message's background color?
I found the way to mark it using the attachments. My script looks like that (quoting gave me some headache):
ATTACHMENTS="[{\"fallback\":\"$INPUT\",\"text\":\"$INPUT\",\"color\":\"$COLOR\"}]"
curl -sS -X POST \
--data "token=$TOKEN&channel=$CHANNEL_ID&username=$FROM&attachments=$ATTACHMENTS" \
https://slack.com/api/chat.postMessage
Setting the $COLOR
variable to danger
, good
, or a hex color, provides a vertical bar of that color next to the message, which works for me. So, even if the messages get grouped by user, the bars provide distinction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With