Slack web-api 将未找到的频道 chat.postMessage 返回到私人频道

Slack web-api returning channel not found chat.postMessage to a private channel

我有以下代码,returns 我出现了以下错误。该错误表示找不到频道,但是我正在按照私人频道的文档使用频道名称或使用 url 中以 G 开头的字符串。我已经为频道的 bot 提供了正确的聊天写入权限,并且正在使用正确的 bot api 生成的 toekn,我之前能够通过 webhook post 但我想使用 web-api.

这是我指的文档https://api.slack.com/methods/chat.postMessage#channels

const { WebClient } = require('@slack/web-api');
const token = process.env.SLACK_BOT_TOKEN;
const web = new WebClient(token);

const conversationId = 'private-channel-name'; & tried this instead 'GCV2FGELX'

    const result = await web.chat.postMessage({
        text: 'Hello world!',
        channel: conversationId,
    });

这是我收到的错误响应

{
  code: 'slack_webapi_platform_error',
  data: {
    ok: false,
    error: 'channel_not_found',
    response_metadata: { scopes: [Array], acceptedScopes: [Array] }
  }
}

我不太确定我做错了什么,但做了一点挖掘,即使我尝试在此处 https://api.slack.com/methods/groups.list/test 使用带有身份验证令牌的测试器获取 groups.list 请求正确的权限我只是得到一个空的响应,而不是一组列表。 这里不确定。

我确实注意到它说 Post into any channel it has access to 机器人可以做什么我怎么知道机器人可以访问哪个频道。我已授予它对我的整个组织的写入权限?

任何帮助将不胜感激

我也遇到过同样的问题。

您是否尝试将 BOT/APP 添加到私人频道(您可以在频道详细信息 >> 更多 >> 添加应用程序下找到它。

将 BOT/APP 添加到频道后。您的消息将发布到频道中。

希望这能解决您的问题。