2

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

Bart
  • 53
  • 6

1 Answers1

3

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.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • I am using slash commands but my app calls some API and modifies other data sometimes user need to wait more than 3000ms to response so I need to use chat.postEphemeral to send the response to the channel, therefore I can't use quick JSON response to slash command. I will consider responding to response_url from slash command payload. – Bart May 13 '19 at 20:25
  • yes. you got up to 30 minutes to reply to slash commands using response_url – Erik Kalkoken May 13 '19 at 20:42
  • If this answer solved your problem, please consider marking it as solution by clicking on the check-mark. TY – Erik Kalkoken May 14 '19 at 12:28