Sending JSON to Slack in a HTTP POST request

后端 未结 11 778
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 05:21

I\'m trying to send a message using Slack\'s chat.postMessage API call. I have no problems encoding my test messages within HTTP GET, but I\'m trying to achieve the same res

11条回答
  •  佛祖请我去吃肉
    2020-12-24 06:09

    This may not qualify for the complete answer, but if the purpose is to send a message attachment, you can send a urlencoded JSON structure as the value of the attachments parameter, like so (split into multiple lines for clarity):

    https://slack.com/api/chat.postMessage?
    token=YOUR-TOKE-N000&
    channel=%23alerts&
    text=Hi&
    attachments=%5B%7B%22color%22%3A%22good%22%2C%22fallback%22%3A%22plain+text%22%2C%22text%22%3A%22colored+text%22%7D%5D
    

    The value of attachments is URL-encoded [{"color":"good","fallback":"plain text","text":"colored text"}]. You should be able to use all attachment attributes described here.

提交回复
热议问题