Beispiel #1
0
    def test_set_methods(self):
        expected_response = '<Response><Record action="https://foo.example.com" callbackMethod="GET" ' \
                            'callbackUrl="https://foo.example.com" fileFormat="wav" finishOnKey="#" ' \
                            'maxLength="10" method="GET" playBeep="false" recordSession="false" ' \
                            'redirect="false" startOnDialAnswer="false" timeout="100" transcriptionMethod="GET" ' \
                            'transcriptionType="hybrid" transcriptionUrl="https://foo.example.com"/>' \
                            '</Response>'
        action = 'https://foo.example.com'
        method = 'GET'
        fileFormat = 'wav'
        redirect = False
        timeout = 100
        maxLength = 10
        recordSession = False
        startOnDialAnswer = False
        playBeep = False
        finishOnKey = '#'
        transcriptionType = 'hybrid'
        transcriptionUrl = 'https://foo.example.com'
        transcriptionMethod = 'GET'
        callbackUrl = 'https://foo.example.com'
        callbackMethod = 'GET'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.RecordElement().set_action(action).set_method(
                method).set_file_format(fileFormat).set_redirect(redirect).
            set_timeout(timeout).set_max_length(maxLength).set_play_beep(
                playBeep).set_finish_on_key(finishOnKey).set_record_session(
                    recordSession).set_start_on_dial_answer(startOnDialAnswer).
            set_transcription_type(transcriptionType).set_transcription_url(
                transcriptionUrl).set_transcription_method(
                    transcriptionMethod).set_callback_url(callbackUrl).
            set_callback_method(callbackMethod)).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #2
0
 def get(self, request, *args, **kwargs):
     print request.GET
     from_number = request.GET.get('From', 1)
     to_number = request.GET.get('To', 2)
     text = request.GET.get('Text', '')
     data = ''
     word_meaning = self.meaning(text)
     word_synonym = self.synonym(text)
     word_antonym = self.antonym(text)
     if word_meaning:
         data += word_meaning
     if word_synonym:
         data += word_synonym
     if word_antonym:
         data += word_antonym
     if data == '':
         data = 'Word not found'
     print data
     params = {"src": to_number, "dst": from_number}
     body = data
     r = plivoxml.ResponseElement()
     r.add_message(body, **params)
     r.add_redirect('http://plivobin.qa.plivodev.com/1aizxag1')
     #xmlresponse = '<Response> <Message src="' + to_number + '" dst="' + from_number + '" type="sms" callbackUrl="http://plivobin.qa.plivodev.com/1aizxag1" callbackMethod="POST">' + body + '</Message> </Response>'
     return Response(data=r.to_string(), content_type="application/xml")
     return Response(data=data,
                     content_type='application/xml',
                     status=status.HTTP_200_OK)
Beispiel #3
0
def dial():

    # When an outbound call is made and then connected different number using Dial element,
    # you can play a custom caller tone using the dialMusic attribute
	response = plivoxml.ResponseElement()
	response.add(plivoxml.DialElement().add(plivoxml.NumberElement('15671234567', send_digits='wwww2410')))
	return response.to_string()
def conference():
    response = plivoxml.ResponseElement()
    response.add(
        plivoxml.ConferenceElement('My Room',
                                   start_conference_on_enter=False,
                                   end_conference_on_exit=True))
    return responseToXML(response)
    def test_set_methods(self):
        expected_response = '<Response><Speak><emphasis level="strong"><break strength="strong"/>' \
                            '<lang xml:lang="it">This is Test</lang><emphasis level="strong">' \
                            'This is Test</emphasis><phoneme alphabet="ipa" ph="t&amp;#x259;mei&amp;#x325;' \
                            '&amp;#x27E;ou&amp;#x325;">This is Test</phoneme><prosody pitch="low">' \
                            'This is Test</prosody><say-as format="" interpret-as="spell-out">' \
                            'This is Test</say-as><sub alias="World Wide Web Consortium">This is Test' \
                            '</sub><w role="claws:VV0">This is Test</w></emphasis></Speak></Response>'
        level = "strong"
        content_break = 'This is Test'
        strength_break = 'strong'
        time_break = '250ms'

        content_lang = 'This is Test'
        xmllang_lang = "it"

        content_emphasis = 'This is Test'
        level_emphasis = 'strong'

        content_phoneme = 'This is Test'
        alphabet_phoneme = "ipa"
        ph_phoneme = "t&#x259;mei&#x325;&#x27E;ou&#x325;"

        content_prosody = "This is Test"
        volume_prosody = "+6dB"
        rate_prosody = "x-high"
        pitch_prosody = "low"

        content_say_as = 'This is Test'
        interpret_as_say_as = "spell-out"
        format_say_as = ""

        content_sub = "This is Test"
        alias_sub = "World Wide Web Consortium"

        content_w = "This is Test"
        role_w = "claws:VV0"

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.SpeakElement("").add(
                plivoxml.EmphasisElement().set_level(level).add_break(
                    strength=strength_break).add_lang(
                        content_lang, xmllang=xmllang_lang).add_emphasis(
                            content_emphasis,
                            level=level_emphasis).add_phoneme(
                                content_phoneme,
                                alphabet=alphabet_phoneme,
                                ph=ph_phoneme).add_prosody(
                                    content_prosody,
                                    pitch=pitch_prosody).add_say_as(
                                        content_say_as,
                                        interpret_as=interpret_as_say_as,
                                        format=format_say_as).add_sub(
                                            content_sub,
                                            alias=alias_sub,
                                        ).add_w(content_w,
                                                role_w))).to_string(False)
        self.assertEqual(response, expected_response)
def moderated():
    response = plivoxml.ResponseElement()
    response.add(
        plivoxml.ConferenceElement('My Room',
                                   start_conference_on_enter=True,
                                   end_conference_on_exit=True,
                                   record=True))
    return responseToXML(response)
    def test_set_methods(self):
        expected_response = '<Response><Speak>substitution example <sub alias="World Wide Web Consortium">W3C</sub></Speak></Response>'
        alias = "World Wide Web Consortium"

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.SpeakElement("substitution example ").add(
                plivoxml.SubElement("W3C").set_alias(alias))).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #8
0
def ivr():
    r = plivoxml.ResponseElement()
    if request.method == 'GET':
        get_digits_action_url = url_for('phone.ivr', _external=True)
        getDigits = plivoxml.GetDigitsElement(action=get_digits_action_url,
                                              method='POST',
                                              timeout=7,
                                              retries=1)
        getDigits.add_speak(
            ''' Thank you for calling Aldora Capital Partners incorporated.
        if you would like to get information about our lending products. Please press one.
        If you are a broker. And would like to partner with us, to help your clients better. Please press two.
        If you know your parties extension, please press three. 
        For all other inquiries please press zero.  
        ''')

        r.add(getDigits)
        r.add_speak(
            'No input recieved. Thank you for contacting Aldora Capital.')
        return Response(r.to_string(), mimetype='text/xml')

    if request.method == 'POST':
        digit = request.form.get('Digits')
        if digit == '1':
            message = ' We are routing your call to a nearest in house specialist, if they do not pick up the phone, leave them a message and they will get back to you.'

            call_number = phone_tools.get_number(role='sales')
            return phone_tools.get_forward(request,
                                           forward_number=call_number,
                                           message=message)

        elif digit == '2':
            r.add_speak(''' Thank you for your interest in partnering with us.

Please use the contact us page on our website: www.aldora . capital.com
            .And someone from our team will contact you as soon as possible..'''
                        )
        elif digit == '3':
            r.add_redirect(url_for('phone.call_router', _external=True),
                           method='GET')

        elif digit == '0':
            call_number = phone_tools.get_number(role='help')
            return phone_tools.get_forward(request,
                                           forward_number=call_number,
                                           message='Calling Help line.')

        elif len(str(digit)) > 0:
            return phone_tools.get_forward(
                request,
                extension=digit,
                message='Getting Forward to extension')

        else:
            r.add_speak('No input detected, Hanging up.')
        return Response(r.to_string(), mimetype='text/xml')
Beispiel #9
0
    def test_set_methods(self):
        expected_response = '<Response><Play loop="1">This is test</Play></Response>'

        loop = 1
        content = 'This is test'
        element = plivoxml.ResponseElement()

        response = element.add(
            plivoxml.PlayElement(content).set_loop(loop)).to_string(False)
        self.assertEqual(response, expected_response)
 def test_set_methods(self):
     time = "1000ms"
     strength = "x-strong"
     expected_response = '<Response><Speak voice="Polly.Joey">Break of<break strength="x-strong" time="1000ms"/> one second or same as paragraph </Speak></Response>'
     element = plivoxml.ResponseElement()
     response = element.add(
         plivoxml.SpeakElement("Break of", "Polly.Joey").add(
             plivoxml.BreakElement().set_strength(strength).set_time(time)).
         add_cont("one second or same as paragraph")).to_string(False)
     self.assertEqual(response, expected_response)
    def test_set_methods(self):
        schedule = 60
        reason = "rejected"
        expected_response = '<Response><Hangup reason="rejected" schedule="60"/></Response>'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.HangupElement().set_reason(reason).set_schedule(schedule)
        ).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #12
0
    def test_set_methods(self):
        expected_response = '<Response><Conference action="http://foo.com/get_recording/" callbackMethod="GET"' \
                            ' callbackUrl="http://foo.com/sms_status/" digitsMatch="#0,99,000"' \
                            ' endConferenceOnExit="true" enterSound="" exitSound="beep:1" floorEvent="true"' \
                            ' hangupOnStar="true" maxMembers="100" method="GET" muted="false" record="true"' \
                            ' recordFileFormat="mp3" recordWhenAlone="" redirect="true" relayDTMF="true"' \
                            ' sendDigits="wwww2410" startConferenceOnEnter="true" stayAlone="true" timeLimit="600"' \
                            ' transcriptionMethod="POST" transcriptionType="auto"' \
                            ' transcriptionUrl="http://www.foo.com/waitmusic/"' \
                            ' waitSound="http://www.foo.com/waitmusic/"/></Response>'
        muted = False
        enter_sound = ""
        exit_sound = "beep:1"
        start_conference_on_enter = True
        end_conference_on_exit = True
        stay_alone = True
        wait_sound = "http://www.foo.com/waitmusic/"
        max_members = 100
        record = True
        record_file_format = "mp3"
        time_limit = 600
        hangup_on_star = True
        action = "http://foo.com/get_recording/"
        method = "GET"
        callback_url = "http://foo.com/sms_status/"
        callback_method = "GET"
        digits_match = "#0,99,000"
        floor_event = True
        redirect = True
        relay_dtmf = True
        send_digits = "wwww2410"
        record_when_alone = ""
        transcription_type = "auto"
        transcription_url = "http://www.foo.com/waitmusic/"
        transcription_method = "POST"

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.ConferenceElement().set_muted(muted).set_enter_sound(
                enter_sound).set_exit_sound(exit_sound).
            set_start_conference_on_enter(start_conference_on_enter).
            set_end_conference_on_exit(end_conference_on_exit).set_stay_alone(
                stay_alone).set_wait_sound(wait_sound).set_max_members(
                    max_members).set_record(record).set_record_file_format(
                        record_file_format).set_time_limit(time_limit).
            set_hangup_on_star(hangup_on_star).set_action(action).set_method(
                method).set_callback_url(callback_url).set_callback_method(
                    callback_method).set_digits_match(digits_match).
            set_floor_event(floor_event).set_redirect(redirect).set_relay_dtmf(
                relay_dtmf).set_send_digits(send_digits).
            set_record_when_alone(record_when_alone).set_transcription_type(
                transcription_type).set_transcription_url(transcription_url).
            set_transcription_method(transcription_method)).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #13
0
    def test_set_methods(self):
        expected_response = '<Response><Redirect method="POST">This is Test</Redirect></Response>'

        method = "POST"
        content = 'This is Test'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.RedirectElement(content).set_method(method)).to_string(
                False)

        self.assertEqual(response, expected_response)
    def test_set_methods(self):
        alphabet = "ipa"
        ph = "t&#x259;mei&#x325;&#x27E;ou&#x325;"
        expected_response = '<Response><Speak><phoneme alphabet="ipa" ph="t&amp;#x259;mei&amp;' \
                            '#x325;&amp;#x27E;ou&amp;#x325;">Well</phoneme></Speak></Response>'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.SpeakElement("").add(
                plivoxml.PhonemeElement("Well").set_alphabet(alphabet).set_ph(
                    ph))).to_string(False)
        self.assertEqual(response, expected_response)
    def test_set_methods(self):
        expected_response = '<Response><GetInput action="https://foo.example.com" digitEndTimeout="50" ' \
                            'executionTimeout="100" finishOnKey="#" hints="1 2 3" inputType="speech" ' \
                            'interimSpeechResultsCallback="https://bar.example.com" ' \
                            'interimSpeechResultsCallbackMethod="POST" language="en-US" log="true" method="GET" ' \
                            'numDigits="2" redirect="false" speechEndTimeout="25" ' \
                            'speechModel="default"><Speak language="en-US" loop="2" ' \
                            'voice="WOMAN">This is test</Speak><Play loop="2">This is test' \
                            '</Play></GetInput></Response>'

        action = 'https://foo.example.com'
        method = 'GET'
        inputType = 'speech'
        executionTimeout = 100
        digitEndTimeout = 50
        speechEndTimeout = 25
        finishOnKey = '#'
        numDigits = 2
        speechModel = 'default'
        hints = '1 2 3'
        language = 'en-US'
        interimSpeechResultsCallback = 'https://bar.example.com'
        interimSpeechResultsCallbackMethod = 'POST'
        redirect = False
        log = True

        content_speak = 'This is test'
        voice_speak = 'WOMAN'
        language_speak = 'en-US'
        loop_speak = 2
        loop_play = 2
        content_play = 'This is test'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.GetInputElement().set_action(action).set_method(method).
            set_input_type(inputType).set_execution_timeout(executionTimeout).
            set_digit_end_timeout(digitEndTimeout).set_speech_end_timeout(speechEndTimeout).
            set_finish_on_key(finishOnKey).set_num_digits(numDigits).
            set_hints(hints).set_interim_speech_results_callback(interimSpeechResultsCallback).
            set_interim_speech_results_callback_method(interimSpeechResultsCallbackMethod).set_log(log).
            set_redirect(redirect).set_language(language).set_speech_model(speechModel).
            add_speak(
                content=content_speak,
                voice=voice_speak,
                language=language_speak,
                loop=loop_speak).add_play(
                content=content_play, loop=loop_play)
        ).to_string(False)
        self.assertEqual(response, expected_response)
    def test_set_methods(self):
        expected_response = '<Response><Wait beep="true" length="1" minSilence="1" silence="true"/></Response>'

        length = 1
        silence = True
        min_silence = 1
        beep = True

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.WaitElement().set_length(length).set_silence(silence).
            set_min_silence(min_silence).set_beep(beep)).to_string(False)

        self.assertEqual(response, expected_response)
Beispiel #17
0
 def test_complex(self):
     self.assertEqual(
         plivoxml.ResponseElement().add(
             plivoxml.MessageElement('text', '123', '456')).add(
                 plivoxml.ConferenceElement('name')).add(
                     plivoxml.DTMFElement('123')).add(
                         plivoxml.WaitElement()).add(
                             plivoxml.SpeakElement('Hello')).
         add(plivoxml.PreAnswerElement().add_speak('Hello')).add(
             plivoxml.PlayElement('url')).add(
                 plivoxml.DialElement().set_caller_name('Test').add(
                     plivoxml.NumberElement('123').set_send_on_preanswer(
                         True))).to_string(),
         '<Response><Message dst="456" src="123">text</Message><Conference>name</Conference><DTMF>123</DTMF><Wait></Wait><Speak>Hello</Speak><PreAnswer><Speak>Hello</Speak></PreAnswer><Play>url</Play><Dial callerName="Test"><Number sendOnPreanswer="true">123</Number></Dial></Response>\n'
     )
Beispiel #18
0
    def test_set_methods(self):
        expected_response = '<Response><Speak><say-as format="application/ssml+xml" interpret-as="spell-out">' \
                            'This is Test</say-as></Speak></Response>'
        interpret_as = "spell-out"
        format = "application/ssml+xml"
        content = 'This is Test'

        element = plivoxml.ResponseElement()

        response = element.add(
            plivoxml.SpeakElement("").add(
                plivoxml.SayAsElement(content).set_interpret_as(
                    interpret_as).set_format(format))).to_string(False)

        self.assertEqual(response, expected_response)
    def test_set_methods(self):
        expected_response = '<Response><Dial><User sendDigits="wwww2410" sendOnPreanswer="true" ' \
                            'sipHeaders="head1=val1,head2=val2">This is Test</User></Dial></Response>'

        content = 'This is Test'
        send_digits = 'wwww2410'
        send_on_preanswer = True
        sip_headers = 'head1=val1,head2=val2'

        element = plivoxml.ResponseElement()

        response = element.add(plivoxml.DialElement().add(
            plivoxml.UserElement(content).set_send_digits(send_digits).
            set_send_on_preanswer(send_on_preanswer).set_sip_headers(
                sip_headers))).to_string(False)
        self.assertEqual(response, expected_response)
    def test_set_methods(self):

        expected_response = '<Response><Message callbackMethod="GET" callbackUrl="http://foo.example.com" dst="1203443444&lt;1203443445" src="1202322222" type="sms">this is test</Message></Response>'
        src = '1202322222'
        dst = '1203443444<1203443445'
        type = 'sms'
        callbackUrl = 'http://foo.example.com'
        callbackMethod = 'GET'
        content = 'this is test'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.MessageElement(content).set_src(src).set_dst(dst).
            set_type(type).set_callback_url(callbackUrl).set_callback_method(
                callbackMethod)).to_string()
        self.assertEqual(response, expected_response + '\n')
Beispiel #21
0
def call_router():
    r = plivoxml.ResponseElement()

    if request.method == 'GET':
        call_router_url = url_for('phone.call_router', _external=True)
        getDigits = plivoxml.GetDigitsElement(action=call_router_url,
                                              method='POST',
                                              timeout=10,
                                              digit_timeout=3,
                                              retries=1)
        r.add(getDigits)
        getDigits.add_speak('Please enter the extension now.')
        return Response(r.to_string(), mimetype='text/xml')

    if request.method == 'POST':
        extension = request.form.get('Digits')
        return phone_tools.get_forward(request, extension)
 def test_add_speak(self):
     response = plivoxml.ResponseElement()
     response.add(
         plivoxml.SpeakElement(
             'Please leave a message after the beep. Press the star key when done.'
         ))
     response.add(
         plivoxml.RecordElement(
             action='http://foo.com/get_recording/',
             max_length=30,
             finish_on_key='*'))
     response.add(plivoxml.SpeakElement('Recording not received.'))
     elem = response.to_string()
     self.assertEqual(
         elem,
         '<Response><Speak>Please leave a message after the beep. Press the star key when done.</Speak><Record action="http://foo.com/get_recording/" finishOnKey="*" maxLength="30"></Record><Speak>Recording not received.</Speak></Response>\n'
     )
    def test_set_methods(self):
        expected_response = '<Response><Dial><Number sendDigits="wwww2410" sendDigitsMode=""' \
                            ' sendOnPreanswer="true">This is Test</Number></Dial></Response>'

        content = 'This is Test'
        send_digits = 'wwww2410'
        send_on_preanswer = True
        send_digits_mode = ""

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.DialElement().add(
                plivoxml.NumberElement(content).set_send_digits(send_digits).set_send_on_preanswer(
                    send_on_preanswer
                ).set_send_digits_mode(
                    send_digits_mode
                )
            )
        ).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #24
0
    def test_set_methods(self):
        expected_response = '<Response><GetDigits action="https://foo.example.com" digitTimeout="10"' \
            ' finishOnKey="#" invalidDigitsSound="http://foo.audio.url" log="true" method="GET"' \
            ' numDigits="2" playBeep="false" redirect="false" retries="1" timeout="100"' \
            ' validDigits="*"><Speak language="en-US" loop="2" voice="WOMAN">This is test</Speak>' \
            '<Play loop="2">This is test</Play></GetDigits></Response>'

        action = 'https://foo.example.com'
        method = 'GET'
        timeout = 100
        digitTimeout = 10
        finishOnKey = '#'
        numDigits = 2
        retries = True
        redirect = False
        playBeep = False
        validDigits = '*'
        invalidDigitsSound = 'http://foo.audio.url'
        log = True

        content_speak = 'This is test'
        voice_speak = 'WOMAN'
        language_speak = 'en-US'
        loop_speak = 2
        loop_play = 2
        content_play = 'This is test'

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.GetDigitsElement().set_action(action).set_method(method).
            set_redirect(redirect).set_timeout(timeout).set_play_beep(playBeep)
            .set_finish_on_key(finishOnKey).set_digit_timeout(digitTimeout).
            set_timeout(timeout).set_num_digits(numDigits).set_retries(retries)
            .set_valid_digits(validDigits).set_invalid_digits_sound(
                invalidDigitsSound).set_log(log).add_speak(
                    content=content_speak,
                    voice=voice_speak,
                    language=language_speak,
                    loop=loop_speak).add_play(
                        content=content_play, loop=loop_play)).to_string(False)
        self.assertEqual(response, expected_response)
Beispiel #25
0
def get_forward(request,
                extension=False,
                forward_number=False,
                message='Forwarding Now'):
    r = plivoxml.ResponseElement()
    if forward_number == False:
        forward_number = get_number(extension)

    if forward_number == 'Fail':
        r.add_speak('No individual found with that extension')
        return Response(r.to_string(), mimetype='text/xml')

    from_number = request.form.get('From')
    xml_data = '''<Response>
        <Speak>{}</Speak>
        <Dial callerId="{}">
            <Number>{}</Number>
        </Dial>
    </Response>
    '''.format(message, from_number, forward_number)
    print(xml_data)
    return Response(xml_data, mimetype='text/xml')
 def test_add_record(self):
     action = 'https://foo.example.com'
     elem = plivoxml.ResponseElement().add_record(action=action).to_string()
     expected_response = '<Response><Record action="https://foo.example.com"></Record></Response>\n'
     self.assertEqual(elem, expected_response)
 def test_add_redirect(self):
     content = 'dummy'
     elem = plivoxml.ResponseElement().add_redirect(
         content=content).to_string()
     self.assertEqual(elem,
                      '<Response><Redirect>dummy</Redirect></Response>\n')
Beispiel #28
0
    def test_set_methods(self):
        expected_response = '<Response><PreAnswer><Speak language="en-US" loop="2" voice="WOMAN">This is test' \
                            '</Speak><Play loop="2">This is test</Play><Wait beep="true" length="1" ' \
                            'minSilence="1" silence="true"/><GetDigits ' \
                            'action="http://www.foo.com/gather_pin/" digitTimeout="2" finishOnKey="#" ' \
                            'invalidDigitsSound="https://s3.amazonaws.com/Trumpet.mp3" log="true" ' \
                            'method="POST" numDigits="1" playBeep="true" redirect="true" retries="1" ' \
                            'timeout="5" validDigits="1234567890*#"/><Redirect method="POST">' \
                            'This is test</Redirect><Message callbackMethod="GET" ' \
                            'callbackUrl="http://foo.example.com" dst="1203443444&lt;1203443445" ' \
                            'src="1202322222" type="sms">this is test</Message><DTMF async="true">this is test' \
                            '</DTMF></PreAnswer></Response>'

        content_speak = 'This is test'
        voice_speak = 'WOMAN'
        language_speak = 'en-US'
        loop_speak = 2
        loop_play = 2
        content_play = 'This is test'
        length_wait = 1
        silence_wait = True
        min_silence_wait = 1
        beep_wait = True

        action_get_digits = 'http://www.foo.com/gather_pin/'
        method_get_digits = 'POST'
        timeout_get_digits = 5
        digit_timeout_get_digits = 2
        finish_on_key_get_digits = '#'
        num_digits_get_digits = 1
        retries_get_digits = 1
        redirect_get_digits = True
        play_beep_get_digits = True
        valid_digits_get_digits = '1234567890*#'
        invalid_digits_sound_get_digits = 'https://s3.amazonaws.com/Trumpet.mp3'
        log_get_digits = True

        content_redirect = 'This is test'
        method_redirect = "POST"

        src_message = '1202322222'
        dst_message = '1203443444<1203443445'
        type_message = 'sms'
        callback_url_message = 'http://foo.example.com'
        callback_method_message = 'GET'
        content_message = 'this is test'

        content_dtmf = 'this is test'
        async_dtmf = True

        element = plivoxml.ResponseElement()
        response = element.add(plivoxml.PreAnswerElement().add_speak(
            content=content_speak,
            voice=voice_speak,
            language=language_speak,
            loop=loop_speak).add_play(
                content=content_play, loop=loop_play).add_wait(
                    length=length_wait,
                    silence=silence_wait,
                    min_silence=min_silence_wait,
                    beep=beep_wait,
                ).add_get_digits(
                    action=action_get_digits,
                    method=method_get_digits,
                    timeout=timeout_get_digits,
                    digit_timeout=digit_timeout_get_digits,
                    finish_on_key=finish_on_key_get_digits,
                    num_digits=num_digits_get_digits,
                    retries=retries_get_digits,
                    redirect=redirect_get_digits,
                    play_beep=play_beep_get_digits,
                    valid_digits=valid_digits_get_digits,
                    invalid_digits_sound=invalid_digits_sound_get_digits,
                    log=log_get_digits,
                ).add_redirect(
                    content=content_redirect,
                    method=method_redirect,
                ).add_message(
                    content=content_message,
                    src=src_message,
                    dst=dst_message,
                    type=type_message,
                    callback_url=callback_url_message,
                    callback_method=callback_method_message,
                ).add_dtmf(
                    content=content_dtmf,
                    async_=async_dtmf,
                )).to_string(False)

        self.assertEqual(response, expected_response)
Beispiel #29
0
 def test_simple(self):
     self.assertEqual(plivoxml.ResponseElement().to_string(),
                      '<Response></Response>\n')
    def test_set_methods(self):
        expected_response = '<Response><Speak language="en-US" loop="1" voice="Polly.Joey">This is Test' \
                            '<break time="250ms"/><emphasis ' \
                            'level="strong">This is Test</emphasis><lang xml:lang="it">This is Test</lang>' \
                            '<p>This is Test</p><phoneme alphabet="ipa" ph="t&amp;#x259;mei&amp;#x325;' \
                            '&amp;#x27E;ou&amp;#x325;">This is Test</phoneme><prosody pitch="low" ' \
                            'rate="x-high" volume="+6dB">This is Test</prosody><s>This is Test</s>' \
                            '<say-as format="" interpret-as="spell-out">This is Test</say-as>' \
                            '<sub alias="World Wide Web Consortium">This is Test</sub><w role="claws:VV0">' \
                            'This is Test</w></Speak></Response>'

        voice = 'Polly.Joey'
        language = 'en-US'
        loop = 1
        content = 'This is Test'

        content_break = 'This is Test'
        strength_break = 'strong'
        time_break = '250ms'

        content_lang = 'This is Test'
        xmllang_lang = "it"

        content_p = 'This is Test'

        content_emphasis = 'This is Test'
        level_emphasis = 'strong'

        content_phoneme = 'This is Test'
        alphabet_phoneme = "ipa"
        ph_phoneme = "t&#x259;mei&#x325;&#x27E;ou&#x325;"

        content_prosody = "This is Test"
        volume_prosody = "+6dB"
        rate_prosody = "x-high"
        pitch_prosody = "low"

        content_s = "This is Test"

        content_say_as = 'This is Test'
        interpret_as_say_as = "spell-out"
        format_say_as = ""

        content_sub = "This is Test"
        alias_sub = "World Wide Web Consortium"

        content_w = "This is Test"
        role_w = "claws:VV0"

        element = plivoxml.ResponseElement()
        response = element.add(
            plivoxml.SpeakElement(content).set_voice(voice).set_language(
                language
            ).set_loop(
                loop
            ).add_break(
                time=time_break
            ).add_emphasis(
                content_emphasis,
                level=level_emphasis
            ).add_lang(
                content_lang,
                xmllang=xmllang_lang
            ).add_p(
                content_p
            ).add_phoneme(
                content_phoneme,
                alphabet=alphabet_phoneme,
                ph=ph_phoneme
            ).add_prosody(
                content_prosody,
                volume=volume_prosody,
                rate=rate_prosody,
                pitch=pitch_prosody
            ).add_s(
                content_s
            ).add_say_as(
                content_say_as,
                interpret_as=interpret_as_say_as,
                format=format_say_as
            ).add_sub(
                content_sub,
                alias=alias_sub,
            ).add_w(
                content_w,
                role_w
            )
        ).to_string(False)
        self.assertEqual(response, expected_response)