11import json
22import logging
33import os
4+ from pydoc import cli
45
5- from slackclient import SlackClient
6+ from slack_sdk import WebClient
67
78logger = logging .getLogger ()
89logger .setLevel (logging .INFO )
910
10- sc = SlackClient (os .getenv ("SLACK_TOKEN" ))
11- sc_bot = SlackClient (os .getenv ("SLACK_BOT_TOKEN" ))
11+ slack_bot_token = os .getenv ("SLACK_BOT_TOKEN" )
12+ client = WebClient (token = slack_bot_token )
13+
1214SLACK_CHANNEL = os .getenv ("SLACK_CHANNEL" , "deployments" )
1315SLACK_BOT_NAME = os .getenv ("SLACK_BOT_NAME" , "BuildBot" )
1416SLACK_BOT_ICON = os .getenv ("SLACK_BOT_ICON" , ":robot_face:" )
@@ -20,7 +22,7 @@ def find_channel(name):
2022 if name in CHANNEL_CACHE :
2123 return CHANNEL_CACHE [name ]
2224
23- r = sc . api_call ( "conversations.list" , exclude_archived = 1 )
25+ r = client . conversations_list ( exclude_archived = 1 )
2426 if 'error' in r :
2527 print ("conversations.list" )
2628 logger .error ("error: {}" .format (r ['error' ]))
@@ -34,7 +36,7 @@ def find_channel(name):
3436
3537
3638def find_msg (ch ):
37- return sc . api_call ( 'conversations.history' , channel = ch )
39+ return client . conversations_history ( channel = ch )
3840
3941
4042def find_my_messages (ch_name , user_name = SLACK_BOT_NAME ):
@@ -95,21 +97,15 @@ def post_build_msg(msgBuilder):
9597
9698
9799def send_msg (ch , attachments ):
98- r = sc_bot .api_call ("chat.postMessage" ,
99- channel = ch ,
100- icon_emoji = SLACK_BOT_ICON ,
101- username = SLACK_BOT_NAME ,
102- attachments = attachments
103- )
100+ r = client .chat_postMessage (channel = ch ,
101+ icon_emoji = SLACK_BOT_ICON ,
102+ username = SLACK_BOT_NAME ,
103+ attachments = attachments )
104104 return r
105105
106106
107107def update_msg (ch , ts , attachments ):
108- r = sc_bot .api_call ('chat.update' ,
109- channel = ch ,
110- ts = ts ,
111- icon_emoji = SLACK_BOT_ICON ,
112- username = SLACK_BOT_NAME ,
113- attachments = attachments
114- )
108+ r = client .chat_update (channel = ch ,
109+ ts = ts ,
110+ attachments = attachments )
115111 return r
0 commit comments