Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get User Email Address From Script #64

Open
richardwlu opened this issue Oct 30, 2015 · 5 comments
Open

Get User Email Address From Script #64

richardwlu opened this issue Oct 30, 2015 · 5 comments

Comments

@richardwlu
Copy link

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?

@timkinnane
Copy link
Contributor

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.

@geekgonecrazy
Copy link
Contributor

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 geekgonecrazy changed the title Hubot Not Able To Get User Email Address From Script Get User Email Address From Script Aug 23, 2016
timkinnane added a commit that referenced this issue May 7, 2018
- Add sdk, api, methodCache and settings as properties
- Move all env setting loading to SDK
- Fixes #275
- Related #282, #64, #230, #250, #254
- Update docs
@timkinnane
Copy link
Contributor

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.

@ayushman075
Copy link

Please assign this to me.

1 similar comment
@ayushman075
Copy link

Please assign this to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants