I have been working on a simple chat bot using the slack-node web api and botkit, but am having some trouble using the chat.delete functionality. I am able to list out all of my channels properly, seeing their channel Id's and names, but when I try to send along the message channel with the chat.delete function, it returns "channel_not_found".
I have also tried to send along the channel name, testing with "general" and the actual channel name that I am targeting, both of which return the same error.
My bot is using a token of the admin user, which should allow deletion of any message. My bot has scope access for chat:write:bot and chat:write:user as well.
Below is a snippet of my code - I have also tried this in other places for deleting messages sent directly from the bot and get the same error, so I don't believe it has to do with permissions. I've looked into the docs and the usage seems to be correct for what I have below, but I may be missing a piece.
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) });
});
The docs are a bit confusing on this, but the chat.delete method of the official @slack/client library take the parameters in a different order:
You'll want to change your code to be:
web.chat.delete(message.ts, message.chanel).then(...)
See here: https://slackapi.github.io/node-slack-sdk/reference/ChatFacet#ChatFacet+delete