为什么我在 slack 中设置主题时收到 {"ok":false,"error":"channel_not_found"}?

Why I receive {"ok":false,"error":"channel_not_found"} when I am setting topic in slack?

这是我设置主题频道的代码,我收到了 {"ok":false,"error":"channel_not_found"} 当频道存在时,我尝试使用 channelId 而不是使用 #channelName 。但没有区别。并且权限设置正确。

function setTopic1() {
var topic = 'testing'
  var url = 'https://xxxx.slack.com/api/conversations.setTopic'
  var payload = {
    'channel': '#temp-w',
    'token': token,
    'topic': topic,
  };

  var options = {
    'method': 'post',
    'payload': payload,
  };

  if (topic.length > 250) {
    Logger.log("Topic is too long, API request might fail")
  }
  var response = UrlFetchApp.fetch(url,options);
  Logger.log(response)
}`

我发现了问题所在。 首先,当我们将机器人集成到频道时,我还需要邀请@channelName。 并且在有效载荷中它是正确的而不是使用#channelName 到 channelID。 它不适用于 channelName,当我在频道中发布消息时它适用于 channelName 但对于设置频道它适用于 payload

中的 channelId

(只是添加我的答案以防将来有人觉得有用)

可能您还没有邀请机器人加入频道。转到频道 #temp-w,邀请机器人加入此频道,然后尝试发送 http 请求。

是的,您很可能需要将机器人添加到频道。为此,我先去了一个我知道该机器人已经在运行的频道。我点击了机器人,然后点击了 add this app to a channel... 并点击了新频道。那么它应该可以工作了!