diff --git a/requirements.txt b/requirements.txt index f90342f..4bbaf02 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/src/util/slack_client.py b/src/util/slack_client.py index a742638..6d4fa55 100644 --- a/src/util/slack_client.py +++ b/src/util/slack_client.py @@ -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() @@ -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: @@ -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()