mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-15 10:37:17 +00:00
31 lines
922 B
Python
31 lines
922 B
Python
class MessageSender:
|
|
def __init__(self, uplink):
|
|
self.uplink = uplink
|
|
|
|
def send(self, message, originator=None):
|
|
message = {
|
|
'key': 'message.send',
|
|
'message': message
|
|
}
|
|
if originator:
|
|
message['originator'] = originator
|
|
self.uplink.send_message(message)
|
|
|
|
def queue_messages(self, messages, originator=None):
|
|
message_queue = {
|
|
'key': 'message.queue',
|
|
'value': []
|
|
}
|
|
for message in messages:
|
|
next_message = {'message': message}
|
|
if originator:
|
|
next_message['originator'] = originator
|
|
message_queue['value'].append(next_message)
|
|
self.uplink.send_message(message_queue)
|
|
|
|
def set_originator(self, originator):
|
|
self.uplink.send_message({
|
|
'key': 'message.config',
|
|
'originator': originator
|
|
})
|