Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved from deprecated slack to slack_sdk. #118

Merged
merged 4 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ python-dateutil==2.8.0
qrcode[pil]==6.1
requests==2.21.0
pyserial==3.4
slackclient==2.5.0
ansicolors==1.1.8
pytest
flake8==5.0.4
slack_sdk==3.21.3
13 changes: 6 additions & 7 deletions src/util/slack_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from src.util.logger import get_logger
import slack
from asyncio import TimeoutError
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError, SlackClientError
import config
import socket
from src.util.token_config import TokenConfiguredClient, TokenExpiredError


logger = get_logger()

hostname = socket.gethostname()
Expand All @@ -16,7 +17,7 @@ class SlackTokenExpiredError(TokenExpiredError):

class SlackClient(TokenConfiguredClient):
def __init__(self, token_path, channel_id, timeout=1, token=None):
self.client = slack.WebClient(token, timeout=timeout)
self.client = WebClient(token, timeout=timeout)
self.token_path = token_path
self.channel_id = channel_id
if token:
Expand All @@ -36,11 +37,9 @@ def _post_message(self, msg):
link_names=True)
if not response['ok']:
logger.error(f'Slack error, response = {response}')
except TimeoutError:
logger.error("Slack request timed out.")
except slack.errors.SlackApiError as e:
except SlackApiError as e:
raise SlackTokenExpiredError(str(e))
except slack.errors.SlackClientError as e:
except SlackClientError as e:
logger.exception(f'Slack error, error = {e}')

@TokenConfiguredClient.require_configured_factory()
Expand Down