-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslackapi.py
More file actions
40 lines (27 loc) · 1.24 KB
/
slackapi.py
File metadata and controls
40 lines (27 loc) · 1.24 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
#slack api calls
from slackclient import SlackClient
import json
# create an instance of the api client and initialize it with a token
def init(token, privtoken):
global api_client
global priv_client
api_client = SlackClient(token)
priv_client = SlackClient(privtoken)
return api_client
def getFullname(userid):
return json.loads(api_client.api_call('users.info', user=userid))['user']['profile']['real_name']
def getUsername(userid):
return json.loads(api_client.api_call('users.info', user=userid))['user']['name']
def sendRR(input):
priv_client.api_call('chat.postMessage', channel='#announcements', text=input, as_user=False, username='torpbot', icon_emoji=':torpedo:')
def sendPM(input, userid):
api_client.api_call('chat.postMessage', channel="@"+getUsername(userid), text=input, as_user=True)
def sendToChannel(input, channel):
api_client.api_call('chat.postMessage', channel=channel, text=input, as_user=True)
def sendMessage():
api_client.api_call('chat.postMessage', channel='#Testing', text='<http://google.com|test>', as_user=True)
def userInChannel(channel, user):
channelInfo = json.loads(api_client.api_call('groups.info', channel=channel))
if user in channelInfo['group']['members']:
return True
return False