Slack WebAPI conversations.unarchive 失败 not_in_channel

Slack WebAPI conversations.unarchive fails with not_in_channel

我的 slack 应用正在侦听 channel_archived 事件,因此它可以检查是否存档了一个非常重要的 slack 频道:

app.event('channel_archive', async ({ event, context }) => {  
    if (event.channel === redacted) {
        fns.textOutput(event.user, "Hello <@"+event.user+"> I noticed you archived the redacted channel. This channel is used by thousands of redacted for slack training.\n"+
        "I have un-archived it so no need to worry, just please be more careful about what you are archiving")
        unArchiveChannel()
    } 
});

所有这些都有效,它调用了 unArchiveChannel() 函数,可以在这里看到:

async function unArchiveChannel() {
    try {
        const result = await app.client.conversations.unarchive({
        // Bot token
        token: process.env.SLACK_BOT_TOKEN,
        // Channel to unarchive
        channel: redacted,
        })
        console.log(result)
    }
    catch (error) {
        console.log(error)
    }
}

我的机器人令牌具有所有正确的范围:channels:manage、groups:write、im:write 和 mpim:write。我用 /invite @(my bots username) 邀请它加入频道。但是,当我实际存档有问题的频道时,我的函数被调用但它给了我错误 not_in_channel 并且它无法取消存档频道。错误未列出 in the documentation 所以我迷路了。

我联系了 Slack 的帮助中心,他们给我回了邮件,告诉我他们的文档中有错误。您不能使用机器人令牌来授权 conversations.unarchive 方法。

我联系了 Slack,他们写信让我添加用户令牌范围:channels:write 所以在 OAuth URL 添加:&user_scope=channels:write