0

I am using simple template of slack bot RTM API, that is given at https://github.com/slackapi/node-slack-sdk

var RtmClient = require('@slack/client').RtmClient;
var CLIENT_EVENTS = require('@slack/client').CLIENT_EVENTS;
var bot_token = process.env.SLACK_BOT_TOKEN || '';
var rtm = new RtmClient(bot_token);

The question is how to fetch the channels name?

I found that I should use channel.list which is compatible with WEB API.

But how to call WEB API when I am using RTM API? And, in general, why all these so overcomplicated?

polypiel
  • 2,321
  • 1
  • 19
  • 27
com
  • 2,606
  • 6
  • 29
  • 44

1 Answers1

2

How about following sample? Please import your access token, when you use this.

Sample :

var WebClient = require('@slack/client').WebClient;
var web = new WebClient('## your access token ##');
web.channels.list(function(err, info) {
  if (err) {
    console.log(err);
  } else {
    for(var i in info.channels) {
      console.log("%s", info.channels[i].name, info.channels[i].id);
    }
  }
});

Result :

channelName1 channelID1
channelName2 channelID2
channelName3 channelID3

If I misunderstand your question, I'm sorry.

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • This is exactly what I am looking for. Thank you! – com May 12 '17 at 01:19
  • By the way, where did you find this sample? – com May 12 '17 at 01:19
  • 1
    Thank you, too. You can find some samples here. https://github.com/slackapi/node-slack-sdk/blob/0c1d59d6904528e31fbdd0fac49c1dd86ab19cb3/docs/_pages/basic_usage.md – Tanaike May 12 '17 at 02:09