2017-01-16 74 views
0

我试图用松弛API https://api.slack.com/methods/channels.join但得到这种反应松弛机器人错误:“user_is_bot”的channels.join

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

创建一个新的渠道我想这

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

如果我错误请让我知道。我已经开始学习松散的API了。

回答

2

您得到user_is_bot的原因是channels.join不能被bot用户使用。正如这个方法的文档中说:

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

要建立频道,你将要使用channels.create。但是,该方法也不能被bot用户使用。

常见的解决办法是使用全access_token,而不是从松弛收到您的时差应用使用OAuth安装它为机器人的用户不能使用所有方法之后bot_access_token,例如创造一个新的渠道。

下面是从OAuth documentation从松弛与两个标记响应什么样子的例子:

{ 
    "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" 
    } 
}