Beispiel #1
0
    def test_ring(self):
        ring = Ring(duration=5, answer_call=False)

        response = Response()
        response.add_verb(ring)
        expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Ring duration="5" answerCall="False"/></Response>'
        assert (response.to_bxml() == expected_bxml)
Beispiel #2
0
 def test_conference_coach_array(self):
     conference = Conference("my-conference",
                             call_ids_to_coach=["c-123", "c-456"])
     response = Response()
     response.add_verb(conference)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference callIdsToCoach="c-123,c-456">my-conference</Conference></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #3
0
 def test_record(self):
     response = Response()
     record = Record(
         tag="tag",
         username="******",
         password="******",
         record_complete_url="https://record.url.server/record",
         record_complete_method="POST",
         recording_available_url="https://record.url.server/available",
         recording_available_method="GET",
         terminating_digits="#",
         max_duration=90,
         file_format="mp3",
         transcribe=False,
         transcription_available_url=
         "https://transcribe.url.server/available",
         transcription_available_method="POST",
         silence_timeout=90,
         record_complete_fallback_url="https://test.com",
         record_complete_fallback_method="GET",
         fallback_username="******",
         fallback_password="******")
     response.add_verb(record)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Record tag="tag" username="******" password="******" recordCompleteUrl="https://record.url.server/record" recordCompleteMethod="POST" recordingAvailableUrl="https://record.url.server/available" recordingAvailableMethod="GET" terminatingDigits="#" maxDuration="90" fileFormat="mp3" transcribe="false" transcriptionAvailableUrl="https://transcribe.url.server/available" transcriptionAvailableMethod="POST" silenceTimeout="90" recordCompleteFallbackUrl="https://test.com" recordCompleteFallbackMethod="GET" fallbackUsername="******" fallbackPassword="******"/></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #4
0
    def test_stop_gather(self):
        stopGather = StopGather()

        response = Response()
        response.add_verb(stopGather)
        expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><StopGather/></Response>'
        assert response.to_bxml() == expected_bxml
Beispiel #5
0
    def test_stop_stream_bxml_verb(self):
        expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StopStream name="test_stream"/></Response>'
        response = Response()
        stop_stream = StopStream(name='test_stream')
        response.add_verb(stop_stream)
        actual = response.to_bxml()

        assert expected == actual
Beispiel #6
0
 def test_play_audio(self):
     response = Response()
     play_audio_1 = PlayAudio(url="https://audio.url/audio1.wav",
                              username="******",
                              password="******")
     response.add_verb(play_audio_1)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><PlayAudio username="******" password="******">https://audio.url/audio1.wav</PlayAudio></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #7
0
def start_gather_game():
    """
    Callback endpoint that returns BXML for making a gather
    """
    gather = Gather(gather_url="/EndGatherGame", max_digits=2)
    response = Response()
    response.add_verb(gather)

    return response.to_bxml()
Beispiel #8
0
 def test_speak_sentence(self):
     response = Response()
     speak_sentence = SpeakSentence(sentence="Phrase.",
                                    voice="kate",
                                    locale="en_US",
                                    gender="female")
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence voice="kate" locale="en_US" gender="female">Phrase.</SpeakSentence></Response>'
     response.add_verb(speak_sentence)
     assert response.to_bxml() == expected_bxml
Beispiel #9
0
 def test_forward_xml_with_optional_fields(self):
     response = Response()
     forward = Forward(to="+10987654321",
                       from_="+11234567890",
                       call_timeout=100,
                       diversion_treatment="propagate",
                       diversion_reason="away")
     response.add_verb(forward)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Forward to="+10987654321" callTimeout="100" from="+11234567890" diversionTreatment="propagate" diversionReason="away"/></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #10
0
 def test_gather_speak_sentence_ssml(self):
     response = Response()
     speak_sentence = SpeakSentence(
         sentence=
         'Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.'
     )
     gather = Gather(speak_sentence=speak_sentence)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather><SpeakSentence>Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Gather></Response>'
     response.add_verb(gather)
     assert response.to_bxml() == expected_bxml
Beispiel #11
0
def handle_end_gather_1():
    #URL of recording is in the tag
    data = json.loads(request.data)
    response = Response()
    if "digits" in data.keys() and data["digits"] == "1":
        #play recording
        play_recording = PlayAudio(
            url=data["tag"],
            username=VOICE_API_USERNAME,
            password=VOICE_API_PASSWORD
        )
        ask_to_re_record = SpeakSentence(
            sentence="Would you like to re record? Press 1 if so, otherwise please hangup"
        )
        gather = Gather(
            first_digit_timeout=15,
            speak_sentence=ask_to_re_record,
            max_digits=1,
            gather_url="/EndGather2"
        )
        response.add_verb(play_recording)
        response.add_verb(gather)
    else:
        hangup = Hangup()
        response.add_verb(hangup)
    return response.to_bxml()
Beispiel #12
0
    def test_start_gather(self):
        startGather = StartGather(dtmfUrl="https://test.com",
                                  dtmfMethod="POST",
                                  username="******",
                                  password="******",
                                  tag="custom tag")

        response = Response()
        response.add_verb(startGather)
        expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><StartGather dtmfUrl="https://test.com" dtmfMethod="POST" username="******" password="******" tag="custom tag"/></Response>'
        assert response.to_bxml() == expected_bxml
Beispiel #13
0
 def test_speak_sentence_SSML(self):
     response = Response()
     speak_sentence = SpeakSentence(
         sentence=
         '<lang xml:lang="es-MX">Hydrogen</lang> is the most abundant element in the universe.',
         voice="kate",
         locale="en_US",
         gender="female")
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><SpeakSentence voice="kate" locale="en_US" gender="female"><lang xml:lang="es-MX">Hydrogen</lang> is the most abundant element in the universe.</SpeakSentence></Response>'
     response.add_verb(speak_sentence)
     assert response.to_bxml() == expected_bxml
Beispiel #14
0
def handle_voice_callback_inbound():
    sentence = 'Hello, let\'s play a game. What is 9 + 2'
    voice = 'kate'
    speak_sentence = SpeakSentence(sentence, voice)
    gather = Gather(max_digits=2,
                    first_digit_timeout=10,
                    gather_url='/Callbacks/Voice/Gather',
                    speak_sentence=speak_sentence)
    response = Response()
    response.add_verb(gather)
    bxml = response.to_bxml()
    print(bxml)
    return bxml
Beispiel #15
0
    def test_start_stream_bxml_verb(self):
        expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartStream destination="https://www.test.com/stream" name="test_stream" tracks="inbound" streamEventUrl="https://www.test.com/event" streamEventMethod="POST" username="******" password="******"/></Response>'
        response = Response()
        start_stream = StartStream(destination='https://www.test.com/stream',
                                   name='test_stream',
                                   tracks='inbound',
                                   streamEventUrl='https://www.test.com/event',
                                   streamEventMethod='POST',
                                   username='******',
                                   password='******')
        response.add_verb(start_stream)
        actual = response.to_bxml()

        assert expected == actual
Beispiel #16
0
 def test_redirect(self):
     response = Response()
     redirect = Redirect(redirect_url="http://flow.url/newFlow",
                         redirect_method="POST",
                         tag="tag",
                         username="******",
                         password="******",
                         redirect_fallback_url="https://test.com",
                         redirect_fallback_method="GET",
                         fallback_username="******",
                         fallback_password="******")
     response.add_verb(redirect)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Redirect redirectUrl="http://flow.url/newFlow" redirectMethod="POST" tag="tag" username="******" password="******" redirectFallbackUrl="https://test.com" redirectFallbackMethod="GET" fallbackUsername="******" fallbackPassword="******"/></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #17
0
def end_gather_transfer():
    """
    A method that receives a Gather callback from Bandwidth and creates a Transfer response
    """
    data = json.loads(request.data)
    phone_number_string = "+1" + data["digits"]

    phone_number = PhoneNumber(number=phone_number_string)

    transfer = Transfer(transfer_caller_id=data["from"],
                        phone_numbers=[phone_number])

    response = Response()
    response.add_verb(transfer)
    return response.to_bxml()
Beispiel #18
0
def start_gather_transfer():
    """
    A method that returns BXML for creating a gather on an outbound call
    """
    speak_sentence = SpeakSentence(
        sentence=
        "Who do you want to transfer this call to? Enter the 10 digit phone number",
        voice="susan",
        locale="en_US",
        gender="female")
    gather = Gather(gather_url="/EndGatherTransfer",
                    max_digits=10,
                    speak_sentence=speak_sentence)
    response = Response()
    response.add_verb(gather)
    return response.to_bxml()
Beispiel #19
0
def handle_recording_gather_1():
    #Recording URL is in the "tag" of the data
    data = json.loads(request.data)
    ask_to_hear_recording = SpeakSentence(
        sentence="Your recording is now available. If you'd like to hear your recording, press 1, otherwise please hangup"
    )
    gather = Gather(
        first_digit_timeout=15,
        speak_sentence=ask_to_hear_recording,
        max_digits=1,
        gather_url="/EndGather1",
        tag=data["tag"]
    )
    response = Response()
    response.add_verb(gather)
    return response.to_bxml()
Beispiel #20
0
 def test_start_recording(self):
     response = Response()
     record = StartRecording(
         tag="tag",
         username="******",
         password="******",
         recording_available_url="https://record.url.server/available",
         recording_available_method="GET",
         file_format="mp3",
         multi_channel=True,
         transcribe=False,
         transcription_available_url=
         "https://transcribe.url.server/available",
         transcription_available_method="POST")
     response.add_verb(record)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><StartRecording tag="tag" username="******" password="******" recordingAvailableUrl="https://record.url.server/available" recordingAvailableMethod="GET" fileFormat="mp3" multiChannel="true" transcribe="false" transcriptionAvailableUrl="https://transcribe.url.server/available" transcriptionAvailableMethod="POST"/></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #21
0
 def test_gather_play_audio(self):
     response = Response()
     play_audio_1 = PlayAudio(url="https://audio.url/audio1.wav")
     gather = Gather(gather_url="https://gather.url/nextBXML",
                     gather_method="POST",
                     terminating_digits="#",
                     tag="tag",
                     max_digits=20,
                     inter_digit_timeout=50,
                     username="******",
                     password="******",
                     first_digit_timeout=10,
                     repeat_count=3,
                     play_audio=play_audio_1)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather gatherUrl="https://gather.url/nextBXML" gatherMethod="POST" terminatingDigits="#" tag="tag" maxDigits="20" interDigitTimeout="50" username="******" password="******" firstDigitTimeout="10" repeatCount="3"><PlayAudio>https://audio.url/audio1.wav</PlayAudio></Gather></Response>'
     response.add_verb(gather)
     assert response.to_bxml() == expected_bxml
Beispiel #22
0
def handle_voice_callback():
    ring_audio = PlayAudio(
        url="https://www.soundjay.com/phone/telephone-ring-01a.wav"
    )
    leave_voicemail = SpeakSentence(
        sentence="Please leave a message after the beep. Your time limit is 3 minutes. Press # to stop the recording early"
    )
    redirect = Redirect(
        redirect_url="/RecordCallback"
    )
    response = Response()
    response.add_verb(ring_audio)
    response.add_verb(leave_voicemail)
    response.add_verb(redirect)
    return response.to_bxml()
Beispiel #23
0
 def test_gather_no_nested(self):
     response = Response()
     gather = Gather(gather_url="https://gather.url/nextBXML",
                     gather_method="POST",
                     terminating_digits="#",
                     tag="tag",
                     max_digits=20,
                     inter_digit_timeout=50,
                     username="******",
                     password="******",
                     first_digit_timeout=10,
                     repeat_count=3,
                     gather_fallback_url="https://test.com",
                     gather_fallback_method="GET",
                     fallback_username="******",
                     fallback_password="******")
     response.add_verb(gather)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather gatherUrl="https://gather.url/nextBXML" gatherMethod="POST" terminatingDigits="#" tag="tag" maxDigits="20" interDigitTimeout="50" username="******" password="******" firstDigitTimeout="10" repeatCount="3" gatherFallbackUrl="https://test.com" gatherFallbackMethod="GET" fallbackUsername="******" fallbackPassword="******"/></Response>'
     assert response.to_bxml() == expected_bxml
Beispiel #24
0
def end_gather_game():
    """
    Callback endpoint that expects a gather callback
    """
    data = json.loads(request.data)

    digits = int(data["digits"])

    audio_url = None

    if digits == 12:
        audio_url = CORRECT_URL
    else:
        audio_url = INCORRECT_URL

    play_audio = PlayAudio(url=audio_url)
    response = Response()
    response.add_verb(play_audio)

    return response.to_bxml()
Beispiel #25
0
    def test_conference(self):
        conference = Conference(
            "my-conference",
            mute=False,
            hold=True,
            call_ids_to_coach="c-123,c-345",
            conference_event_url="https://test.com",
            conference_event_method="GET",
            username="******",
            password="******",
            tag="tag",
            conference_event_fallback_url="https://test2.com",
            conference_event_fallback_method="POST",
            fallback_username="******",
            fallback_password="******")

        response = Response()
        response.add_verb(conference)
        expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Conference mute="false" hold="true" callIdsToCoach="c-123,c-345" conferenceEventUrl="https://test.com" conferenceEventMethod="GET" tag="tag" username="******" password="******" conferenceEventFallbackUrl="https://test2.com" conferenceEventFallbackMethod="POST" fallbackUsername="******" fallbackPassword="******">my-conference</Conference></Response>'
        assert response.to_bxml() == expected_bxml
Beispiel #26
0
 def test_gather_with_speak_sentence(self):
     response = Response()
     speak_sentence = SpeakSentence(sentence="Phrase.",
                                    voice="kate",
                                    locale="en_US",
                                    gender="female")
     gather = Gather(gather_url="https://gather.url/nextBXML",
                     gather_method="POST",
                     terminating_digits="#",
                     tag="tag",
                     max_digits=20,
                     inter_digit_timeout=50,
                     username="******",
                     password="******",
                     first_digit_timeout=10,
                     repeat_count=3,
                     speak_sentence=speak_sentence)
     expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Gather gatherUrl="https://gather.url/nextBXML" gatherMethod="POST" terminatingDigits="#" tag="tag" maxDigits="20" interDigitTimeout="50" username="******" password="******" firstDigitTimeout="10" repeatCount="3"><SpeakSentence voice="kate" locale="en_US" gender="female">Phrase.</SpeakSentence></Gather></Response>'
     response.add_verb(gather)
     assert response.to_bxml() == expected_bxml
Beispiel #27
0
    def test_bridge(self):
        bridge = Bridge(
            "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d",
            bridge_complete_url="https://test.com",
            bridge_complete_method="GET",
            bridge_target_complete_url="https://test2.com",
            bridge_target_complete_method="POST",
            username="******",
            password="******",
            tag="custom tag",
            bridge_complete_fallback_url="https://test3.com",
            bridge_complete_fallback_method="GET",
            bridge_target_complete_fallback_url="https://test4.com",
            bridge_target_complete_fallback_method="POST",
            fallback_username="******",
            fallback_password="******")

        response = Response()
        response.add_verb(bridge)
        expected_bxml = '<?xml version="1.0" encoding="UTF-8"?><Response><Bridge bridgeCompleteUrl="https://test.com" bridgeCompleteMethod="GET" bridgeTargetCompleteUrl="https://test2.com" bridgeTargetCompleteMethod="POST" username="******" password="******" tag="custom tag" bridgeCompleteFallbackUrl="https://test3.com" bridgeCompleteFallbackMethod="GET" bridgeTargetCompleteFallbackUrl="https://test4.com" bridgeTargetCompleteFallbackMethod="POST" fallbackUsername="******" fallbackPassword="******">c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d</Bridge></Response>'
        assert response.to_bxml() == expected_bxml
Beispiel #28
0
def handle_end_gather_2():
    data = json.loads(request.data)
    response = Response()
    if "digits" in data.keys() and data["digits"] == "1":
        redirect = Redirect(
            redirect_url="/RecordCallback"
        )
        response.add_verb(redirect)
    else:
        hangup = Hangup()
        response.add_verb(hangup)
    return response.to_bxml()
Beispiel #29
0
def handle_record_complete_callback():
    #Loops endlessly until the recording is available
    pause = Pause(
        duration=3
    )
    redirect = Redirect(
        redirect_url="/RecordCompleteCallback"
    )
    response = Response()
    response.add_verb(pause)
    response.add_verb(redirect)
    return response.to_bxml()
Beispiel #30
0
def handle_voice_callback_gather():
    data = json.loads(request.data)
    digits = data['digits']
    success_file = 'https://bw-demo.s3.amazonaws.com/tada.wav'
    fail_file = 'https://bw-demo.s3.amazonaws.com/fail.wav'
    audio_uri = success_file if digits == '11' else fail_file
    play_audio = PlayAudio(url=audio_uri)
    hangup = Hangup()
    response = Response()
    response.add_verb(play_audio)
    response.add_verb(hangup)
    bxml = response.to_bxml()
    print(bxml)
    return bxml