0

I am trying to create a new channel using slack api https://api.slack.com/methods/channels.join but getting this response

info: ** API CALL: https://slack.com/api/channels.join
Response :  { ok: false, error: 'user_is_bot' }

I tried this

controller.hears('hello', ['direct_message', 'direct_mention', 'mention'], function (bot, message) {
  bot.api.channels.join({'name':'nag'}, function (err, response) {
    console.log("Response : ",response);
  })
});

If I am mistaken please let me know. I have started learning slack api.

Nagarjuna Reddy
  • 4,083
  • 14
  • 41
  • 85

1 Answers1

5

The reason you are getting user_is_bot is that channels.join can not be used by a bot user. As it says in the documentation for this method:

user_is_bot: This method cannot be called by a bot user.

To create channel you will want to use channels.create. However, that method can also not be used by a bot user.

The common solution is to use the full access_token, not the bot_access_token that your Slack app received from Slack after installing it with OAuth for all methods that bot users can not use, e.g. creating a new channel.

Here is the example from the OAuth documentation on how the response from Slack with both tokens look like:

{
    "access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
    "scope": "incoming-webhook,commands,bot",
    "team_name": "Team Installing Your Hook",
    "team_id": "XXXXXXXXXX",
    "incoming_webhook": {
        "url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
        "channel": "#channel-it-will-post-to",
        "configuration_url": "https://teamname.slack.com/services/BXXXXX"
    },
    "bot":{
        "bot_user_id":"UTTTTTTTTTTR",
        "bot_access_token":"xoxb-XXXXXXXXXXXX-TTTTTTTTTTTTTT"
    }
}
Xavi
  • 20,111
  • 14
  • 72
  • 63
Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • In the mean time this has changed and bots are supposed to be able to join channels autonomously, but for some weird reason I can't get it to work. – Alper Mar 01 '20 at 19:15