松弛的WebAPI对话.unarchive失败,not_in_channel

时间:2020-08-11 15:08:02

标签: javascript slack slack-api

我的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)
    }
}

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

我联系了Slack,他们写信给我添加了用户令牌范围:channels:write 因此,在OAuth URL中添加:&user_scope=channels:write