From f7a36873147ac8f201d320b8c0b692437720a0cc Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Sun, 3 Nov 2019 08:41:39 -0800 Subject: Add initial implementation of slack blocks display. --- wee_slack.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 6eb725e..61a25a8 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2474,6 +2474,9 @@ class SlackMessage(object): else: text = "" + if "blocks" in self.message_json: + text += unfurl_blocks(self.message_json) + if self.message_json.get('mrkdwn', True): text = render_formatting(text) @@ -3371,6 +3374,20 @@ def linkify_text(message, team, only_users=False): return re.sub(linkify_regex, linkify_word, message_escaped, re.UNICODE) +def unfurl_blocks(message_json): + block_text = [] + for block in message_json["blocks"]: + if block["type"] == "section": + block_text.append(block["text"]["text"]) #TODO: markdown, etc. parse? + if block["type"] == "actions": + block_text.append("|".join(i["text"]["text"] for i in block["elements"])) + if block["type"] == "divider": + block_text.append("\n") + if block["type"] == "context": + block_text.append("|".join(i["text"] for i in block["elements"])) + return "\n".join(block_text) + + def unfurl_refs(text, ignore_alt_text=None, auto_link_display=None): """ input : <@U096Q7CQM|someuser> has joined the channel -- cgit