(request, backend_id=None)
Handles tropo messaging requests
Handles tropo messaging requests
Handles tropo messaging requests
def sms_in(request, backend_id=None):
    """
    Handles tropo messaging requests
    """
    from tropo import Tropo
    if request.method == "POST":
        data = json.loads(request.body.decode('utf-8'))
        session = data["session"]
        # Handle when Tropo posts to us to send an SMS
        if "parameters" in session:
            params = session["parameters"]
            if ("_send_sms" in params) and ("numberToDial" in params) and ("msg" in params):
                numberToDial = params["numberToDial"]
                msg = params["msg"]
                t = Tropo()
                t.call(to = numberToDial, network = "SMS")
                t.say(msg)
                return HttpResponse(t.RenderJson())
        # Handle incoming SMS
        phone_number = None
        text = None
        if "from" in session:
            phone_number = session["from"]["id"]
        if "initialText" in session:
            text = session["initialText"]
        if phone_number is not None and len(phone_number) > 1:
            if phone_number[0] == "+":
                phone_number = phone_number[1:]
        incoming_sms(phone_number, text, SQLTropoBackend.get_api_id(), backend_id=backend_id)
        t = Tropo()
        t.hangup()
        return HttpResponse(t.RenderJson())
    else:
        return HttpResponseBadRequest("Bad Request")
def sms_in ( request , backend_id = None ) : from tropo import Tropo if request . method == "POST" : data = json . loads ( request . body . decode ( 'utf-8' ) ) session = data [ "session" ] # Handle when Tropo posts to us to send an SMS if "parameters" in session : params = session [ "parameters" ] if ( "_send_sms" in params ) and ( "numberToDial" in params ) and ( "msg" in params ) : numberToDial = params [ "numberToDial" ] msg = params [ "msg" ] t = Tropo ( ) t . call ( to = numberToDial , network = "SMS" ) t . say ( msg ) return HttpResponse ( t . RenderJson ( ) ) # Handle incoming SMS phone_number = None text = None if "from" in session : phone_number = session [ "from" ] [ "id" ] if "initialText" in session : text = session [ "initialText" ] if phone_number is not None and len ( phone_number ) > 1 : if phone_number [ 0 ] == "+" : phone_number = phone_number [ 1 : ] incoming_sms ( phone_number , text , SQLTropoBackend . get_api_id ( ) , backend_id = backend_id ) t = Tropo ( ) t . hangup ( ) return HttpResponse ( t . RenderJson ( ) ) else : return HttpResponseBadRequest ( "Bad Request" )