コード例 #1
0
def weather():
    # Get destination from url query string:
    # 'node' : destination
    # 'Digits' : input digits from user
    if request.method == 'POST':
        dtmf = request.form.get('Digits', -1)
    else:
        dtmf = -1
    try:
        dtmf = int(dtmf)
    except ValueError:
        dtmf = -1

    zipcode = str(dtmf)
    zipcode = zipcode.replace('#', '').replace('*', '')[:5]
    if len(zipcode) != 5:  #todo check zipcode format
        r = plivohelper.Response()
        r.addSpeak("Invalid Zipcode")
    else:
        print "zipcode %s" % zipcode
        r = plivohelper.Response()
        xml_weather = fetch_weather(zipcode)
        if xml_weather and xml_weather.find('City not found') == -1:
            weather = parse(xml_weather)
            r.addSpeak(
                "It is currently %s degrees fahrenheit and %s in %s." %
                (weather['temp'], weather['conditions'], weather['location']))
        else:
            r.addSpeak("Error getting the weather forecast for zipcode %s." %
                       zipcode)

    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #2
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    d = r.addGetSpeech(action="http://127.0.0.1:5000/result/",
                       timeout=10,
                       playBeep=True,
                       engine="pocketsphinx",
                       grammar="pizza_yesno")
    d.addSpeak("Get Speech. say yes or no")
    r.addSpeak("Oh noooo, speech failed")
    r.addHangup()
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #3
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    d = r.addGetDigits(action="http://127.0.0.1:5000/menu/", 
                       timeout=10, retries=2, finishOnKey='#',
                       numDigits=2, playBeep=True, 
                       validDigits="01234")
    d.addSpeak("Get Digits. Press 0, 1, 2, 3 or 4")
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #4
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    r.addSpeak("Hello World", loop=1)
    r.addSpeak("${strepoch()}",
               loop=1,
               type="CURRENT_DATE_TIME",
               method="PRONOUNCED")
    r.addSpeak("${strepoch()}",
               loop=5,
               type="CURRENT_TIME",
               method="PRONOUNCED")
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #5
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    p = r.addConference("plivo",
                        muted=False,
                        enterSound="beep:2",
                        exitSound="beep:1",
                        startConferenceOnEnter=True,
                        endConferenceOnExit=True,
                        waitSound="http://127.0.0.1:5000/waitmusic/",
                        timeLimit=60,
                        hangupOnStar=True)
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #6
0
 def testSpeakLoop(self):
     """should say hello monkey and loop 3 times"""
     r = plivohelper.Response()
     r.append(plivohelper.Speak("Hello Monkey", loop=3))
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Speak loop="3">Hello Monkey</Speak></Response>')
コード例 #7
0
 def testPlayHello(self):
     """should play hello monkey"""
     r = plivohelper.Response()
     r.append(plivohelper.Play("http://hellomonkey.mp3"))
     r = self.strip(r)
     self.assertEqual(
         r, '<Response><Play>http://hellomonkey.mp3</Play></Response>')
コード例 #8
0
 def testDial(self):
     """ should redirect the call"""
     r = plivohelper.Response()
     r.append(plivohelper.Dial("1231231234"))
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Dial><Number>1231231234</Number></Dial></Response>')
コード例 #9
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    r.addSpeak("Dial Test")
    d = r.addDial(action="http://127.0.0.1:5000/dialed/",
                  hangupOnStar=True,
                  timeLimit=60,
                  dialMusic="http://127.0.0.1:5000/dialmusic/",
                  confirmSound="http://127.0.0.1:5000/confirm/",
                  confirmKey="9")
    d.addNumber("4871", gateways="sofia/gateway/pstn/", gatewayTimeouts="30")
    d.addNumber("1749", gateways="sofia/gateway/pstn", gatewayTimeouts="30")
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #10
0
def answered_bridge():
    From = request.POST['From']
    to = request.POST['To']
    r = plivohelper.Response()
    g = r.addDial()
    g.addNumber(From, gateways="user/,user/")
    return jinja2_template('response_template.xml', response=r)
コード例 #11
0
def confirm():
    r = plivohelper.Response()
    r.addSpeak("Confirm by pressing 9", loop=1)
    r.addPlay("http://127.0.0.1:5000/static/duck.mp3", loop=1)
    r.addPlay("http://127.0.0.1:5000/static/duck.mp3", loop=1)
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #12
0
def dialmusic():
    r = plivohelper.Response()
    r.addSpeak("Calling now", loop=1)
    r.addPlay("http://127.0.0.1:5000/static/duck.mp3", loop=1)
    r.addPlay("http://127.0.0.1:5000/static/duck.mp3", loop=1)
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #13
0
 def testAddConferenceConvenceMethod(self):
     """ add a conference to a dial, conviently"""
     r = plivohelper.Response()
     r.addConference("My Room")
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Conference>My Room</Conference></Response>')
コード例 #14
0
 def testAddConference(self):
     """ add a conference to a dial"""
     r = plivohelper.Response()
     r.append(plivohelper.Conference("My Room"))
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Conference>My Room</Conference></Response>')
コード例 #15
0
 def testAddNumberConvience(self):
     """add a number to a dial, convience method"""
     r = plivohelper.Response()
     d = r.addDial()
     d.addNumber("1231231234")
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Dial><Number>1231231234</Number></Dial></Response>')
コード例 #16
0
 def testRedirectMethod(self):
     r = plivohelper.Response()
     r.append(plivohelper.Redirect(url="example.com", method="POST"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Redirect method="POST">example.com</Redirect></Response>'
     )
コード例 #17
0
 def testRecordMaxlengthFinishTimeout(self):
     """should record with an maxlength, finishonkey, and timeout"""
     r = plivohelper.Response()
     r.addRecord(timeout=4, finishOnKey="#", maxLength=30)
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Record finishOnKey="#" maxLength="30" timeout="4"/></Response>'
     )
コード例 #18
0
def dialed():
    if request.method == 'POST':
        print request.form.items()
    else:
        print request.args.items()
    r = plivohelper.Response()
    r.addSpeak("Dial done")
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #19
0
 def testAddNumber(self):
     """add a number to a dial"""
     r = plivohelper.Response()
     d = plivohelper.Dial()
     d.append(plivohelper.Number("1231231234"))
     r.append(d)
     r = self.strip(r)
     self.assertEquals(
         r, '<Response><Dial><Number>1231231234</Number></Dial></Response>')
コード例 #20
0
def recorded():
    if request.method == 'POST':
        print request.form.items()
    else:
        print request.args.items()
    r = plivohelper.Response()
    r.addHangup()
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #21
0
 def testPlayConvienceMethod(self):
     """convenience method: should play hello monkey"""
     r = plivohelper.Response()
     r.addPlay("http://hellomonkey.mp3", loop=3)
     r = self.strip(r)
     self.assertEqual(
         r,
         '<Response><Play loop="3">http://hellomonkey.mp3</Play></Response>'
     )
コード例 #22
0
 def testRedirectMethodGetParams(self):
     r = plivohelper.Response()
     r.append(
         plivohelper.Redirect(url="example.com?id=34&action=hey",
                              method="POST"))
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><Redirect method="POST">example.com?id=34&amp;action=hey</Redirect></Response>'
     )
コード例 #23
0
def waitmusic():
    if request.method == 'POST':
        logger.info(str(request.form.items()))
    else:
        logger.info(str(request.args.items()))

    r = plivohelper.Response()
    r.addPlay("/home/csik/public_html/sounds/programs/3/current.mp3")
    logger.info("RESTXML Response => {}".format(r))
    #return render_template('response_template.xml', response=r)
    return "OK"
コード例 #24
0
def hostwait():
    if request.method == 'POST':
        logger.info(str(request.form.items()))
    else:
        logger.info(str(request.args.items()))
    r = plivohelper.Response()
    r.addPlay(TELEPHONY_SERVER_IP + "/~csik/sounds/english/Hello_Host.mp3")
    r.addPlay(TELEPHONY_SERVER_IP +
              "/~csik/sounds/english/You_Have_X_Listeners.mp3")
    r.addPlay(TELEPHONY_SERVER_IP + "/~csik/sounds/english/Instructions.mp3")
    logger.info("RESTXML Response => {}".format(r))
    return render_template('response_template.xml', response=r)
コード例 #25
0
def answered():
    # Get destination from url query string:
    # 'node' : destination
    # 'Digits' : input digits from user

    r = plivohelper.Response()
    g = r.addGetDigits(numDigits=5, action='http://127.0.0.1:5000/weather/')
    g.addSpeak("Welcome to Plivo Weather Forecast")
    g.addSpeak("please enter your Zip Code")

    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #26
0
 def testNestedSpeakPlayWaitConvience(self):
     """ a gather with a say, play, and pause"""
     r = plivohelper.Response()
     g = r.addGetDigits()
     g.addSpeak("Hey")
     g.addPlay("hey.mp3")
     g.addWait()
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><GetDigits><Speak>Hey</Speak><Play>hey.mp3</Play><Wait/></GetDigits></Response>'
     )
コード例 #27
0
def waitmusic():
    if request.method == 'POST':
        print request.form.items()
    else:
        print request.args.items()
    r = plivohelper.Response()
    r.addSpeak("Please wait")
    r.addSpeak("Be patient")
    #r.addPlay("http://127.0.0.1:5000/static/duck.mp3")
    r.addPlay(
        "/usr/local/freeswitch/sounds/en/us/callie/ivr/8000/ivr-welcome.wav")
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)
コード例 #28
0
 def testNestedSpeakPlayWait(self):
     """ a gather with a say, play, and pause"""
     r = plivohelper.Response()
     g = plivohelper.GetDigits()
     g.append(plivohelper.Speak("Hey"))
     g.append(plivohelper.Play("hey.mp3"))
     g.append(plivohelper.Wait())
     r.append(g)
     r = self.strip(r)
     self.assertEquals(
         r,
         '<Response><GetDigits><Speak>Hey</Speak><Play>hey.mp3</Play><Wait/></GetDigits></Response>'
     )
コード例 #29
0
def confer(parameters, schedule_program_id, action):
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call
    logger.info(
        "confer is receiveing schedule_program_id: {}     action: {}".format(
            schedule_program_id, action))
    if action == "ringing":
        logger.info(
            "Ringing for scheduled_program {}".format(schedule_program_id))
        return "OK"
    elif action == "heartbeat":
        logger.info(
            "Heartbeat for scheduled_program {}".format(schedule_program_id))
        return "OK"
    elif action == "hangup":
        # THIS IS WHERE NUMBER IS TRANSFERRED FROM outgoing_busy TO outgoing_unused
        logger.info(
            "Hangup for scheduled_program {}".format(schedule_program_id))
        return "OK"
    elif action == "answered":
        logger.info(
            "*Answered for scheduled_program {}".format(schedule_program_id))
        #  This is where station daemons are contacted
        r = plivohelper.Response()
        from_number = parameters.get('From')
        try:
            logger.info("url_for format = {}".format(url_for('confer_events')))
        except Exception:
            logger.info("unable to get url_for")
        p = r.addConference(
            "plivo",
            muted=False,
            enterSound="beep:2",
            exitSound="beep:1",
            startConferenceOnEnter=True,
            endConferenceOnExit=False,
            waitSound=ANSWERED + 'waitmusic/',
            timeLimit=0,
            hangupOnStar=True,
            callbackUrl=ANSWERED + 'confer_events/',
            callbackMethod="POST",
            digitsMatch="#9,#7,#8,7,8,9",
        )
        logger.info("RESTXML Response => {}".format(r))
        return render_template('response_template.xml', response=r)
    else:
        logger.info("Could not recognize plivo url variable")
        return "OK"
コード例 #30
0
def answered():
    # Post params- 'CallUUID': unique id of call, 'Direction': direction of call,
    #               'To': Number which was called, 'From': calling number,
    #               If Direction is outbound then 2 additional params:
    #               'ALegUUID': Unique Id for first leg,
    #               'ALegRequestUUID': request id given at the time of api call

    if request.method == 'POST':
        try:
            print "CallUUID: %s" % request.form['CallUUID']
        except:
            pass
    else:
        try:
            print "CallUUID: %s" % request.args['CallUUID']
        except:
            pass
    r = plivohelper.Response()
    r.addPlay("http://127.0.0.1:5000/static/duck.mp3", loop=10)
    print "RESTXML Response => %s" % r
    return render_template('response_template.xml', response=r)