コード例 #1
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        texts = locale_functions.get_locale_texts(handler_input)

        attr = handler_input.attributes_manager.session_attributes

        question_obj = db_functions.get_question(attr['question_id'])

        speech_text = None

        if attr.get('state') == STATES['QUESTION_ASKED']:
            speech_text = '{}, {}'.format(question_obj['question'],
                                          texts.TRUE_FALSE_TEXT)
            (handler_input.response_builder.speak(speech_text).set_card(
                SimpleCard(texts.SKILL_NAME,
                           speech_text)).ask(texts.TRUE_FALSE_TEXT))
        elif attr.get('state') == STATES['QUESTION_ANSWERED']:
            speech_text = '{}, {}'.format(question_obj['more_info'],
                                          texts.NEW_ANSWER_TEXT)
            (handler_input.response_builder.speak(speech_text).set_card(
                SimpleCard(texts.SKILL_NAME,
                           speech_text)).ask(texts.NEW_ANSWER_TEXT))
        elif attr.get('state') == STATES['INITIALIZED']:
            (handler_input.response_builder.speak(texts.HELLO_TEXT).set_card(
                SimpleCard(texts.SKILL_NAME,
                           texts.HELLO_TEXT)).ask(texts.HELLO_REPROMPT_TEXT))

        return handler_input.response_builder.response
コード例 #2
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        texts = locale_functions.get_locale_texts(handler_input)

        (handler_input.response_builder.speak(texts.EXIT_TEXT).set_card(
            SimpleCard(texts.SKILL_NAME,
                       texts.EXIT_TEXT)).set_should_end_session(True))

        return handler_input.response_builder.response
コード例 #3
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        texts = locale_functions.get_locale_texts(handler_input)

        (handler_input.response_builder.speak(texts.HELP_TEXT).set_card(
            SimpleCard(texts.SKILL_NAME,
                       texts.HELP_TEXT)).ask(texts.HELLO_REPROMPT_TEXT))

        return handler_input.response_builder.response
    def handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> Response
        logger.get_logger().error(exception, exc_info=True)

        texts = locale_functions.get_locale_texts(handler_input)

        (handler_input.response_builder.speak(texts.EXCEPTION_TEXT).set_card(
            SimpleCard(texts.SKILL_NAME, texts.EXCEPTION_TEXT)).ask(
                texts.EXCEPTION_REPROMPT_TEXT))

        return handler_input.response_builder.response
コード例 #5
0
    def handle(self, handler_input):
        texts = locale_functions.get_locale_texts(handler_input)

        speech_text = '{} {}'.format(texts.START_OVER_TEXT, question_functions.new_question_process(handler_input, texts))

        (handler_input.response_builder
            .speak(speech_text)
            .set_card(SimpleCard(texts.SKILL_NAME, speech_text))
            .ask(texts.TRUE_FALSE_TEXT))

        return handler_input.response_builder.response
コード例 #6
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        texts = locale_functions.get_locale_texts(handler_input)

        speech_text = question_functions.new_question_process(handler_input, texts)

        (handler_input.response_builder
            .speak(speech_text)
            .set_card(SimpleCard(texts.SKILL_NAME, speech_text))
            .ask(speech_text))

        return handler_input.response_builder.response
コード例 #7
0
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        texts = locale_functions.get_locale_texts(handler_input)

        attr = handler_input.attributes_manager.session_attributes

        attr['state'] = STATES['INITIALIZED']

        handler_input.attributes_manager.session_attributes = attr

        (handler_input.response_builder.speak(texts.HELLO_TEXT).set_card(
            SimpleCard(texts.SKILL_NAME,
                       texts.HELLO_TEXT)).ask(texts.HELLO_REPROMPT_TEXT))

        return handler_input.response_builder.response
    def handle(self, handler_input):
        # type: (HandlerInput) -> Response

        texts = locale_functions.get_locale_texts(handler_input)

        attr = handler_input.attributes_manager.session_attributes
        attr['state'] = STATES['QUESTION_ANSWERED']

        handler_input.attributes_manager.session_attributes = attr

        question_obj = db_functions.get_question(attr['question_id'])

        slots = handler_input.request_envelope.request.intent.slots

        user_answer = misc_functions.parse_boolean_slot(slots.get("response"))

        logger.get_logger().info(
            'QuestionAnswerIntentHandler user answer: {}'.format(user_answer))

        speech_text = ''

        if question_functions.check_correct_answer(question_obj, user_answer):
            speech_text = '<say-as interpret-as="interjection">{}</say-as>. '.format(
                random.choice(texts.CORRECT_ANSWER_SPEECHCONS))

            speech_text_card = '{}. '.format(
                random.choice(texts.CORRECT_ANSWER_SPEECHCONS))
        else:
            speech_text = '<say-as interpret-as="interjection">{}</say-as>, no es correcto. '.format(
                random.choice(texts.INCORRECT_ANSWER_SPEECHCONS))

            speech_text_card = '{}, no es correcto. '.format(
                random.choice(texts.INCORRECT_ANSWER_SPEECHCONS))

        speech_text += '{}. {}'.format(question_obj['more_info'],
                                       texts.NEW_ANSWER_TEXT)
        speech_text_card += '{}. {}'.format(question_obj['more_info'],
                                            texts.NEW_ANSWER_TEXT)

        (handler_input.response_builder.speak(speech_text).set_card(
            SimpleCard(texts.SKILL_NAME,
                       speech_text_card)).ask(texts.NEW_ANSWER_TEXT))

        return handler_input.response_builder.response