diff --git a/slack/web/__init__.py b/slack/web/__init__.py index e69de29bb..3631743b4 100644 --- a/slack/web/__init__.py +++ b/slack/web/__init__.py @@ -0,0 +1,28 @@ +import os +import warnings + +# https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api +deprecated_method_prefixes_2020_01 = ["channels.", "groups.", "im.", "mpim."] + + +def show_2020_01_deprecation(method_name: str): + skip_deprecation = os.environ.get( + "SLACKCLIENT_SKIP_DEPRECATION" + ) # for unit tests etc. + if skip_deprecation: + return + if not method_name: + return + + matched_prefixes = [ + prefix + for prefix in deprecated_method_prefixes_2020_01 + if method_name.startswith(prefix) + ] + if len(matched_prefixes) > 0: + message = ( + f"{method_name} is deprecated. Please use the Conversations API instead. " + "For more info, go to " + "https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api" + ) + warnings.warn(message) diff --git a/slack/web/base_client.py b/slack/web/base_client.py index 2b1201ec8..093a3b6b4 100644 --- a/slack/web/base_client.py +++ b/slack/web/base_client.py @@ -15,6 +15,7 @@ from aiohttp import FormData, BasicAuth # Internal Imports +from slack.web import show_2020_01_deprecation from slack.web.slack_response import SlackResponse import slack.version as ver import slack.errors as err @@ -170,6 +171,7 @@ def api_call( if self._event_loop is None: self._event_loop = self._get_event_loop() + show_2020_01_deprecation(api_method) future = asyncio.ensure_future( self._send(http_verb=http_verb, api_url=api_url, req_args=req_args), loop=self._event_loop, diff --git a/tests/web/test_web_client_coverage.py b/tests/web/test_web_client_coverage.py index 3802dfbb0..366cc65c6 100644 --- a/tests/web/test_web_client_coverage.py +++ b/tests/web/test_web_client_coverage.py @@ -1,4 +1,5 @@ # Standard Imports +import os import unittest # ThirdParty Imports @@ -17,6 +18,7 @@ class TestWebClientCoverage(unittest.TestCase): ) api_methods_to_call = [] + os.environ.setdefault("SLACKCLIENT_SKIP_DEPRECATION", "1") def setUp(self): self.loop = asyncio.new_event_loop()