How can I color part of Slack incoming-webhook messages?

后端 未结 2 1463
野性不改
野性不改 2020-12-10 11:24

I want to compose a python script which sends a color-formatted message to a configured slack channel. I managed to send sentences of plain texts to slack channels but I cou

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-10 12:03

    Unfortunately it is at the moment not possible to color text of a Slack message with the API. You can use different styles, e.g. bold and italic, but not colors. (See Message Formatting in Slack documentation on how to use styles.)

    You can use colors for your attachments. That will however result in a vertical color bar marker for the whole attachment, but not in colored text. (See Attachment Parameters in Slack documentation on how to color your attachments.)

    Here is an example on how to use colors for Slack attachments (taken from the Slack documentation):

    {
        "attachments": [
            {
                "fallback": "New ticket from Andrea Lee - Ticket #1943: Can't rest my password - https://groove.hq/path/to/ticket/1943",
                "pretext": "New ticket from Andrea Lee",
                "title": "Ticket #1943: Can't reset my password",
                "title_link": "https://groove.hq/path/to/ticket/1943",
                "text": "Help! I tried to reset my password but nothing happened!",
                "color": "#7CD197"
            }
        ]
    }
    

提交回复
热议问题