Search code examples
slackslack-api

Get Slack channel where app is integrated


I might be missing something really simple but don't seem to find the solution.

I have created a quick and simple app which is meant to do some processing every morning and then send some logs to Slack.

I have been perfectly able to do so using Incoming Webhooks. Cool. The "problem" is that it requires me to set it up from the app settings (aka it obviously makes me define a specific channel for the Webhook so I can have the specific URL) and that's something I like a bit less.

I thought it'd be easier if I can just add/integrate the app on a channel using the Slack UI so I don't have to worry about having to know beforehand the channel(s) ID where the message has to go to and also any other user would be able to integrate in any other channel they consider.

I have integrated it on my testing channel (all good) and tested chat.postMessage (all good) but it still needs the channel (obviously). However, using conversations.list lists ALL channels and that's the opposite of what I'm looking for.

I need a way of getting just those channels where the app is integrated so I can post the message to those and only those.

Is this something that Slack doesn't allow or I'm just missing something very obvious here?

I hope it makes sense and someone can shed some light on this :)


Solution


  • You can use users.conversations method to get list conversations the calling user/bot may access.
    https://api.slack.com/methods/users.conversations

    Use Bot token to call the API.
    Use type argument to search public, private, mpim & im conversations
    https://api.slack.com/methods/users.conversations#arg_types

    Mix and match channel types by providing a comma-separated list of any combination of public_channel, private_channel, mpim, im