diff options
author | Aidan Epstein <aidan@jmad.org> | 2019-11-06 18:37:54 -0800 |
---|---|---|
committer | Aidan Epstein <aidan@jmad.org> | 2020-02-18 14:48:34 -0800 |
commit | 2cfbd67f817f2dc3c48dfda51eb7bc81aa732ab2 (patch) | |
tree | a0eb04babc60f624b11c7b2f85c19b546e4b500e | |
parent | f7a36873147ac8f201d320b8c0b692437720a0cc (diff) | |
download | wee-slack-2cfbd67f817f2dc3c48dfda51eb7bc81aa732ab2.tar.gz |
Handle a couple more cases. Also add some debug output.
-rw-r--r-- | wee_slack.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/wee_slack.py b/wee_slack.py index 61a25a8..b969ef5 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3377,17 +3377,30 @@ def linkify_text(message, team, only_users=False): 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"])) + try: + if block["type"] == "section": + if "text" in block: block_text.append(block["text"]["text"]) + if "fields" in block: block_text += unfurl_texts(block["fields"]) + elif block["type"] == "actions": + block_text.append("|".join(i["text"]["text"] for i in block["elements"])) + elif block["type"] == "divider": + block_text.append("\n") + elif block["type"] == "context": + block_text.append("|".join(i["text"] for i in block["elements"])) + else: + block_text.append(json.dumps(block)) + except KeyError as e: + block_text.append(json.dumps(block) + repr(e)) return "\n".join(block_text) +def unfurl_texts(texts): + texts_ret = [] + for text in texts: + texts_ret.append(text["text"]) #TODO: markdown, etc. parse? + return texts_ret + + def unfurl_refs(text, ignore_alt_text=None, auto_link_display=None): """ input : <@U096Q7CQM|someuser> has joined the channel |