client/#75 - fixed thumbnail upload in Python2

This commit is contained in:
Petr Kalis 2021-06-09 18:03:09 +02:00
parent 53a0579cda
commit 80833c7b79

View file

@ -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)