【问题标题】:slack bot error: 'user_is_bot' for channels.join松弛机器人错误:channels.join 的“user_is_bot”
【发布时间】:2017-01-16 09:47:07
【问题描述】:

我正在尝试使用 slack api https://api.slack.com/methods/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);
  })
});

如果我弄错了,请告诉我。我已经开始学习slack api了。

【问题讨论】:

    标签: slack-api botkit


    【解决方案1】:

    你得到user_is_bot 的原因是channels.join 不能被机器人用户使用。正如它在此方法的文档中所说:

    user_is_bot: bot 用户无法调用此方法。

    要创建频道,您需要使用channels.create。但是,bot 用户也不能使用该方法。

    常见的解决方案是使用完整的access_token,而不是使用 OAuth 安装 Slack 应用程序后从 Slack 收到的 bot_access_token,用于机器人用户无法使用的所有方法,例如创建一个新频道。

    这是来自 OAuth documentation 的示例,说明 Slack 使用两个令牌的响应如下所示:

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

    【讨论】:

    • 与此同时,这种情况发生了变化,机器人应该能够自主加入频道,但由于某些奇怪的原因,我无法让它工作。
    猜你喜欢
    • 2017-03-20
    • 1970-01-01
    • 2016-10-27
    • 1970-01-01
    • 2018-07-17
    • 1970-01-01
    • 2018-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多