handle duplicates, messages, beautiful format

This commit is contained in:
Alexis Yushin 2023-07-25 13:59:10 +02:00
parent aa761ca90d
commit cbc0e16caf

View File

@ -24,28 +24,32 @@ def convert_slack_webhook_to_markdown(data):
attachment_titles = [] attachment_titles = []
if "text" in data: if "text" in data:
markdown_message += f"*{data['text']}*\n" markdown_message += f"{data['text']}\n"
if "attachments" in data: if "attachments" in data:
for attach in data["attachments"]: for attach in data["attachments"]:
attachment_md = "> "
if "title" in attach: if "title" in attach:
attachment_titles.append(attach['title']) attachment_titles.append(attach['title'])
if "title" in attach and "title_link" in attach: if "title" in attach and "title_link" in attach:
markdown_message += f"## [{attach['title']}]({attach['title_link']})\n" attachment_md += f"[{attach['title']}]({attach['title_link']})\n> "
elif "title" in attach: elif "title" in attach:
markdown_message += f"## {attach['title']}\n" attachment_md += f"## {attach['title']}\n> "
if "text" in attach: if "text" in attach:
markdown_message += f"{attach['text']}\n" 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: if 'fields' in attach:
for field in attach['fields']: for field in attach['fields']:
markdown_message += f"- **{field['title']}** : {field['value']}\n" attachment_md += f"- **{field['title']}** : {field['value']}\n> "
markdown_message += attachment_md + "\n"
if "sections" in data: if "sections" in data:
for section in data["sections"]: for section in data["sections"]:
if "activityTitle" in section and section['activityTitle'] not in attachment_titles: if "activityTitle" in section and section['activityTitle'] not in attachment_titles:
markdown_message += f"## {section['activityTitle']}\n" markdown_message += f"## {section['activityTitle']}\n"
if "activitySubtitle" in section: if "activitySubtitle" in section:
markdown_message += f">{section['activitySubtitle']}\n" markdown_message += f"{section['activitySubtitle']}\n"
return [markdown_message] return [markdown_message]