I'm curious if there is an easy way with this framework to get a list of all the users in the channel. I would be using this list to see if a user-typed handle is a valid user in the channel. Is there something like the channels.list in the native Slack API?
Thanks in advance for your help!
@musicaljoeker I think this has yet to be implemented. Though sounds like an interesting endeavour so I might try to tackle it on my own
You can use almost all Slack API Methods from the bot object. Here is some info in Botkit docs,
You can get a list of members of a channel by calling the following and finding the members array in the channel object you will get back.
bot.api.channels.info('CHANNEL_ID', function(err, response) {})
I'm having some issues getting the response right, and I'm not sure I'm calling this the proper way.
Here is what I have:
bot.api.channels.info(channel, function(err, response) {
bot.reply(message, "ChannelID: " + channel + "\n" +
"Response: " + JSON.stringify(response));
});
What I'm getting back is a JSON object saying that the error is invalid_form_data. Does the first parameter in the bot.api.channels.info need to be a string or an object? I see you have it listed as a string above, but in the documentation I see a blank object. Or perhaps I'm doing something else wrong?
Your assistance is much appreciated!
Oops! You need to pass it a key value pair in an object.
controller.hears('test', 'direct_mention', function(bot, message) {
bot.api.channels.info({channel: message.channel}, function(err, res) {
if (err) console.log('ERR:',err)
else console.log('============CHANNELS LIST INFO:\n', res)
})
})
This will give you back a channel object that has an array contain user ID's of the channel members. I think if you look in dev4slack there have been some people who have asked similar questions to matching usernames with ID's.
If you aren't a part of the slack team sign up here
@musicaljoeker Checkout PR #367
Haven't used this myself, and it isn't complete, but is a place to start for you perhaps.
Thank you for providing that code above. That supplied exactly what I needed and solved my problem.