Compare commits

..

No commits in common. "407cbddae31095acbccebd9e7ba77fe3604812eb" and "ec1bfefbb908136e050b0d1b4c058721c04abfb6" have entirely different histories.

View File

@ -20,41 +20,38 @@ More information is on [Github](https://github.com/moan0s/alertbot)
def convert_slack_webhook_to_markdown(data):
# Error Handling: Check if data is a dictionary
if not isinstance(data, dict):
return ["Input data must be a dictionary"]
markdown_parts = []
markdown_message = ""
attachment_titles = []
if "text" in data:
markdown_parts.append(f"{data['text']}")
markdown_message += f"{data['text']}\n"
if "attachments" in data:
for attach in data["attachments"]:
attachment_md = "> "
if "title" in attach:
attachment_titles.append(attach['title'])
title_md = f"## {attach['title']}" if "title_link" not in attach else f"[{attach['title']}]({attach['title_link']})"
markdown_parts.append(f"> {title_md}")
for key in ["text", "image_url"]:
if key in attach and attach[key] is not None:
extra_md = attach[key] if key == "text" else f"![Image]({attach[key]})"
markdown_parts.append(f"> {extra_md}")
if "title" in attach and "title_link" in attach:
attachment_md += f"[{attach['title']}]({attach['title_link']})\n> "
elif "title" in attach:
attachment_md += f"## {attach['title']}\n> "
if "text" in attach:
attachment_md += f"{attach['text']}\n> "
if "image_url" in attach and attach["image_url"] is not None:
attachment_md += f"![Image]({attach['image_url']})\n> "
if 'fields' in attach:
field_parts = [f"- **{field['title']}** : {field['value']}" for field in attach['fields']]
markdown_parts.extend([f"> {part}" for part in field_parts])
for field in attach['fields']:
attachment_md += f"- **{field['title']}** : {field['value']}\n> "
markdown_message += attachment_md + "\n"
if "sections" in data:
markdown_parts.append("")
for section in data["sections"]:
if "activityTitle" in section and section['activityTitle'] not in attachment_titles:
markdown_parts.append(f"## {section['activityTitle']}")
markdown_message += f"## {section['activityTitle']}\n"
if "activitySubtitle" in section:
markdown_parts.append(section['activitySubtitle'])
markdown_message += f"{section['activitySubtitle']}\n"
return ['\n'.join(markdown_parts)]
return [markdown_message]
def get_alert_type(data):