Skip to content

Commit

Permalink
Add support for button block in slack msgs (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-fr authored Jan 21, 2025
1 parent efcbc62 commit d9783d3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions slackviewer/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,30 @@ def _generate_blocks_text(self, blocks):
def _format_block_type(self, text_obj, b_type):
"""Format the text based on the block type"""
if "text" not in text_obj:
logging.warning(f"Missing 'text' in {text_obj}")
return ""
logging.warning(f"Block Type {b_type}: Missing 'text' in {text_obj}")
return "unsupported_block({b_type}: {text_obj})\n\n"

text = text_obj["text"]

if "type" in text_obj and text_obj["type"] not in ["plain_text", "mrkdwn"]:
logging.warning(f"Unsupported text type {text_obj['text_type']} for {text_obj}")
return f"{text}\n\n"
if "type" in text_obj and text_obj["type"] not in ["plain_text", "mrkdwn", "button"]:
logging.warning(f"Block Type {b_type}: Unsupported text type '{text_obj['type']}' for {text_obj}")
return f"unsupported_block({b_type}: {text})\n\n"

if "type" in text_obj and text_obj["type"] == "button":
if "text" in text_obj['text']:
text = f"Slack_Button({text['text']})"

if b_type == "header":
return f"*{text}*\n\n"
elif b_type == "section":
return f"{text}\n\n"
elif b_type == "context":
return f"<small>{text}</small>\n"
elif b_type == "actions":
return f"Slack_Action({text})\n"
else:
logging.warning(f"Unsupported block type {b_type} for {text_obj}")
return f"{text}\n\n"
logging.warning(f"Unsupported block type '{b_type}' for {text_obj}")
return f"unsupported_block({b_type}: {text_obj}\n\n)"

def user_message(self, user_id):
return {"user": user_id}
Expand Down

0 comments on commit d9783d3

Please sign in to comment.