From 6facda3520bac227b496f3c41eba8b2552411f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Tue, 30 Jan 2018 17:24:17 +0100 Subject: [PATCH] Update MessageSender to implement designed message format --- src/event_handlers/message_sender.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/event_handlers/message_sender.py b/src/event_handlers/message_sender.py index e780c92..63a03b2 100644 --- a/src/event_handlers/message_sender.py +++ b/src/event_handlers/message_sender.py @@ -1,3 +1,6 @@ +import json +from datetime import datetime + from server_connector import ServerUplinkConnector @@ -8,7 +11,11 @@ class MessageSender: custom_anchor = custom_anchor.encode('utf-8') self.anchor = custom_anchor or b'message' - def send(self, message): - if isinstance(message, str): - message = message.encode('utf-8') - self.server_connector.send(self.anchor, message) + def send(self, originator, message): + response = { + 'originator': originator, + 'timestamp': datetime.now().isoformat(), + 'message': message + } + encoded_response = json.dumps(response).encode('utf-8') + self.server_connector.send(self.anchor, encoded_response)