i am working on a slack app (scope including bot and incoming webhooks). I can send message to a defined channel but i don't know how to stop using the "&channel=" parameter and just send messages to listening channels. By listening i mean, when the app is installed, user is asked where to post (channel or dm has to be chosen).
String postUrl = "https://slack.com/api/chat.postMessage?token=" + botAccessToken + "&as_user=false&channel=%23community&text=testing&username=CommunityQ";
Any hints would be useful.
I think you can't: According to the official Slack API documentation it is not possible to send messages to all/multiple listening channels:
Incoming webhooks output to a default channel and can only send messages to a single channel at a time. You can override a custom integration's configured channel by specifying the channel field in your JSON payload.
I interpret this as "there is always exactly one channel your message is sent to"
Furthermore, Slack restricts this channel override feature for Slack apps:
You cannot override the default username, icon, or channel for incoming webhooks attached to Slack apps.
I think there is a slight confusion here. I am not sure what the "incoming webhook" scope does that the "bot" scope cannot do. Here's how I see things
If you give a bit more details in what you want to achieve we can perhaps help you better
If you want a more dynamic approach on sending messages into any channel I would suggest to user the API method chat.postMessage
instead of an incoming webhook.
The API method can post messages into any channel (including private channels, DMs) as long as your token as access to it.
As Michael mentioned in his answer, it is not possible to post to multiple channels at the same time. You have to look through them and do multiple requests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With