hubot-rocketchat
hubot-rocketchat copied to clipboard
Get User Email Address From Script
Are we able to get the user``email address
while in the script? So far, I can see in the message
object we have:
message:
{ user:
{ id: 'ozCSNcrfcNJb2b7',
name: 'johndoe',
room: 'h7PdcWSubYw2zQy' },
text: '@R2Z2: get circuit 61011',
id: 'jMSMw4WtzvGQs9b',
done: false,
room: 'h7PdcWSubYw2zQy' },
match:
[ '@R2Z2: get circuit 61011',
'61011',
index: 0,
input: '@R2Z2: get circuit 61011' ],
envelope:
{ room: 'h7PdcWSubYw2zQy',
user:
{ id: 'ozCSNcrfcNJb2b7',
name: 'johndoe',
room: 'h7PdcWSubYw2zQy' },
message:
{ user: [Object],
text: '@R2Z2: get circuit 61011',
id: 'jMSMw4WtzvGQs9b',
done: false,
room: 'h7PdcWSubYw2zQy' } } }
I can get the User
name
but now wondering if there is a way to pull the email address either from rocket.chat or the LDAP instance using the name
?
Hi again @richardwlu, as with my response to your comment on #136. Rocket-chat-bot-helpers is a package you can add manually (its not part of core or published to Meteor yet), that will give you methods to run a user query, which includes returning their email array.
There's been discussion of adding these methods to the adapter, but I don't actually think its possible at this point.
You would just need the appropriate meteor command to live in rocket.chat with the bot having the appropriate permission to view the users details and you would be able to get via: robot.adapter.callMethod('method_name', 'username')
Feel free to take a poke around the methods, and open a pull request on the Rocket.Chat project to add those. Just a forewarning... You'll need to make sure the method checks to see if a user has permission to see the information.
This can be done in the latest (pre-release) adapter, using the SDK's new API client to get additional data not provided in the message object - depending on the bot user's permissions. e.g...
module.exports = (robot) => {
robot.hear(/test/i, (res) => {
const userId = res.message.user.id
robot.adapter.api.get('users.info', { userId }).then((result) => {
if (result.success) {
const user = result.user
res.reply(`Hello ${user.name} - I can get all this info about you:`)
res.reply(`[${Object.keys(user).join(', ')}]`)
} else {
res.reply(`Hmm, couldn't get any info on you :shrug:`)
}
})
})
}
See API docs for full details: https://rocket.chat/docs/developer-guides/rest-api/users/info/
Please test the pre release, by adding it to your package.json
with the repo address instead of the npm version. e.g. "hubot-rocketchat": "rocketchat/hubot-rocketchat"
We'll update the version published to NPM as soon as we have more feedback that its stable.
Please assign this to me.
Please assign this to me.