Skip to content

Commit

Permalink
Added support for close session with test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaderabbit committed Jul 10, 2014
1 parent 73ef53c commit 1abe76d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions vxaat/ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ def get_callback_url(self):
config.base_url,
config.web_path)

def get_to_addr(self):
config = self.get_static_config()
return config.to_addr

@inlineCallbacks
def handle_raw_inbound_message(self, message_id, request):
errors = {}
to_address = self.get_to_addr()
to_address = self.get_static_config().to_addr

values, field_value_errors = self.get_field_values(
request,
Expand Down Expand Up @@ -84,21 +81,24 @@ def handle_raw_inbound_message(self, message_id, request):
}
)

def generate_body(self, reply, callback):
def generate_body(self, reply, callback, session_event):
request = Element('request')
headertext = SubElement(request, 'headertext')
headertext.text = reply
options = SubElement(request, 'options')
SubElement(
options,
'option',
{
'command': '1',
'order': '1',
'callback': callback,
'display': "false"
}
)

# If this is a SESSION_CLOSE, then do not send options
if session_event != TransportUserMessage.SESSION_CLOSE:
options = SubElement(request, 'options')
SubElement(
options,
'option',
{
'command': '1',
'order': '1',
'callback': callback,
'display': "false"
}
)

return tostring(
request,
Expand All @@ -111,7 +111,8 @@ def handle_outbound_message(self, message):
message_id = message['message_id']
body = self.generate_body(
message['content'],
self.get_callback_url()
self.get_callback_url(),
message['session_event']
)

if message.payload.get('in_reply_to') and 'content' in message.payload:
Expand All @@ -132,3 +133,4 @@ def handle_outbound_message(self, message):

yield self.publish_ack(user_message_id=message_id,
sent_message_id=message_id)

0 comments on commit 1abe76d

Please sign in to comment.