slack incoming webhook - send message to another c

2020-04-10 01:51发布

I am trying to post message to any channel in a slack team.

My webhook has been properly created and installed into my test team. As part of the install process, I selected "Post to #channel1"

When I review permissions, I see my app has been granted Other/Post to specific channels in Slack (#channel1).

From there, I am able to post into #channel1 with a basic JSON request:

{
    "text":"Hello, World!"
}

Now I want to validate I can use same webhook to post to any other channel of the same team. So I created a channel #channel2 and I try the following request:

{
    "channel":"#channel2",
    "text":"Hello, World!"
}

The request is accepted (HTTP Status 200) but it still publishes on #channel1.

What am I doing wrong ? Is that a syntax or permission issue ? I guess it is more a permission issue but I have not found how to grant my app access to additional channels (or all channels).

Regards.

2条回答
神经病院院长
2楼-- · 2020-04-10 02:49

The app needs the chat:write:bot permission to post messages to other channels.

The permission can be added in Manage Apps → your app → OAuth & Permissions:

The default permission, and the permission necessary to post to other channels / users.

Reading Slack's own documentation, this was not obvious to me. (although it is mentioned under "Using the Web API" in the Intro to Messaging.)

查看更多
倾城 Initia
3楼-- · 2020-04-10 02:51

I created an incoming Webhook, and I found this documentation (see image)

I followed the instructions given in that, and I found that it worked. I can send a message to a different channel than the one the Incoming Webhook was set for

Overriding Slack Channel in a webhook

查看更多
登录 后发表回答