最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why I receive {"ok":false,"error":"channel_not_found"} when I

programmeradmin2浏览0评论

Here is my code for setting topic channel and I receive {"ok":false,"error":"channel_not_found"} while the channel exists and I tried to use channelId instead of using #channelName . but no difference. And the permissions are set correct.

function setTopic1() {
var topic = 'testing'
  var url = '.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)
}`

Here is my code for setting topic channel and I receive {"ok":false,"error":"channel_not_found"} while the channel exists and I tried to use channelId instead of using #channelName . but no difference. And the permissions are set correct.

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)
}`
Share Improve this question edited Apr 30, 2020 at 11:27 Erik Kalkoken 32.7k8 gold badges94 silver badges127 bronze badges asked Apr 29, 2020 at 21:26 I.SI.S 2,0533 gold badges29 silver badges52 bronze badges 3
  • Is this for a public or private channel? – Erik Kalkoken Commented Apr 30, 2020 at 11:27
  • It's a public ,but I want to post it on private as well, but this one I tried on public one. – I.S Commented Apr 30, 2020 at 20:42
  • @ Erik Kalkoken Do you have any idea? – I.S Commented May 1, 2020 at 22:22
Add a comment  | 

4 Answers 4

Reset to default 9

Yeah you most likely need to add the bot to the channel. I did this by first going to a channel where I know the bot works already. I clicked on the bot, and clicked on add this app to a channel... and clicked on the new channel. Then it should work!

I found what was the issue. First as we integrate bot to channel ,I also needed to invite @channelName. And in payload it would be correct instead of using #channelName to channelID. It didn't work for me with channelName, it works with channelName when I posted message in channel but for set channel it works with channelId in payload

(Just adding my answer in case someone finds it helpful in the future)

Probably, you have not invited the bot to the channel yet. Go to the channel #temp-w, invite the bot to this channel and then try sending the http request.

Maybe it helps someone not to make the same mistake:

I added the bot while installing to a server. But that only adds the integration to the channel, additionally you need to add the bot (invite it) to the channel, it's not there automatically! :)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论