mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:21:32 +00:00
Update MessageSender to implement designed message format
This commit is contained in:
parent
7b76afe232
commit
6facda3520
@ -1,3 +1,6 @@
|
|||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from server_connector import ServerUplinkConnector
|
from server_connector import ServerUplinkConnector
|
||||||
|
|
||||||
|
|
||||||
@ -8,7 +11,11 @@ class MessageSender:
|
|||||||
custom_anchor = custom_anchor.encode('utf-8')
|
custom_anchor = custom_anchor.encode('utf-8')
|
||||||
self.anchor = custom_anchor or b'message'
|
self.anchor = custom_anchor or b'message'
|
||||||
|
|
||||||
def send(self, message):
|
def send(self, originator, message):
|
||||||
if isinstance(message, str):
|
response = {
|
||||||
message = message.encode('utf-8')
|
'originator': originator,
|
||||||
self.server_connector.send(self.anchor, message)
|
'timestamp': datetime.now().isoformat(),
|
||||||
|
'message': message
|
||||||
|
}
|
||||||
|
encoded_response = json.dumps(response).encode('utf-8')
|
||||||
|
self.server_connector.send(self.anchor, encoded_response)
|
||||||
|
Loading…
Reference in New Issue
Block a user