missing_scope 尝试使用机器人令牌获取频道历史记录时出错

missing_scope error when trying to fetch channel history with bot token

使用 Slacks Bolt 框架执行以下操作时:

app.client.conversations.history({
      token: token,
      channel: channelId,
      latest: messageId,
      count: 1
    })

我得到 Error: An API error occurred: missing_scope

我正在传递一个 Bot 令牌(支持指示的文档 https://api.slack.com/methods/conversations.history)并且已经将 channels.historychannels.read 范围添加到我的 oAuth 和权限范围,所以我'我有点烂

有人遇到过这个吗?

如果您想使用 conversations.history 从 public 频道提取消息,您的机器人令牌将不起作用。它只有 build-in 个直接消息通道的范围,无法添加范围。

来自API documentation page

Bot user tokens may use this method for direct message and multi-party direct message conversations but lack sufficient permissions to use this method on public and private channels.

来自bot token documentation page

Bot user tokens can't have resource-based OAuth scopes added to them, any scopes other than bot requested during the OAuth installation flow have no effect on the bot user token

所以解决方案是使用具有所需范围的 Oauth 访问令牌,也就是用户令牌。