mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 02:11:56 +00:00
Refactor MessageSender
This commit is contained in:
parent
e5d0e91e93
commit
dc5e26843a
@ -1,17 +1,22 @@
|
||||
DEFAULT_ORIGINATOR = 'avataobot'
|
||||
|
||||
|
||||
class MessageSender:
|
||||
def __init__(self, uplink):
|
||||
self.uplink = uplink
|
||||
|
||||
def send(self, message, originator=None):
|
||||
def send(self, message, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||
message = {
|
||||
'key': 'message.send',
|
||||
'message': message
|
||||
}
|
||||
if originator:
|
||||
message['originator'] = originator
|
||||
if buttons:
|
||||
message['buttons'] = buttons
|
||||
self.uplink.send_message(message)
|
||||
|
||||
def queue_messages(self, messages, originator=None):
|
||||
def queue_messages(self, messages, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||
message_queue = {
|
||||
'key': 'message.queue',
|
||||
'messages': []
|
||||
@ -21,10 +26,6 @@ class MessageSender:
|
||||
if originator:
|
||||
next_message['originator'] = originator
|
||||
message_queue['messages'].append(next_message)
|
||||
if buttons and message_queue['messages']:
|
||||
message_queue['messages'][-1]['buttons'] = buttons
|
||||
self.uplink.send_message(message_queue)
|
||||
|
||||
def set_originator(self, originator):
|
||||
self.uplink.send_message({
|
||||
'key': 'message.config',
|
||||
'originator': originator
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user