1stvamp / hippybot

Hipchat.com bot written in Python with a simple plugin API
Other
95 stars 42 forks source link

Use mention_name instead of name when sending a direct message #14

Closed pete0emerson closed 10 years ago

pete0emerson commented 10 years ago

A user can change their HipChat mention name by going into their web settings.

However, the current method of getting the name to send a direct message to is by manipulating the from field in the message:

In https://github.com/1stvamp/hippybot/blob/master/hippybot/decorators.py:

username = unicode(origin.getFrom()).split('/')[1].replace(" ","")

If the user has changed their mention name to something other than the concatenation of their first and last name, then hippybot direct messaging won't work as intended.

Via the HipChat API, it looks like you can pull the user's mention_name:

https://www.hipchat.com/docs/api/method/users/show

If the user has an API token configured, you could pull their mention_name via the HipChat API and then leverage it. Cache it, too, for bonus points!

it looks like you can pull all users at once via the HipChat API, so another way to solve would be to pull the list on bot startup and cache it. It misses some edge cases (new users or users that change their mention_name since the bot started up), but the list could be re-pulled on bot reload.

GET /v1/users/list?format=json&auth_token=token HTTP/1.1
Host: api.hipchat.com

Unfortunately, it looks like the HipChat API token has to be an admin token in order to pull the user list.