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
4 Answers
Reset to default 9Yeah 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! :)