diff options
author | Aidan Epstein <aidan@jmad.org> | 2019-11-03 08:41:39 -0800 |
---|---|---|
committer | Aidan Epstein <aidan@jmad.org> | 2020-02-18 14:48:34 -0800 |
commit | f7a36873147ac8f201d320b8c0b692437720a0cc (patch) | |
tree | 97814befe71bebae26246720d93d5f9f9f149061 /wee_slack.py | |
parent | 958296fb6c3a17db85cbdcf44bf35647c51aaccd (diff) | |
download | wee-slack-f7a36873147ac8f201d320b8c0b692437720a0cc.tar.gz |
Add initial implementation of slack blocks display.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 17 |
1 files changed, 17 insertions, 0 deletions
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 |