Skip to content

Commit e8c4bfd

Browse files
Merge pull request #1 from danyhoron/features/update-slack-sdk
refactor: replace slackclient with slack_sdk
2 parents e6e4861 + ddb4aeb commit e8c4bfd

File tree

4 files changed

+16
-25
lines changed

4 files changed

+16
-25
lines changed

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ verify_ssl = true
66
[dev-packages]
77

88
[packages]
9-
slackclient = "==1.3.1"
9+
slack_sdk = "*"
1010
aws-cli = "*"
1111

1212
[requires]

src/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
slackclient==1.3.1
1+
slack_sdk==3.15.2

src/slack_helper.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import json
22
import logging
33
import os
4+
from pydoc import cli
45

5-
from slackclient import SlackClient
6+
from slack_sdk import WebClient
67

78
logger = logging.getLogger()
89
logger.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+
1214
SLACK_CHANNEL = os.getenv("SLACK_CHANNEL", "deployments")
1315
SLACK_BOT_NAME = os.getenv("SLACK_BOT_NAME", "BuildBot")
1416
SLACK_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

3638
def find_msg(ch):
37-
return sc.api_call('conversations.history', channel=ch)
39+
return client.conversations_history(channel=ch)
3840

3941

4042
def find_my_messages(ch_name, user_name=SLACK_BOT_NAME):
@@ -95,21 +97,15 @@ def post_build_msg(msgBuilder):
9597

9698

9799
def 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

107107
def 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

template.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ Transform: AWS::Serverless-2016-10-31
33
Description: Code Pipeline Slack Notifier
44

55
Parameters:
6-
SlackOAuthAccessToken:
7-
MinLength: 1
8-
Type: String
9-
NoEcho: True
106
SlackBotUserOAuthAccessToken:
117
MinLength: 1
128
Type: String
@@ -36,7 +32,6 @@ Resources:
3632
ReservedConcurrentExecutions: 1
3733
Environment:
3834
Variables:
39-
SLACK_TOKEN: !Ref SlackOAuthAccessToken
4035
SLACK_BOT_TOKEN: !Ref SlackBotUserOAuthAccessToken
4136
SLACK_BOT_NAME: !Ref SlackBotName
4237
SLACK_BOT_ICON: !Ref SlackBotIcon

0 commit comments

Comments
 (0)