Slack api conversations.history returns error: not_in_channel

Slack Api

Slack Api Problem Overview


I'm starting out with the Slack API and trying to just get a list of messages.

Here are my steps:

  1. Created a Slack app and gave it channels:read and channels:history scope (also re-installed it)
  2. Queried the list of channels with conversations.list (this worked fine)
  3. From the output of conversations.list, I found a channel that I use and copied the id
  4. Used the conversations.history api with the channelid from step 3

Result:

{ "ok": false, "error": "not_in_channel" }

I'm not at all sure what is happening here. I definitely have messages in the channel, and the documentation page for that api does not say anything about this "not_in_channel" error code.

What am I doing wrong?

Slack Api Solutions


Solution 1 - Slack Api

After a long time of investigations (~2 hours), I found an easy approach. For Caleb's answer, I didn't understand how to invite a Bot to the channel. Hence, I am posting this answer.

Go to your Slack Channel and type the following as a message.

/invite @BOT_NAME

Eg: If your Bot name is SRE Incident Manager the command would be as follows.

/invite @sre_incident_manager

As soon as you start typing @, Slack will automatically suggest. So it becomes easy. For this, the Bot needs to be added to your Slack Workspace.

PS: Original answer.

Solution 2 - Slack Api

This error arises when you are using the bot oauth token and the bot is not invited to the channel. To solve this you need to

  • Invite the bot(slack app) to join the channel.
  • Use the OAuth Access Token instead

To add Bot to your channel you need to write /invite @Bot_name in the slack channel

Solution 3 - Slack Api

The error not_in_channel has the exact meaning, your custom Slack app should be added to the channel.

Exact solution 1

To resolve the error, in the Web Slack interface:

  • Open channel settings
  • Click on the Integrations tab
  • Click Add apps and find your custom app.

Slack app might have different interface, see Iryna Vernik's answer. enter image description here


Alternative solution 2

Give access to the bot to all channels by adding workspace wide scope, for example, chat:write.public. Depends on your needs and security requirements.

Alternative solution 3

To access the channel chat from API specify Incoming webhook. Slack will generate a unique URL with the token per each channel. Only convenient for a few channels.

Solution 4 - Slack Api

I also didn't understand how to invite a Bot to the channel. Way that was proposed by Caleb and Keet was not clear for me or not working. From my side, 'invite' work after

  • open channel
  • in Details tab, choose a 'More'clause
  • in dropdown menu, chouse an 'add app'
  • in pop-up look for you app (bot)

Also i was use Bot User OAuth Access Token, because i need this functionality in private channel (additionaly, you should add for bot groups:history scope)

Solution 5 - Slack Api

FOr me, instead of invite a user/bot, I invite the app.

Categories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric JorgensenView Question on Stackoverflow
Solution 1 - Slack ApiKeet SugathadasaView Answer on Stackoverflow
Solution 2 - Slack ApiCaleb NjiiriView Answer on Stackoverflow
Solution 3 - Slack ApiArtur AView Answer on Stackoverflow
Solution 4 - Slack ApiIryna VernikView Answer on Stackoverflow
Solution 5 - Slack ApiNam G VUView Answer on Stackoverflow