Slack WebAPI 对话。取消存档因 not_in_channel 失败

Ril*_*ton 0 javascript slack-api slack

我的 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()
    } 
});
Run Code Online (Sandbox Code Playgroud)

所有这些都有效,它调用了 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)
    }
}
Run Code Online (Sandbox Code Playgroud)

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

Ril*_*ton 7

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