forked from mattmakai/slack-starterbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_user_id.py
More file actions
28 lines (22 loc) · 854 Bytes
/
print_user_id.py
File metadata and controls
28 lines (22 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import os
import sys
from slackclient import SlackClient
if len(sys.argv) != 2:
print("User Name must be passed in as the only argument on the command line.")
exit()
slack_token = os.environ.get('SLACK_BOT_TOKEN')
if not slack_token:
print("Slack token environment variable is missing: SLACK_BOT_TOKEN")
exit()
user_name = sys.argv[1]
slack_client = SlackClient(slack_token)
if __name__ == "__main__":
api_call = slack_client.api_call("users.list")
if api_call.get('ok'):
# retrieve all users so we can find our bot
users = api_call.get('members')
for user in users:
if 'name' in user and user.get('name') == user_name:
print("User ID for [{}] is [{}]".format(user['name'], user.get('id')))
else:
print("Could not find user with the name: ".format(user_name))