Last active
August 29, 2015 14:05
-
-
Save sellorm/95b4fecf4fab821c4be3 to your computer and use it in GitHub Desktop.
A quick utility to map local email usernames to slack.com names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import simplejson as json | |
from urlgrabber import urlread | |
slackAPIToken = '<your API key here>' | |
emailDomain = '<your domain name here>' | |
try: | |
lookupName = sys.argv[1] | |
except: | |
print 'Usage: ' + sys.argv[0] + ': <user email to look up>' | |
quit(1) | |
usersList = urlread('https://slack.com/api/users.list?token=' + slackAPIToken + '&pretty=1') | |
ul = json.loads(usersList) | |
for i in range(len(ul['members'])): | |
if ul['members'][i]['profile']['email'] == lookupName + '@' + emailDomain: | |
print ul['members'][i]['name'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use this with slacks incoming webhooks to target messages.
Incoming messages should have the channel set to '@' and the user will receive the message from slackbot.
If you plan on sending lots of messages like this, you'd probably be better off keeping a complete copy of the users.list locally and running off that, then update the local copy periodically. This approach would keep you well away from the API rate limit and unless users change their slack names frequently (who does that?) there should be few issues running that way.