From 609704384bde4733770a7aaf4c499de5bbb92f59 Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Tue, 9 Jun 2020 20:52:47 +0900 Subject: [PATCH 1/2] Support thread_ts in uploads --- slackbot/slackclient.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/slackbot/slackclient.py b/slackbot/slackclient.py index fb8d5768..c48e5e28 100644 --- a/slackbot/slackclient.py +++ b/slackbot/slackclient.py @@ -124,19 +124,21 @@ def rtm_send_message(self, channel, message, attachments=None, thread_ts=None): } self.send_to_websocket(message_json) - def upload_file(self, channel, fname, fpath, comment): + def upload_file(self, channel, fname, fpath, comment, thread_ts=None): fname = fname or to_utf8(os.path.basename(fpath)) self.webapi.files.upload(fpath, channels=channel, filename=fname, - initial_comment=comment) + initial_comment=comment, + thread_ts=thread_ts) - def upload_content(self, channel, fname, content, comment): + def upload_content(self, channel, fname, content, comment, thread_ts=None): self.webapi.files.upload(None, channels=channel, content=content, filename=fname, - initial_comment=comment) + initial_comment=comment, + thread_ts=thread_ts) def send_message(self, channel, message, attachments=None, as_user=True, thread_ts=None): self.webapi.chat.post_message( @@ -193,18 +195,20 @@ def __eq__(self, compare_str): cid = self._body['id'] return name == compare_str or "#" + name == compare_str or cid == compare_str - def upload_file(self, fname, fpath, initial_comment=''): + def upload_file(self, fname, fpath, initial_comment='', thread_ts=None): self._client.upload_file( self._body['id'], to_utf8(fname), to_utf8(fpath), - to_utf8(initial_comment) + to_utf8(initial_comment), + thread_ts ) - def upload_content(self, fname, content, initial_comment=''): + def upload_content(self, fname, content, initial_comment='', thread_ts=None): self._client.upload_content( self._body['id'], to_utf8(fname), to_utf8(content), - to_utf8(initial_comment) + to_utf8(initial_comment), + thread_ts ) From 1a8c8043d1d8d05227d2ecfeb43ab539361ba81a Mon Sep 17 00:00:00 2001 From: Daisuke Taniwaki Date: Tue, 9 Jun 2020 22:48:29 +0900 Subject: [PATCH 2/2] Support filetype in uploads --- slackbot/slackclient.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/slackbot/slackclient.py b/slackbot/slackclient.py index c48e5e28..87eefb37 100644 --- a/slackbot/slackclient.py +++ b/slackbot/slackclient.py @@ -124,21 +124,23 @@ def rtm_send_message(self, channel, message, attachments=None, thread_ts=None): } self.send_to_websocket(message_json) - def upload_file(self, channel, fname, fpath, comment, thread_ts=None): + def upload_file(self, channel, fname, fpath, comment, thread_ts=None, filetype=None): fname = fname or to_utf8(os.path.basename(fpath)) self.webapi.files.upload(fpath, channels=channel, filename=fname, initial_comment=comment, - thread_ts=thread_ts) + thread_ts=thread_ts, + filetype=filetype) - def upload_content(self, channel, fname, content, comment, thread_ts=None): + def upload_content(self, channel, fname, content, comment, thread_ts=None, filetype=None): self.webapi.files.upload(None, channels=channel, content=content, filename=fname, initial_comment=comment, - thread_ts=thread_ts) + thread_ts=thread_ts, + filetype=filetype) def send_message(self, channel, message, attachments=None, as_user=True, thread_ts=None): self.webapi.chat.post_message( @@ -195,20 +197,22 @@ def __eq__(self, compare_str): cid = self._body['id'] return name == compare_str or "#" + name == compare_str or cid == compare_str - def upload_file(self, fname, fpath, initial_comment='', thread_ts=None): + def upload_file(self, fname, fpath, initial_comment='', thread_ts=None, filetype=None): self._client.upload_file( self._body['id'], to_utf8(fname), to_utf8(fpath), to_utf8(initial_comment), - thread_ts + thread_ts, + filetype ) - def upload_content(self, fname, content, initial_comment='', thread_ts=None): + def upload_content(self, fname, content, initial_comment='', thread_ts=None, filetype=None): self._client.upload_content( self._body['id'], to_utf8(fname), to_utf8(content), to_utf8(initial_comment), - thread_ts + thread_ts, + filetype )