Exemplo n.º 1
0
class XMPPMessageHandler(object):
  def __init__(self):
    self._current_menu = None
    self.auth = USSDAuthBackend()

  def answer(self, transport, recipient, message):
    user = self.auth.authenticate(recipient)
    if user:
      session = USSDSession.objects.recent(user)
      if session:
        log.debug("User: %s USSD Session: %s" % (user, session))
        msg = str(message)
        if msg == "$start":
          response = handle_start(session)
        elif msg == "$end":
          response = handle_end(session)
        elif msg == "$error":
          import pdb
          pdb.set_trace()
        else:
          if session.current_menu and not session.current_menu.is_finished():
            response = handle_session(session, msg)
          else:
            response = "Use $start to create menu"
        if recipient and response:
          transport(recipient, response)
        else:
          log.error("Either recipient (%s) or response (%s) is not valid!" % (recipient, response))
        return
      else:
        transport(recipient, "Error: No USSD Session!")
    else:
      transport(recipient, "Error: No User!")
Exemplo n.º 2
0
 def __init__(self):
   self._current_menu = None
   self.auth = USSDAuthBackend()