Slackbot: how to use the slack channel functions

Multi tool use
Multi tool use


Slackbot: how to use the slack channel functions



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(...)


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.


channel.leave



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


channel.leave





This method is used to leave a channel. thats what you want?!
– Jonas W.
Jul 2 at 7:07


This method is used to leave a channel.




1 Answer
1



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.





Can you show me a code example?
– L1ghtk3ira
Jul 2 at 23:07





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 2 at 23:21


https://slack.com/api/users.list?token=TOKEN






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Ly gw2TPyX FnJ3R 7PUH
rkrjRHIxc,eU9 diwctC stoRvEJVVLWvDX6,3,mO5D32V P6BSswbFSkWAxQvU3Rh9R T11IlN,RTI

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications