question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot post message to DM or private group

See original GitHub issue

Description

When I call app.client.chat.postMessage with the channel id of a direct message or private group, I get the error channel_not_found. I’m confused because my bot is able to post in channels fine. I’ve read through the api for postMessage multiple times but still don’t understand what my problem is. Thanks!

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
aoberoicommented, Apr 22, 2020

Hey folks I think I can provide some help here.

In the case of slash commands, neither a bot token nor a user token are necessary. From a security point of view, a user invoking a slash command is considered an implicit temporary grant for the app to post a message back to that conversation.

So if your app just wants to send a message to the conversation where the slash command was invoked, there’s no reason to try and get app.client.chat.postMessage() to work with the right token. Instead, use the respond() function, which is passed as an argument to your listener function. The respond() function have be used up to 5 times within 30 minutes after the slash command was invoked. Under the hood, it uses the response_url, which is described here: https://api.slack.com/interactivity/handling#message_responses. It’s also alluded to in the Bolt for JS docs , but maybe a complete example would be more helpful:

app.command('/demo', async ({ command, ack, respond }) => {
  
  // Let the user know immediately that their command was received
  await ack('One moment please...');
  

  // Do some stuff that may take a while (possibly more than 3 seconds)
  const result = await doSomeStuff(command.text);
  await respond({
    // Replace the previous message to clean up the history
    replace_original: true,
    text: `The result is ${result}`,
  });
});

For completeness, I should probably also mention that if you can come up with a response immediately (without calling some other async operation) then you should just use that as the argument for await ack(), as I’ve done above with “One moment please…”.

4reactions
jackleincommented, Apr 22, 2020

@securisec unfortunately it seems that this action isn’t possible anymore with the new apps. with a legacy slack app this was possible, but as of a few months ago you have to use version 2 of slack’s oauth. it’s sort of unbelievable that the new version of slack apps leave this function out :–(

Read more comments on GitHub >

github_iconTop Results From Across the Web

Slack bot cannot post message to private 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...
Read more >
Unable to send messages on Facebook | Facebook Help Center
If you see an error message saying “You can't reply to this conversation,” it might be because: A message or something you shared...
Read more >
chat.postMessage method - Slack API
This method posts a message to a public channel, private channel, or direct message/IM channel. Consider reviewing our message guidelines, especially if ...
Read more >
Why isn't my DM going through? - Discord Support
If your direct message was unable to be sent, you will receive an error message from Clyde that looks something like this:.
Read more >
How to Direct Message (DM) on Twitter - Twitter Help Center
Direct Messages are the private side of Twitter. You can use Direct Messages to have private conversations with people about Tweets and other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found