hubot-rocketchat icon indicating copy to clipboard operation
hubot-rocketchat copied to clipboard

Get User Email Address From Script

Open richardwlu opened this issue 9 years ago • 5 comments

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?

richardwlu avatar Oct 30 '15 00:10 richardwlu

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.

timkinnane avatar Jun 23 '16 05:06 timkinnane

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.

geekgonecrazy avatar Jun 25 '16 03:06 geekgonecrazy

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.

timkinnane avatar May 07 '18 15:05 timkinnane

Please assign this to me.

ayushman075 avatar Dec 25 '23 14:12 ayushman075

Please assign this to me.

ayushman075 avatar Dec 25 '23 14:12 ayushman075