【问题标题】:Node-slack web api: chat.delete returns channel_not_found for all channels although channels.list returns all channelsNode-slack web api:chat.delete为所有频道返回channel_not_found,尽管channels.list返回所有频道
【发布时间】:2018-01-05 18:22:48
【问题描述】:

我一直在使用 slack-node web api 和 botkit 开发一个简单的聊天机器人,但在使用 chat.delete 功能时遇到了一些问题。我能够正确列出我的所有频道,查看他们的频道 ID 和名称,但是当我尝试使用 chat.delete 函数沿着消息频道发送时,它返回“channel_not_found”。

我还尝试发送频道名称,使用“general”和我所针对的实际频道名称进行测试,两者都返回相同的错误。

我的机器人正在使用管理员用户的令牌,这应该允许删除任何消息。我的 bot 也具有 chat:write:bot 和 chat:write:user 的范围访问权限。

下面是我的代码的 sn-p - 我也在其他地方尝试过删除直接从机器人发送的消息并得到相同的错误,所以我认为它与权限无关。我查看了文档,并且对于我下面的内容,用法似乎是正确的,但我可能遗漏了一部分。

controller.on('ambient', function(bot, message) {

      web.channels.list().then((res) => {
        console.log(res); // this prints out all of the channels
        // listed channels show a match for the channel ID given in message.channel
      });

      // this call returns an error "error: Response not OK:  channel_not_found"
      web.chat.delete(message.channel, message.ts).then((res) => {

         console.log(res + " was deleted bc it was not tagged");

      }).catch((err) => { console.log(err) });
});

【问题讨论】:

    标签: javascript node.js slack-api botkit


    【解决方案1】:

    文档对此有点混乱,但官方@slack/client 库的chat.delete 方法以不同的顺序获取参数:

    您需要将代码更改为:

    web.chat.delete(message.ts, message.chanel).then(...)
    

    看这里: https://slackapi.github.io/node-slack-sdk/reference/ChatFacet#ChatFacet+delete

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-11
      • 2020-02-28
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-06
      • 2019-11-10
      相关资源
      最近更新 更多