Bart
Bart

Reputation: 73

Why chat.postEphemeral returns error channel_not_found if for direct message channel?

I am building a Slack App which shows an ephemeral message to users if they use my custom slash command anywhere: direct messages, public channel or private channel.

It all works on public channels and private channels (where the bot is invited), but when a request comes from a direct message channel (user is typing something to another user in a direct message channel) I get an error: channel_not_found.

Am I missing any of app permissions or chat.postEphemeral doesn't work for direct messages channels?

In the documentation is information that chat.postEphemeral works in private conversation.

Here is the response from a direct message channel (user write to another user):

{ 
  token: 'myValidToken',
  team_id: 'TG8HU58EM',
  team_domain: 'Test',
  channel_id: 'DGE085TRH',
  channel_name: 'directmessage',
  user_id: 'UG1TR625J',
  user_name: 'test.user',
  command: '/my-command',
  text: 'help',
  response_url:
'https://hooks.slack.com/commands/TG8HU58EM/459862138745/VvhWfjkzqj41g21MZnQnJh8J',
  trigger_id: '459862138745.76621584642.5dc0055d2dd61c155fd1cd1c163df5a5' }

The bot scopes: bot scopes

Upvotes: 2

Views: 1542

Answers (1)

Erik Kalkoken
Erik Kalkoken

Reputation: 32737

Your bot user needs to be a member to every non-public channel to be able to post messages. That includes direct message channels. So if e.g. user A has a direct conversations with user B your bot user is obviously not a part of that channel. Therefore your bot gets the error.

That method will work in direct message channels, but only for direct conversations of your bot user with others.

If you want your app to work in all channels you may want to consider switching to slash commands. Those will also work in any direct message channel.

Upvotes: 3

Related Questions