aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorJustin Kenyon <kenyonj@gmail.com>2015-09-18 16:09:15 -0400
committerJustin Kenyon <kenyonj@gmail.com>2015-11-03 09:37:05 -0500
commitc79e62cc8f2579fee4f7345dd5b79617d3a5eb6b (patch)
treebc0097b8357d9032b27bd9f207dfb5a6ca0e5db2 /wee_slack.py
parent9e25dbdfb3ccdd0c3975ecff9c9f3d947b700844 (diff)
downloadwee-slack-c79e62cc8f2579fee4f7345dd5b79617d3a5eb6b.tar.gz
Add upload capability to slack buffer
This commit: - Adds the ability to upload a file to the current slack buffer using the `/slack upload [file_path]` command Why? - This is a very useful feature for people that are trying to fully replace the slack web app
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index c789b43..4b334c0 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -4,6 +4,7 @@
from functools import wraps
import time
import json
+import os
import pickle
import sha
import re
@@ -902,6 +903,26 @@ def slack_buffer_required(f):
@slack_buffer_required
+def command_upload(current_buffer, args):
+ """
+ Uploads a file to the current buffer
+ /slack upload [file_path]
+ """
+ post_data = {}
+ channel = current_buffer_name(short=True)
+ domain = current_domain_name()
+ token = servers.find(domain).token
+
+ if servers.find(domain).channels.find(channel):
+ channel_identifier = servers.find(domain).channels.find(channel).identifier
+
+ if channel_identifier:
+ post_data["token"] = token
+ post_data["channels"] = channel_identifier
+ post_data["file"] = args
+ async_slack_api_upload_request(token, "files.upload", post_data)
+
+@slack_buffer_required
def command_talk(current_buffer, args):
"""
Open a chat with the specified user
@@ -1719,6 +1740,14 @@ def async_slack_api_request(domain, token, request, post_data, priority=False):
dbg("URL: {} context: {} params: {}".format(url, context, params))
w.hook_process_hashtable(url, params, 20000, "url_processor_cb", context)
+def async_slack_api_upload_request(token, request, post_data, priority=False):
+ if not STOP_TALKING_TO_SLACK:
+ url = 'https://slack.com/api/{}'.format(request)
+ file_path = os.path.expanduser(post_data["file"])
+ command = 'curl -F file=@{} -F channels={} -F token={} {}'.format(file_path, post_data["channels"], token, url)
+ context = pickle.dumps({"request": request, "token": token, "post_data": post_data})
+ w.hook_process(command, 20000, "url_processor_cb", context)
+
# funny, right?
big_data = {}