Skip to content

Instantly share code, notes, and snippets.

@sellorm
Last active August 29, 2015 14:05
Show Gist options
  • Save sellorm/95b4fecf4fab821c4be3 to your computer and use it in GitHub Desktop.
Save sellorm/95b4fecf4fab821c4be3 to your computer and use it in GitHub Desktop.
A quick utility to map local email usernames to slack.com names
#!/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']
@sellorm
Copy link
Author

sellorm commented Aug 29, 2014

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.

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