From 0fc94dba3b007a7d4337b796556a38022e8e2f50 Mon Sep 17 00:00:00 2001 From: Carina Antunes <carina.oliveira.antunes@cern.ch> Date: Thu, 21 Oct 2021 16:22:18 +0200 Subject: [PATCH] [hotfix] channel category --- notifications_routing/router.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/notifications_routing/router.py b/notifications_routing/router.py index d6e47d0..77a64e4 100644 --- a/notifications_routing/router.py +++ b/notifications_routing/router.py @@ -64,11 +64,19 @@ class Router(megabus.Listener): """Convert message to json and retrieves target, body, created timestamp, priority.""" message_json = json.loads(message) + channel = message_json[str(InputMessageKeys.TARGET)] + + category_name = ( + channel[str(InputMessageKeys.CATEGORY)][str(InputMessageKeys.NAME)] + if InputMessageKeys.CATEGORY in channel + else None + ) + notification = { str(OutputMessageKeys.ID): message_json[str(InputMessageKeys.ID)], - str(OutputMessageKeys.CHANNEL_ID): message_json[str(InputMessageKeys.TARGET)][str(InputMessageKeys.ID)], - str(OutputMessageKeys.CHANNEL_NAME): message_json[str(InputMessageKeys.TARGET)][str(InputMessageKeys.NAME)], - str(OutputMessageKeys.CHANNEL_SLUG): message_json[str(InputMessageKeys.TARGET)][str(InputMessageKeys.SLUG)], + str(OutputMessageKeys.CHANNEL_ID): channel[str(InputMessageKeys.ID)], + str(OutputMessageKeys.CHANNEL_NAME): channel[str(InputMessageKeys.NAME)], + str(OutputMessageKeys.CHANNEL_SLUG): channel[str(InputMessageKeys.SLUG)], str(OutputMessageKeys.PRIORITY): message_json[str(InputMessageKeys.PRIORITY)], str(OutputMessageKeys.CREATED_TIMESTAMP): convert_timestamp_to_local_timezone( message_json[str(InputMessageKeys.SENT_AT)] @@ -77,14 +85,9 @@ class Router(megabus.Listener): str(OutputMessageKeys.SUMMARY): message_json[str(InputMessageKeys.SUMMARY)], str(OutputMessageKeys.LINK): message_json[str(InputMessageKeys.LINK)], str(OutputMessageKeys.IMGURL): message_json[str(InputMessageKeys.IMGURL)], + str(OutputMessageKeys.CHANNEL_CATEGORY): category_name, } - notification[str(OutputMessageKeys.CHANNEL_CATEGORY)] = ( - message_json[str(InputMessageKeys.TARGET)][str(InputMessageKeys.CATEGORY)] - if InputMessageKeys.CATEGORY in message_json[InputMessageKeys.TARGET] - else None - ) - return notification def get_channel_users(self, channel_id): -- GitLab