0

I am using the ruby HipChat Wrapper to send HipChat messages with a script. Before attempting to send any messages I would like to be able to check that the users I am attempting to message exist and are valid.

Is there a function in the HipChat::Client class that allows me to do this?

Note: I know that I can test if a user exists by attempting to send a message. If the script exits with a Access denied to user error then it is invalid. However I would like to test that a user exists without actually sending any messages.

Alex Cohen
  • 5,596
  • 16
  • 54
  • 104

1 Answers1

1

I'm not familiar with that client, however looking at the library you should be able to do something like this client.user('foo@bar.org').view (assuming API V2).

Have a look at user.rb#L57 which uses https://www.hipchat.com/docs/apiv2/method/view_user, that will probably give you back an error as well if the user does not exist (unsure). It's probably still better than sending the entire message before realising the user does not exist (alternatively you can also retrieve all users and check it against that).

Nabeel
  • 2,272
  • 1
  • 11
  • 14
  • Yep I actually just started working with the `view` function as a solution and it works quite well returning an `Unknown user:` error when the user does not exist. I was actually just about to answer my own question with this, but I guess you beat me to it lol. – Alex Cohen Sep 12 '16 at 00:02
  • Also to be able to use the view function I had to create a HipChat token with the following permissions `Send Message, Send Notification, View Group, View Messages, View Room` I'm pretty sure I would only need `Send Message,View Group` but I am not 100% sure on that. – Alex Cohen Sep 12 '16 at 00:04