Sending message to different channel via slack webhook fails

后端 未结 2 1340
臣服心动
臣服心动 2020-12-03 23:28

I\'m not sure if I am understanding the way how to use webhooks quite right, but: I want to send messages in different channels or to different users (not at once), without

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 00:02

    In general incoming webhooks are fixed to the configured channel. So if you want to send messages to users and/or multiple channels you need to create multiple webhooks or send messages though the API (e.g. chat.PostMessage).

    However, there is a another way to create webhooks, that allows you to send messages to every channel with the same webhook by adding a channel override property ('channel') to your message. Its how incoming webhooks used to work in the past and part of legacy custom integrations.

    To create such a webhook you need to install an app called "Incoming webhooks" from the Slack App Directory (app is made by the Slack team).

    Syntax:

    POST https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX
    Content-type: application/json
    {
        "text": "Hello, world."
        "channel": "U12345678"
    }
    

    Where U12345678 is the Slack ID of the user you want to send a direct message to.

    Note that the channel property is optional and the message will be send to the default channel if omitted.

    See here fore the full documentation.

提交回复
热议问题