From c79fecb587a533515a13ad1a37fadc6e5a6801de Mon Sep 17 00:00:00 2001 From: Caetan Tojeiro Carpente <caetan.tojeiro.carpente@cern.ch> Date: Tue, 6 Dec 2022 09:57:18 +0100 Subject: [PATCH] [#86] [Bugfix] Links missing from Mattermost notification --- notifications_consumer/processors/mattermost/utils.py | 6 ++---- scripts/docker-send-mattermost.py | 8 ++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/notifications_consumer/processors/mattermost/utils.py b/notifications_consumer/processors/mattermost/utils.py index 4396626..9a784dc 100644 --- a/notifications_consumer/processors/mattermost/utils.py +++ b/notifications_consumer/processors/mattermost/utils.py @@ -1,7 +1,5 @@ """Mattermost notifications utils.""" -import html import logging -import re import unicodedata from mattermostdriver import Driver @@ -11,8 +9,8 @@ from notifications_consumer.config import Config def create_message(summary: str, body: str, url: str, image: str): """Create json blob to be sent via Mattermost.""" - # strip tags, html decode and replace unicode blobs - text_content = unicodedata.normalize("NFKD", html.unescape(re.sub("<.*?>", "", body))) + # Replace unicode blobs + text_content = unicodedata.normalize("NFKD", body) # If message is empty string, webpush will fill with the ugly json message if not text_content: text_content = "empty" diff --git a/scripts/docker-send-mattermost.py b/scripts/docker-send-mattermost.py index 9a363c9..595c7b7 100644 --- a/scripts/docker-send-mattermost.py +++ b/scripts/docker-send-mattermost.py @@ -6,14 +6,14 @@ conn = stomp.Connection([("activemq", 61613)]) conn.connect("admin", "admin", wait=True) message_body = r"""{ "channel_name": "The Best Notifications", -"content":"<p>This is an <a href=\"http://example.com/\">example link</a>.</p><!-- This comment --><code>/home/\nhi" - "codeline2\ncodeline3</code>\n<img src=\"img_girl.jpg\" alt=\"Girl" +"message_body":"<p>This is an <a href=\"http://example.com/\">example link</a>.</p><!--" + "This comment --><code>/home/\nhicodeline2\ncodeline3</code>\n<img src=\"img_girl.jpg\" alt=\"Girl" " in a jacket\" width=\"500\" height=\"600\">\n<h1>Hello</h1>\n<h2>Hello</h2>", "summary": "sub test EO", "link": "http://cds.cern.ch/record/2687667", "img_url": "http://cds.cern.ch/record/2687667/files/CLICtd.png?subformat=icon-640", -"device_token": "emmanuel.ormancey@cern.ch", -"email": "emmanuel.ormancey@cern.ch", +"device_token": "caetan.tojeiro.carpente@cern.ch", +"email": "caetan.tojeiro.carpente@cern.ch", "device_id": "084a9172-cc5d-451a-b573-c5baafc1257c", "notification_id": "kujasdhdkjszhdghello" }""" -- GitLab