示例#1
0
 def test_ask(self):
     """
     Test the "ask" Tropo class method.
     """
     tropo = Tropo()
     tropo.ask("[5 digits]",
               say = Say("Please enter a 5 digit zip code").json)
     rendered = tropo.RenderJson()
     pretty_rendered = tropo.RenderJson(pretty=True)
     print "===============test_ask================="
     print "render json: %s" % pretty_rendered
     rendered_obj = jsonlib.loads(rendered)
     wanted_json = '{"tropo": [{"ask": {"say": {"value": "Please enter a 5 digit zip code"}, "choices": {"value": "[5 digits]"}}}]}'
     wanted_obj = jsonlib.loads(wanted_json)
     # print "test_ask: %s" % tropo.RenderJson()
     self.assertEqual(rendered_obj, wanted_obj)
示例#2
0
if __name__ == '__main__':
    """
    Unit tests.
    """
    if (0):
        TO = "8005551212"

        ID = "foo"
        URL = "http://s3.amazonaws.com/xxx_s3_bucket/hello.wav"



        tropo = Tropo()

        tropo.ask("[5 digits]",
                  say = Say("Please enter a 5 digit zip code").json)


        tropo.call (TO)
        tropo.conference(ID)
        tropo.hangup()
        tropo.message ("Hello, World", TO)
        tropo.on(event="continue", 
             next="http://example.com/weather.py",
             say="Please hold.")

        tropo.record(say="Please say something for posterity", 
                     url=URL, 
                     choices = Choices("", terminator="#").json)
        tropo.redirect(ID)
        tropo.reject(ID)
示例#3
0
#CPA
mc = MachineDetection(introduction="THis is a CPA test", voice="Victor").json
t.call("+14071234321", machineDetection=mc)

#CPA with Boolean value which will detect CPA with 30 seconds of silence.
t.call("+14071234321", machineDetection=True)

#Conference with join/leave prompts
jp = JoinPrompt(value="Someone just joined the conference",
                voice="Victor").json
lp = LeavePrompt(value="Someone just left the conference", voice="Victor").json
t.conference(id="1234", joinPrompt=jp, leavePrompt=lp)

whisper = {}

c = Choices(value="1", mode="dtmf")
ask = Ask(say="Press 1 to accept this call", choices=c).json
whisper["ask"] = ask

say = Say("You are now being connected to the call").json
whisper["say"] = say

say1 = Say("http://www.phono.com/audio/holdmusic.mp3").json
whisper["ring"] = say1

t.transfer(to="+14071234321", on=whisper)
t.on(event="incomplete", say="You are now being disconnected. Goodbye")

print t.RenderJson()