5

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.

Ralph David Abernathy
  • 5,230
  • 11
  • 51
  • 78

1 Answers1

5

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.

Tomi S
  • 81
  • 4
  • Thank you for your answer. I just tried removing the params from the API call, but all that still outputs in the console is `[Function]` – Ralph David Abernathy Apr 11 '17 at 16:47
  • 1
    That is because you are trying to console log a function (`bot.api.users.list`) the same one that you are calling two lines above. Instead try logging `list` from the callback. – Tomi S Apr 11 '17 at 18:08
  • @TomiS I am trying to use bot.api.users.list((error, response) => { console.log(response); }) terminal showing its call but didn't get any response even bot.api.users.info is working fine, is there any mistake ? – Deepak Patidar Feb 28 '18 at 18:17
  • @DeepakPatidar try using this API call: bot.api.users.list({ }, (error, response) => { console.log(response) }) – Tomi S Feb 28 '18 at 19:03