Esempio n. 1
0
    def test_add(self):
        play = Mc.play('testing file')

        builder = McBuilder()
        builder.add(play)
        self.assertEqual(1, len(builder.build()))
        self.assertEqual(play.get_request_data(), builder.build()[0])

        play.set_files('testing file2')
        builder.add(play)
        self.assertEqual(2, len(builder.build()))
        self.assertEqual(play.get_request_data(), builder.build()[1])
Esempio n. 2
0
def ivr_play(digit, call):
    """
    Returns an Mc object for playing an URL file, or saying bye statements
    """
    mocean_command = McBuilder()

    # Create mocean commands for say action
    english_reject_say_action = Mc.say('Ok bye!')
    chinese_reject_say_action = Mc.say('那再见啦!').set_language('cmn-CN')

    # Sample music from downloaded from:
    # http://amachamusic.chagasi.com/music_konekonoosanpo.html
    play_action = Mc.play(
        f'http://{call.host}/audio/konekonoosanpo.mp3')  # nopep8

    if digit is not None and len(digit) > 0:
        mocean_command.add(play_action)
    else:
        if call.language == LanguageChoice.LANG_CNM_CN:
            mocean_command.add(chinese_reject_say_action)
        else:
            # default to english
            mocean_command.add(english_reject_say_action)

    return mocean_command
Esempio n. 3
0
def ivr_end(call):
    # Creates empty mocean_command and delete call, this should end
    # the call on Mocean VoiceGW
    logging.error(
        f'Call state should have ended on CALL_GET_CONSENT, current callstate: {call.state}'
    )  # nopep8
    return McBuilder()
Esempio n. 4
0
    def test_setter_method(self):
        voice = self.get_client_obj().voice

        voice.set_to('test to')
        self.assertIsNotNone(voice._params['mocean-to'])
        self.assertEqual('test to', voice._params['mocean-to'])

        voice.set_event_url('test event url')
        self.assertIsNotNone(voice._params['mocean-event-url'])
        self.assertEqual('test event url', voice._params['mocean-event-url'])

        voice.set_mocean_command('test mocean command')
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual('test mocean command',
                         voice._params['mocean-command'])

        voice.set_resp_format('json')
        self.assertIsNotNone(voice._params['mocean-resp-format'])
        self.assertEqual('json', voice._params['mocean-resp-format'])

        # test multiple call control commands
        voice = self.get_client_obj().voice
        voice.set_mocean_command([{'action': 'say'}])
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps([{
            'action': 'say'
        }]), voice._params['mocean-command'])

        voice = self.get_client_obj().voice
        builder_params = McBuilder().add(Mc.say("hello world"))
        voice.set_mocean_command(builder_params)
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps(builder_params.build()),
                         voice._params['mocean-command'])

        voice = self.get_client_obj().voice
        mc_params = Mc.say('hello world')
        voice.set_mocean_command(mc_params)
        self.assertIsNotNone(voice._params['mocean-command'])
        self.assertEqual(json.dumps(McBuilder().add(mc_params).build()),
                         voice._params['mocean-command'])
Esempio n. 5
0
def ivr_init(call):
    """
    Returns mocean command JSON when it first initialised
    """
    # Create mocean commands for say action
    record_action = Mc.record()
    english_say_action = Mc.say(
        'Welcome to Mocean Voice IVR. For English, please press 1.'
    ).set_barge_in(True)  # nopep8
    chinese_say_action = Mc.say('中文请按二').set_language('cmn-CN').set_barge_in(
        True)  # nopep8
    # Create mocean command for collect
    collect_action = Mc.collect(f'http://{call.host}/voice/collect-command')
    collect_action.set_minimum(1).set_maximum(1).set_timeout(5000)

    # Adding mocean_command actions into mocean_command
    mocean_command = McBuilder()  # create builder
    mocean_command.add(record_action)  # adding record actions
    mocean_command.add(english_say_action)  # say it in english
    mocean_command.add(chinese_say_action)  # say it in chinese
    mocean_command.add(collect_action)  # adding collect action

    return False, mocean_command.build()
Esempio n. 6
0
 def test_throw_exception_for_add_method_pass_in_non_mc_object(self):
     try:
         McBuilder().add('abc')
         self.fail()
     except MoceanErrorException:
         pass
Esempio n. 7
0
def ivr_get_language(digit, call):
    """
    Returns an Mc object for 2nd phase of IVR
    """

    # Define a mocean command builder
    mocean_command = McBuilder()
    # Create mocean commands for say action
    english_say_action = Mc.say(
        'Would you like to listen to some music? Press any key to proceed.'
    ).set_barge_in(True)  # nopep8
    chinese_say_action = Mc.say('你想听听音乐吗?若想,请按任意一键').set_language(
        'cmn-CN').set_barge_in(True)  # nopep8
    english_say_action_proceed = Mc.say(
        'Invalid input, we would assume you have picked English').set_barge_in(
            True)  # nopep8

    # Cleansing digit cache
    english_say_action.set_clear_digit_cache(True)
    chinese_say_action.set_clear_digit_cache(True)
    english_say_action_proceed.set_clear_digit_cache(True)

    # Create mocean command for collect
    collect_action = Mc.collect(f'http://{call.host}/voice/collect-command')
    collect_action.set_minimum(1).set_maximum(1).set_timeout(5000)
    # set a random character to avoid default '#' character termination
    collect_action.set_terminators('x')

    if is_digit(digit):
        # Convert input string into number
        digit = float(digit)
        if digit == 1:
            # Pressed 1 for english
            mocean_command.add(english_say_action)
            call.set_language(LanguageChoice.LANG_EN_US)
        elif digit == 2:
            # Pressed 2 for chinese
            mocean_command.add(chinese_say_action)
            call.set_language(LanguageChoice.LANG_CNM_CN)
        else:
            # Invalid input, but we should assume English and proceed
            mocean_command.add(english_say_action_proceed)
            # Since english_say_action_proceed has cleared digit cache
            # we should not clear digit cache for the subsequent actions
            english_say_action.set_clear_digit_cache(False)
            mocean_command.add(english_say_action)
            call.set_language(LanguageChoice.LANG_EN_US)
        # Add a collect action for proceeding action
        mocean_command.add(collect_action)
    else:
        mocean_command.add(english_say_action_proceed)
        # Since english_say_action_proceed has cleared digit cache
        # we should not clear digit cache for the subsequent actions
        english_say_action.set_clear_digit_cache(False)
        mocean_command.add(english_say_action)
        call.set_language(LanguageChoice.LANG_EN_US)
        # Add a collect action for proceeding action
        mocean_command.add(collect_action)
    return mocean_command