37

I follow Slack bot post message documents

it works perfectly when post to public channel, but get error [error] => channel_not_found when post to private channel, I even change channel_name to channel ID (ex: G1HCG4BQ9)

I already authorized with both chat:write:user and chat:write:bot permissions

Community
  • 1
  • 1
ytdm
  • 1,069
  • 1
  • 12
  • 15

8 Answers8

66

Did you invite the bot to the channel? A bot can't post in a private channel if it's not a member - you need to invite it to the channel like you would a person.

@YourBotsName will do it!

Sam Mullin
  • 659
  • 5
  • 7
8

I ran into this same issue and was able to solve it by using chat.postEphemeral with the OAuth Access Token available in the OAuth & Permissions page of your app configuration, which should be accessible at https://api.slack.com/apps/APP-ID-GOES-HERE/oauth

Note that there are two different token types, the OAuth Access Token and Bot User OAuth Access Token. When I tried using the Bot User OAuth Access Token to send an ephemeral message to a user while they were in a private chat with another user, I received the same error message as you: channel_not_found, however, it worked properly when using the OAuth Access Token.

See here for details regarding the different token types.

adamc
  • 1,315
  • 19
  • 16
  • The `OAuth Access Token` does not appear by default, you need to grant the app some User Token Scopes and reinstall the app, then the `OAuth Access Token` will appear, alongside the `Bot User OAuth Access Token`. – alexykot Feb 03 '21 at 11:57
7

i had the same issue. for getting a message in private channel you just need to manually add your app there enter image description here

4

I had the same issue. You need to add your bot manually in the private channel with the slack command invite

/invite @yourBotName

Don't forgot to add OAuthS Scope chat:write from Features/OAuth & Permissions

Demont Zhang
  • 184
  • 4
1

Sam Mullin answer is correct, it's the first point you need to look at.

But for me even that didn't work out. I didn't consider incoming webhook(https://api.slack.com/messaging/webhooks), because that's also an option, but not in my case.

The thing that got me progressing is that slack has "Tester" tab for testing requests in its api method f.e. https://api.slack.com/methods/chat.postMessage/test. When you fill out the data and submit, the request you see in url also consists "token" and "pretty" arguments. I've added token argument only to authorization header, which didn't work for me, so I've added it also as param. For pretty argument I set same as text message.

I'm not sure about security issues, when passing token directly,somebody could correct me on that. But that's a variant that worked out for me.

Oleksandr Verhun
  • 814
  • 1
  • 8
  • 23
1

I had the same problem today, you have to add the app to the desired private channel manually.

Kévin Berthommier
  • 1,402
  • 15
  • 15
0

It only worked for me when I added message.groups on Subscribe to bot events. Before just on public channels.

enter image description here

-2

Try setting explicitly as_user: false and using the team access token instead of the bot user's one.

Alex Ramirez
  • 1
  • 1
  • 1