mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 23:31:31 +00:00
31 lines
928 B
Python
31 lines
928 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',
|
|
'messages': []
|
|
}
|
|
for message in messages:
|
|
next_message = {'message': message}
|
|
if originator:
|
|
next_message['originator'] = originator
|
|
message_queue['messages'].append(next_message)
|
|
self.uplink.send_message(message_queue)
|
|
|
|
def set_originator(self, originator):
|
|
self.uplink.send_message({
|
|
'key': 'message.config',
|
|
'originator': originator
|
|
})
|