Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split Slack messages from same user?

Tags:

slack-api

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?

like image 698
code_assassin Avatar asked Oct 19 '22 13:10

code_assassin


1 Answers

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.

like image 131
code_assassin Avatar answered Oct 23 '22 00:10

code_assassin