Slack api conversations.history returns error: not_in_channel

怎甘沉沦 提交于 2020-11-27 04:47:51

问题


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. Queryied the list of channels with conversations.list (this worked fine)
  3. From the output of conversations.list, 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?


回答1:


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.




回答2:


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




回答3:


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)



来源:https://stackoverflow.com/questions/60198159/slack-api-conversations-history-returns-error-not-in-channel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!