From 80833c7b7918eecb721c9e141fa4d56883917a1f Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 9 Jun 2021 18:03:09 +0200 Subject: [PATCH] client/#75 - fixed thumbnail upload in Python2 --- .../plugins/publish/integrate_slack_api.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/openpype/modules/slack/plugins/publish/integrate_slack_api.py b/openpype/modules/slack/plugins/publish/integrate_slack_api.py index ce1511d8e3..d3f0f36140 100644 --- a/openpype/modules/slack/plugins/publish/integrate_slack_api.py +++ b/openpype/modules/slack/plugins/publish/integrate_slack_api.py @@ -83,19 +83,22 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin): from slackclient import SlackClient try: client = SlackClient(token) - if not published_path: + if published_path and os.path.exists(published_path): + with open(published_path, 'rb') as pf: + response = client.api_call( + "files.upload", + channels=channel, + initial_comment=message, + file=pf, + title=os.path.basename(published_path) + ) + else: response = client.api_call( "chat.postMessage", channel=channel, text=message ) - else: - response = client.api_call( - "files.upload", - channels=channel, - initial_comment=message, - file=published_path, - ) + if response.get("error"): error_str = self._enrich_error(str(response.get("error")), channel) @@ -110,17 +113,17 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin): from slack_sdk.errors import SlackApiError try: client = WebClient(token=token) - if not published_path: - _ = client.chat_postMessage( - channel=channel, - text=message - ) - else: + if published_path and os.path.exists(published_path): _ = client.files_upload( channels=channel, initial_comment=message, file=published_path, ) + else: + _ = client.chat_postMessage( + channel=channel, + text=message + ) except SlackApiError as e: # You will get a SlackApiError if "ok" is False error_str = self._enrich_error(str(e.response["error"]), channel)