Search code examples
node.jsslackslack-apislack-commands

Slack bot posting in a conversation without being in it


Everything I see around slack bot say that a bot cannot post within a conversation it's not been invited to.
➡️ However, why /giphy or simple poll (/poll) can post in PM (one to one) OR in a conversation where the bot has not been added to?

  • The current permissions are chat:write,commands,files:write
  • The oauth token is a "Bot User OAuth Access Token"
  • The plan is to support the Add to slack and to distribute the app.

Functionality wise, it support a /command and post file to a conversation.

The bot can:
- receive the oauth token uppon app install (via add to slack)
- delete ephemeral messages
- post a file only where it's been added too, which suck because the bot does not need to read any message within anything.

Code of the bot here

If the bot is not invited too, the answer is either channel_not_found or not_in_channel.

What am I missing?


Solution

  • It is correct that bots in general can only post messages to channels they are invited to. However, there are two exceptions:

    1. Bots can inherit the rights of the installing user. So bots can post to every private channel the installing user is a member of (including direct message channels).

    2. Slash commands work differently. If a user issues a slash command from a channel the bot can reply to that slash command. That works for every channel and does not require the bot to be invited. Those replies are normal Slack messages, so the can contain all kind of message features incl. image attachments or blocks with images.

    A common pattern to give bot full access to private channels is the following:

    • User starts the bot with a slash command
    • Bot checks if it has full access to the current channel
    • If not it asks the user to invite it to that channel