mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-21 20:51:31 +00:00
Refactor MessageSender
This commit is contained in:
parent
e5d0e91e93
commit
dc5e26843a
@ -1,17 +1,22 @@
|
|||||||
|
DEFAULT_ORIGINATOR = 'avataobot'
|
||||||
|
|
||||||
|
|
||||||
class MessageSender:
|
class MessageSender:
|
||||||
def __init__(self, uplink):
|
def __init__(self, uplink):
|
||||||
self.uplink = uplink
|
self.uplink = uplink
|
||||||
|
|
||||||
def send(self, message, originator=None):
|
def send(self, message, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||||
message = {
|
message = {
|
||||||
'key': 'message.send',
|
'key': 'message.send',
|
||||||
'message': message
|
'message': message
|
||||||
}
|
}
|
||||||
if originator:
|
if originator:
|
||||||
message['originator'] = originator
|
message['originator'] = originator
|
||||||
|
if buttons:
|
||||||
|
message['buttons'] = buttons
|
||||||
self.uplink.send_message(message)
|
self.uplink.send_message(message)
|
||||||
|
|
||||||
def queue_messages(self, messages, originator=None):
|
def queue_messages(self, messages, originator=DEFAULT_ORIGINATOR, buttons=None):
|
||||||
message_queue = {
|
message_queue = {
|
||||||
'key': 'message.queue',
|
'key': 'message.queue',
|
||||||
'messages': []
|
'messages': []
|
||||||
@ -21,10 +26,6 @@ class MessageSender:
|
|||||||
if originator:
|
if originator:
|
||||||
next_message['originator'] = originator
|
next_message['originator'] = originator
|
||||||
message_queue['messages'].append(next_message)
|
message_queue['messages'].append(next_message)
|
||||||
|
if buttons and message_queue['messages']:
|
||||||
|
message_queue['messages'][-1]['buttons'] = buttons
|
||||||
self.uplink.send_message(message_queue)
|
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