0

I create a slackbot fusing the following from this guide:

var util = require('util');
var path = require('path');
var fs = require('fs');
var SQLite = require('sqlite3').verbose();
var Bot = require('slackbots');

The slackbot I created is basic by replying to keywords and posting messages back in the channel using: this.postMessageToChannel(...)

What I would like is to use functions I see from the slack API such as the ability for the slackbot to leave a channel by itself. The channel.leave function found here in the slack API looks to be able to do this however I am not sure how to get it to work.

How am I able to use this Slack api correctly? Specifically starting with the channel.leave method?

L1ghtk3ira
  • 3,021
  • 6
  • 31
  • 70

1 Answers1

2

To use any of Slack's API method you need a token. If you followed the instruction from the link you provided you can get your token from the page of installed apps, where you also find your bot.

If will look like this:

enter image description here

Just take the "API Token" and use it in your code to call any of the web methods. If you are unsure how to make an API call in node.js, check out this question.

There is one caveat to your specific problem though. This particular method does not work with a bot token (which is what you got), only with a user token. I don't think it is possible for a bot to leave a channel by itself. Only a real user can do that.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • Just use the example I linked to make a call to an API method. Its really simple. You can also just put it into a browser for testing, e.g. `https://slack.com/api/users.list?token=TOKEN` – Erik Kalkoken Jul 02 '18 at 23:21