def process(self, handler_input, response):
        # type (HandlerInput, Response)
        if (
            (handler_input.request_envelope.session.new == True) or
            is_request_type("SessionEndedRequest")(handler_input) or
            not response
        ):
            return

        try:
            prompt = response.reprompt.output_speech.ssml
            LastPrompt.save_last_prompt_str(handler_input, prompt)
        except Exception as e:
            logger.warning(f"CacheRepromptInterceptor   {e}")
        return
Example #2
0
    def handle(self, handler_input):
        logger.info("HAN  FP_SetTimesTablesHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        ## Get & Set slots
        lower_table, upper_table, tables_query = (
            FreePlayAttr.get_times_table_input_slots(handler_input))

        ## Logic checks
        retry_query = attr.get('inform_query_tables_format', False)
        tables_provided = FreePlayLogic.check_tables_provided(
            lower_table, upper_table, tables_query)

        if tables_provided:
            FreePlayAttr.set_attr_free_play(handler_input)
            FreePlayAttr.set_attr_times_tables(handler_input, lower_table,
                                               upper_table, tables_query)

            if retry_query:
                ms_potential_mistake = FPTimesTables.get_ms_potential_mistake_parsing_query(
                )
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_potential_mistake, 2)
            else:
                ms_confirm = ConfirmUtils.get_random_confirmation(
                    handler_input)
                speech_list.append(ms_confirm)

            ms_using_tables = (FPTimesTables.get_ms_using_tables_from_input(
                lower_table, upper_table, tables_query))
            speech_list += Pauser.make_ms_pause_level_list(ms_using_tables, 2)

            if retry_query:
                ms_retry_query = FPTimesTables.get_ms_can_retry_query_format()
                speech_list += Pauser.make_ms_pause_level_list(
                    ms_retry_query, 3.5)
                FreePlayAttr.reset_attr_query_format(handler_input)

            prompt = FPPrompts.get_q_fp_setup_prompt(handler_input)
            reprompt = FPPrompts.get_q_fp_setup_reprompt(handler_input)
            speech_list.append(prompt)

        ## Ask for times_tables slots
        else:
            q_times_tables, reprompt = (
                FPTimesTables.get_q_times_tables_input() for _ in range(2))
            q_times_tables = CardFuncs.format_prompt(q_times_tables)
            speech_list.append(q_times_tables)
            reprompt = LastPrompt.get_last_prompt(handler_input)

        ModeStats.translate_mode_stats_to_sesh(handler_input)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Example #3
0
    def handle(self, handler_input):
        logger.info("HAN  FP_ParametersIntent")
        speech_list = []

        ms_confirm = ConfirmUtils.get_confirmation(True)
        ms_fp_params = FPSpeech.get_ms_fp_parameters(handler_input)

        prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                            for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 1,
                                                       ms_fp_params, 2.5,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def handle(self, handler_input):
        logger.info("HAN    ModeStatsHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []
        player_obj = PlayerDict.load_player_obj(handler_input)

        mode = attr.get('mode', None)
        activity = SlotUtils.get_resolved_value(handler_input, 'activity')
        activity = activity if activity else mode
        difficulty = True

        if activity == 'survival':
            speech_list += ModeSpeech.get_ms_sm_stats(player_obj, activity)

        elif activity == 'speed':
            difficulty = SlotUtils.get_resolved_value(handler_input,
                                                      'difficulty')
            sc_difficulty = difficulty if difficulty else attr.get(
                'sc_difficulty', None)

            if (difficulty in speed_challenge.data.SC_DIFFICULTIES):
                speech_list += ModeSpeech.get_ms_sc_stats(
                    player_obj, sc_difficulty, activity)
            else:
                reprompt = ModeSpeech.get_ms_sc_what_difficulty()
                speech_list += reprompt
                reprompt = get_linear_nlg(reprompt)

        else:
            ms_can_tell_record = ModeSpeech.get_ms_can_tell_record()
            ms_example_saying = ModeSpeech.get_example_hear_records()
            speech_list = [ms_can_tell_record, 2, ms_example_saying]

            reprompt = HelpUtils.get_q_what_todo()

        if activity in ('survival', 'speed') and (difficulty):
            prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                                for _ in range(2))
            speech_list += Pauser.make_ms_pause_level_list(3, prompt)

        speech = get_linear_nlg(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def handle(self, handler_input):
        # type (HandlerInput) -> Response
        logger.info("HAN    HelpHandler")
        speech_list = []

        ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        prompt, reprompt = (
            LastPrompt.get_last_prompt(handler_input) for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list( ms_help, 3, prompt)

        speech = ' '.join(speech_list)
        
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (
            handler_input.response_builder
                .speak(speech)
                .ask(reprompt)
                .set_card( SimpleCard(
                    card_title, card_text))
                .response)
Example #6
0
    def handle(self, handler_input):
        logger.info("HAN    FallbackHandler")
        FallbackUtils.log_fallback_intent(handler_input)
        speech_list = []

        # ms_help = HelpUtils.get_ms_corresponding_help(handler_input)
        ms_prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                               for _ in range(2))

        speech_list.append(data.MS_FALLBACK)
        speech_list.append(Pauser.get_p_level(1))

        ## NOTE: ms_help needs refinement if help after fallback handler.
        ## Develop relevant methods from FallbackUtils.
        # speech_list.append( ms_help)
        speech_list.append(ms_prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
Example #7
0
    def handle(self, handler_input):
        logger.info("HAN    NumQuestionsAnsweredHandler")
        attr = handler_input.attributes_manager.session_attributes
        speech_list = []

        questions_answered = attr.get('questions_answered', 0)
        ms_confirm = ConfirmUtils.get_player_confirmation(handler_input)

        ms_ans_questions = random.choice(
            mult_questions.data.MT_NUM_QUESTIONS_ANS).format(
                questions_answered)

        prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                            for _ in range(2))
        speech_list += Pauser.make_ms_pause_level_list(ms_confirm, 1,
                                                       ms_ans_questions, 2,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)
    def return_unknown_slot_response(handler_input) -> object:
        """If cannot find answer slot, returns same response prompt.
        
        NOTE: Can probably just return last response object.
        """
        speech_list = []
        attr = handler_input.attributes_manager.session_attributes

        ms_not_understand = get_linear_nlg(fallback.data.MMT_NOT_UNDERSTAND)

        if attr.get('mode', None) == 'free_play':
            prompt, reprompt = (GenQuestions.get_same_question(handler_input)
                                for _ in range(2))
        else:
            prompt, reprompt = (LastPrompt.get_last_prompt(handler_input)
                                for _ in range(2))

        speech_list += Pauser.make_ms_pause_level_list(ms_not_understand, 2,
                                                       prompt)

        speech = ' '.join(speech_list)
        card_title, card_text = CardFuncs.get_card_info(handler_input, speech)
        return (handler_input.response_builder.speak(speech).ask(
            reprompt).set_card(SimpleCard(card_title, card_text)).response)