-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.py
35 lines (29 loc) · 901 Bytes
/
message.py
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
import os
from slackclient import SlackClient
SLACK_TOKEN = os.environ.get('SLACK_TOKEN')
slack_client = SlackClient(SLACK_TOKEN)
my_channel_id = 'C97L01PHN'
def list_channels():
channels_call = slack_client.api_call("channels.list")
if channels_call.get('ok'):
return channels_call['channels']
return None
def channel_info(channel_id):
channel_info = slack_client.api_call("channels.info", channel=channel_id)
if channel_info:
return channel_info['channel']
return None
def send_message(channel_id, message):
slack_client.api_call(
"chat.postMessage",
channel=channel_id,
text=message,
as_user=True
)
if __name__ == '__main__':
channels = list_channels()
if channels:
print("Authenticated")
send_message(my_channel_id, "HELLO , it works")
else:
print("Unable to authenticate.")