8

New to slack at the moment - I've looked around to see if there's a Slack command to show all online users in a Slack channel but haven't found any.

Would a custom slack command calling a Slack API method eg. users.getPresence be the way to go or is there another way?

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
essa
  • 83
  • 1
  • 1
  • 4

1 Answers1

6

Your best bet would be to first retrieve the list of members within the channel using the Web API method channels.info.

Each channel object will contain a members field containing a collection of user IDs -- those who have joined the channel.

You would then have two options depending on your preferences:

1) Use users.list to retrieve a list of all team members (including each user's presence) and narrow list of users down to those listed in the members field from above.

2) or, you could look up each user from that members field, one at a time using users.info.

Taylor Singletary
  • 2,211
  • 17
  • 16
  • can you tell, why `users.info` is needed? with `users.list` there is said to be include presence data too, and is not that enough? – T.Todua Aug 15 '17 at 14:07
  • 1
    On very large teams, requesting `users.list` with presence can result in slow or error responses. It's also recommended your app only concern itself with the info it needs to function: if you only need presence information for a limited set of users, looking them up atomically is best. – Taylor Singletary Aug 15 '17 at 16:39
  • @TaylorSingletary doesn't `members` give info of ACTIVE users only? why to compare with the list returned by `users.list`? – Volatil3 Dec 29 '17 at 11:04
  • @Volatil3 `members` will include all active channel members, yes, but the active status is actually unrelated to `presence`. – Taylor Singletary Jan 12 '18 at 00:01