Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of users from Slack API using BotKit?

Tags:

I'm trying to create a bot that sends a direct message to a random slack user. The first step I am trying to accomplish is console.logging the list of users.

Here is what I have so far:

controller.hears('marco', 'direct_message', function(bot, message) {
  bot.api.users.list({user: message.user}, function(err, list){
    bot.reply(message, "polo");
    console.log(bot.api.users.list);
  })
});

When I direct message the bot marco, it replies polo and [Function] is logged. How am able to log some real data? I tried bot.api.users.list.members, but it logs as undefined. Thank you.

like image 731
Ralph David Abernathy Avatar asked Mar 07 '17 17:03

Ralph David Abernathy


1 Answers

If you want to list ALL users, you are using a correct API call, just remove the params from it ({} instead of {user: message.user}). Docs: users.list

If you want to get information about a specific user from your team, you should use the following API call: bot.api.users.info({ user: USER_ID }, function (err, response) { ... }); Docs: users.info

There's also a test section in the Slack docs ('Tester' tab) so that you can try out what the API calls will return for your actual users.

like image 200
Tomi S Avatar answered Sep 21 '22 10:09

Tomi S