Exemplo n.º 1
0
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .response
        )

# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.


sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(GetCurrentTemperatureIntentHandler())
sb.add_request_handler(GetDesiredTemperatureIntentHandler())
sb.add_request_handler(SetDesiredTemperatureIntentHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
    def handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(NationalCasesIntentHandler())
sb.add_request_handler(AddInfoIntentHandler())
sb.add_request_handler(StateCasesIntentHandler())
sb.add_request_handler(SMSIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
        return True

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

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(IndianArmyFactsIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
Exemplo n.º 4
0
# Exception Handler
class CatchAllExceptionHandler(AbstractExceptionHandler):
    """Catch all exception handler, log exception and
    respond with custom message.
    """

    def can_handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> bool
        return True

    def handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> Response
        # Add logging logger.info("In CatchAllExceptionHandler")
        # more logging logger.error(exception, exc_info=True)

        handler_input.response_builder.speak(EXCEPTION_MESSAGE).ask(
            HELP_REPROMPT)

        return handler_input.response_builder.response


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(ShopHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelAndStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
Exemplo n.º 5
0
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(SetDifficultyIntentHandler())
sb.add_request_handler(SetCategoryIntentHandler())
sb.add_request_handler(AskQuestionIntentHandler())
sb.add_request_handler(SessionStartHandler())
sb.add_request_handler(GoToAnswerIntentHandler())
sb.add_request_handler(BuzzIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())
Exemplo n.º 6
0
            except TelethonException as error:
                return handle_telethon_error_response(error, handler_input)

            if user_has_telegrams:
                speech_text = i18n.USER_HAS_TELEGRAMS
            else:
                speech_text = i18n.WELCOME
        else:
            speech_text = i18n.NOT_AUTHORIZED

        handler_input.response_builder.speak(speech_text) \
            .set_should_end_session(False).ask(i18n.FALLBACK)
        return handler_input.response_builder.response


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(SendIntentHandler())
sb.add_request_handler(SpeedIntentHandler())
sb.add_request_handler(MessageIntentHandler())
sb.add_request_handler(ReplyIntentHandler())
sb.add_request_handler(SettingsIntentHandler())
sb.add_request_handler(AuthorizationIntentHandler())
sb.add_request_handler(YesIntentHandler())
sb.add_request_handler(NoIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

sb.add_global_request_interceptor(LoggingRequestInterceptor())
sb.add_global_request_interceptor(AccountInterceptor())
    """
    def process(self, handler_input):
        locale = handler_input.request_envelope.request.locale
        i18n = gettext.translation('data',
                                   localedir='locales',
                                   languages=[locale],
                                   fallback=True)
        handler_input.attributes_manager.request_attributes["_"] = i18n.gettext


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
# make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
sb.add_request_handler(IntentReflectorHandler())

sb.add_global_request_interceptor(LocalizationInterceptor())

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemplo n.º 8
0
    """Log the alexa requests."""
    def process(self, handler_input):
        # type: (HandlerInput) -> None
        logger.debug("Alexa Request: {}".format(
            handler_input.request_envelope.request))


class ResponseLogger(AbstractResponseInterceptor):
    """Log the alexa responses."""
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        logger.debug("Alexa Response: {}".format(response))


# Register intent handlers
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(PagerIntentHandler())
sb.add_request_handler(KaraokeIntentHandler())
sb.add_request_handler(DeviceIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# TODO: Uncomment the following lines of code for request, response logs.
# sb.add_global_request_interceptor(RequestLogger())
# sb.add_global_response_interceptor(ResponseLogger())

# Handler name that is used on AWS lambda
Exemplo n.º 9
0
        logger.error(exception, exc_info=True)

        speech = "scusa Rod non mi ha programmato bene. potresti ripetere??"
        handler_input.response_builder.speak(speech).ask(speech)

        return handler_input.response_builder.response


def getTicker():
    r = requests.session().get(
        "https://api.hitbtc.com/api/2/public/ticker/BTCUSD")
    if r.status_code == 200:
        data = r.json()
        return float(data["ask"]), float(data["bid"]), float(data["last"])
    return None, None, None


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(PrezzoIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(NavigateHomeIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(DimmiqualcosaIntentHandler())
sb.add_request_handler(CitazioneIntentHandler())
sb.add_request_handler(CiaoIntentHandler())

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
    """Log the alexa requests."""
    def process(self, handler_input):
        # type: (HandlerInput) -> None
        logger.debug("Alexa Request: {}".format(
            handler_input.request_envelope.request))


class ResponseLogger(AbstractResponseInterceptor):
    """Log the alexa responses."""
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        logger.debug("Alexa Response: {}".format(response))


# Register intent handlers
sb.add_request_handler(GetMissingObjectHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# Register request and response interceptors
sb.add_global_request_interceptor(LocalizationInterceptor())
sb.add_global_request_interceptor(RequestLogger())
sb.add_global_response_interceptor(ResponseLogger())

# Handler name that is used on AWS lambda
lambda_handler = sb.lambda_handler()
Exemplo n.º 11
0
    for item in schedule_json:
        itemdate = item['eventdate'].split(" ")[0]
        if itemdate == datestr:
            if item['information'] == 'FlowRider':
                date = item['eventdate'].split(" ")[0]
                starttime = item['starttime'].split(" ")[1].split('.')[0]
                endtime = item['endtime'].split(" ")[1].split('.')[0]
                print(item['infoid'], date, starttime, 'to', endtime)
                speech = 'the flowrider is open from <say-as interpret-as="time">' + starttime + '</say-as> to <say-as interpret-as="time">' + endtime + '</say-as>.'

    return speech


# Register intent handlers
sb.add_request_handler(GetNewFactHandler())
sb.add_request_handler(GetFlowriderScheduleHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# TODO: Uncomment the following lines of code for request, response logs.
# sb.add_global_request_interceptor(RequestLogger())
# sb.add_global_response_interceptor(ResponseLogger())

# Handler name that is used on AWS lambda
lambda_handler = sb.lambda_handler()
Exemplo n.º 12
0
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# # The SkillBuilder object acts as the entry point for your skill, routing all request and response
# # payloads to the handlers above. Make sure any new handlers or interceptors you've
# # defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
#sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(StateIntentHandler())
sb.add_request_handler(CostIntentHandler())
sb.add_request_handler(operationIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())

#sb.add_request_handler(heartTransplantHandler())
sb.add_request_handler(SessionEndedRequestHandler())
#sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemplo n.º 13
0
    """Log the request envelope."""
    def process(self, handler_input):
        # type: (HandlerInput) -> None
        logger.info("Request Envelope: {}".format(
            handler_input.request_envelope))


class ResponseLogger(AbstractResponseInterceptor):
    """Log the response envelope."""
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        logger.info("Response: {}".format(response))


# Add all request handlers to the skill.
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(QuizHandler())
sb.add_request_handler(DefinitionHandler())
sb.add_request_handler(QuizAnswerHandler())
sb.add_request_handler(QuizAnswerElementSelectedHandler())
sb.add_request_handler(RepeatHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(ExitIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(FallbackIntentHandler())

# Add exception handler to the skill.
sb.add_exception_handler(CatchAllExceptionHandler())

# Add response interceptor to the skill.
sb.add_global_response_interceptor(CacheResponseForRepeatInterceptor())
Exemplo n.º 14
0
from intents.begin_game_intent_handler import BeginGameIntentHandler
from intents.yes_intent_handler import YesIntentHandler
from intents.no_intent_handler import NoIntentHandler
from intents.get_number_intent_handler import GetNumberIntentHandler
from intents.get_user_guess_intent_handler import GetUserGuessIntentHandler
from intents.help_intent_handler import HelpIntentHandler
from intents.cancel_or_stop_intent_handler import CancelOrStopIntentHandler
from intents.session_ended_request_handler import SessionEndedRequestHandler
from intents.catch_all_exception_handler import CatchAllExceptionHandler
from apis.mode_range_attempts_api_handler import ModeRangeAttemptsIntentHandler


sb = SkillBuilder()

# Register intent handlers
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(GetGuessAlexaNumberorGetGuessMyNumberIntentHandler())
# sb.add_request_handler(GetAttemptsIntentHandler())
# sb.add_request_handler(GetRangeIntentHandler())
sb.add_request_handler(GetLowerorHigherIntentHandler())
sb.add_request_handler(BeginGameIntentHandler())
sb.add_request_handler(YesIntentHandler())
sb.add_request_handler(NoIntentHandler())
sb.add_request_handler(GetNumberIntentHandler())
sb.add_request_handler(GetUserGuessIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register intent handlers
sb.add_request_handler(ModeRangeAttemptsIntentHandler())
Exemplo n.º 15
0
        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .response
        )


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(GetLastReadIntentHandler())
sb.add_request_handler(AddReadInstanceIntentHandler())
sb.add_request_handler(DeleteLastReadInstanceIntentHandler())
sb.add_request_handler(GetNumberOfTimesReadIntentHandler())
sb.add_request_handler(LastTimeReadIntentHandler())
sb.add_request_handler(HowManyBooksReadDuringYearIntent())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
        try:
            session_attributes[
                "repeat_reprompt"] = response.reprompt.output_speech.ssml.replace(
                    "<speak>", "").replace("</speak>", "")
        except:
            session_attributes[
                "repeat_reprompt"] = response.output_speech.ssml.replace(
                    "<speak>", "").replace("</speak>", "")


# Skill Builder
# Define a skill builder instance and add all the request handlers,
# exception handlers and interceptors to it.

sb = SkillBuilder()
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(WhatIsMyNameIntentHandler())
sb.add_request_handler(WhatIsMyEmailIntentHandler())
sb.add_request_handler(RepeatIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequesthandler())

sb.add_exception_handler(CatchAllExceptionHandler())

sb.add_global_request_interceptor(LocalizationInterceptor())
sb.add_global_response_interceptor(RepeatInterceptor())
sb.add_global_request_interceptor(RequestLogger())
sb.add_global_response_interceptor(ResponseLogger())
Exemplo n.º 17
0
        elif (input["betType"].value == "number"):
            speak_output = "What number will you choose, 0 to 36"
        else:
            speak_output = "Please choose color or number"
        
        
        return (
            handler_input.response_builder
                .speak(speak_output)
                .response
        )
# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.


sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(RouletteIntentHandler())
sb.add_request_handler(numberIntentHandler())
sb.add_request_handler(colorIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())

sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
Exemplo n.º 18
0
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(StartMeetingIntentHandler())
# sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(PersonalMeetingIntentHandler())
sb.add_request_handler(MeetingIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemplo n.º 19
0
        return (
            handler_input.response_builder
                .speak(speak_output)
                .ask(speak_output)
                .response
        )

# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.


sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(OpenSalonIntentHandler())
sb.add_request_handler(CloseSalonIntentHandler())
sb.add_request_handler(StopSalonIntentHandler())
sb.add_request_handler(OpenChambreIntentHandler())
sb.add_request_handler(CloseChambreIntentHandler())
sb.add_request_handler(StopChambreIntentHandler())
sb.add_request_handler(OpenSdbIntentHandler())
sb.add_request_handler(CloseSdbIntentHandler())
sb.add_request_handler(StopSdbIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())
class TestSkillBuilder(unittest.TestCase):
    def setUp(self):
        self.sb = SkillBuilder()

    def test_skill_configuration_getter_no_registered_components(self):
        actual_config = self.sb.skill_configuration

        assert actual_config.request_mappers is not None, (
            "Skill Configuration getter in Skill Builder didn't set request "
            "mappers correctly")
        assert actual_config.request_mappers[
            0].request_handler_chains is not None, (
                "Skill Configuration getter in Skill Builder didn't set handler "
                "chains in request mappers correctly")
        assert len(
            actual_config.request_mappers[0].request_handler_chains) == 0, (
                "Skill Configuration getter in Skill Builder added invalid "
                "handler in handler chain, "
                "when no request handlers are registered")
        assert actual_config.handler_adapters is not None, (
            "Skill Configuration getter in Skill Builder didn't set handler "
            "adapters correctly")
        assert isinstance(
            actual_config.handler_adapters[0], GenericHandlerAdapter
        ), ("Skill Configuration getter in Skill Builder didn't set default "
            "handler adapter")
        assert isinstance(
            actual_config.exception_mapper, GenericExceptionMapper), (
                "Skill Configuration getter in Skill Builder created invalid "
                "exception mapper, "
                "when no exception handlers are registered")
        assert len(actual_config.exception_mapper.exception_handlers) == 0, (
            "Skill Configuration getter in Skill Builder created invalid "
            "exception handlers in exception mapper, "
            "when no exception handlers are registered")
        assert actual_config.request_interceptors == [], (
            "Skill Configuration getter in Skill Builder created invalid "
            "request interceptors, "
            "when no global request interceptors are registered")
        assert actual_config.response_interceptors == [], (
            "Skill Configuration getter in Skill Builder created invalid "
            "response interceptors, "
            "when no global response interceptors are registered")
        assert actual_config.custom_user_agent is None, (
            "Skill Configuration getter in Skill Builder set invalid custom "
            "user agent")
        assert actual_config.skill_id is None, (
            "Skill Configuration getter in Skill Builder set invalid skill id")

    def test_skill_configuration_getter_handlers_registered(self):
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        self.sb.add_request_handler(request_handler=mock_request_handler)

        mock_exception_handler = mock.MagicMock(spec=AbstractExceptionHandler)
        self.sb.add_exception_handler(exception_handler=mock_exception_handler)

        actual_config = self.sb.skill_configuration

        assert actual_config.request_mappers is not None, (
            "Skill Configuration getter in Skill Builder didn't set request "
            "mappers correctly")
        assert actual_config.request_mappers[
            0].request_handler_chains is not None, (
                "Skill Configuration getter in Skill Builder didn't set handler "
                "chains in request mappers correctly")
        assert len(
            actual_config.request_mappers[0].request_handler_chains) == 1, (
                "Skill Configuration getter in Skill Builder didn't add valid "
                "handler in handler chain, "
                "when request handlers are registered")
        assert actual_config.request_mappers[0].request_handler_chains[
            0].request_handler == mock_request_handler, (
                "Skill Configuration getter in Skill Builder added invalid "
                "handler in handler chain, "
                "when request handlers are registered")

        assert actual_config.exception_mapper is not None, (
            "Skill Configuration getter in Skill Builder didn't create "
            "exception mapper, "
            "when exception handlers are registered")
        assert len(actual_config.exception_mapper.exception_handlers) == 1, (
            "Skill Configuration getter in Skill Builder added additional "
            "exception handlers than the registered ones "
            "in exception mapper")
        assert actual_config.exception_mapper.exception_handlers[
            0] == mock_exception_handler, (
                "Skill Configuration getter in Skill Builder added invalid "
                "handler in exception mapper, "
                "when exception handlers are registered")

    def test_create_skill(self):
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        self.sb.add_request_handler(request_handler=mock_request_handler)

        mock_exception_handler = mock.MagicMock(spec=AbstractExceptionHandler)
        self.sb.add_exception_handler(exception_handler=mock_exception_handler)

        actual_skill = self.sb.create()
        expected_skill = CustomSkill(self.sb.skill_configuration)

        assert actual_skill.request_dispatcher.request_mappers[0].request_handler_chains[0].request_handler == \
            expected_skill.request_dispatcher.request_mappers[0].request_handler_chains[0].request_handler, (
            "Skill Builder created skill with incorrect request handlers when "
            "using create method")

        assert actual_skill.request_dispatcher.exception_mapper.exception_handlers[0] == \
            expected_skill.request_dispatcher.exception_mapper.exception_handlers[0], (
            "Skill Builder created skill with incorrect exception handlers "
            "when using create method")

    def test_lambda_handler_creation(self):
        handler_func = self.sb.lambda_handler()
        assert callable(handler_func), "Skill Builder Lambda Handler " \
                                       "function returned an invalid object"

        actual_arg_spec = inspect.getargspec(handler_func)
        assert len(actual_arg_spec.args) == 2, (
            "Skill Builder Lambda Handler function created a handler of "
            "different signature than AWS Lambda")
        assert "event" in actual_arg_spec.args, (
            "Skill Builder Lambda Handler function created a handler without "
            "named parameter event")
        assert "context" in actual_arg_spec.args, (
            "Skill Builder Lambda Handler function created a handler without "
            "named parameter context")

    def test_lambda_handler_invocation(self):
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        mock_request_handler.can_handle.return_value = True
        mock_response = Response()
        mock_response.output_speech = "test output speech"
        mock_request_handler.handle.return_value = mock_response
        self.sb.add_request_handler(request_handler=mock_request_handler)

        mock_request_envelope_payload = {
            "context": {
                "System": {
                    "application": {
                        "applicationId": "test"
                    }
                }
            },
            "session": {
                "new": "True"
            }
        }

        self.sb.skill_id = "test"
        lambda_handler = self.sb.lambda_handler()

        response_envelope = lambda_handler(event=mock_request_envelope_payload,
                                           context=None)

        assert response_envelope["version"] == RESPONSE_FORMAT_VERSION, (
            "Response Envelope from lambda handler invocation has version "
            "different than expected")
        assert response_envelope["userAgent"] == user_agent_info(
            sdk_version=__version__, custom_user_agent=None
        ), ("Response Envelope from lambda handler invocation has user agent "
            "info different than expected")
        assert response_envelope["response"][
            "outputSpeech"] == "test output speech", (
                "Response Envelope from lambda handler invocation has incorrect "
                "response than built by skill")

    def test_out_of_session_lambda_handler_invocation(self):
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        mock_request_handler.can_handle.return_value = True
        mock_response = Response()
        mock_response.output_speech = "test output speech"
        mock_request_handler.handle.return_value = mock_response
        self.sb.add_request_handler(request_handler=mock_request_handler)

        mock_request_envelope_payload = {
            "context": {
                "System": {
                    "application": {
                        "applicationId": "test"
                    }
                }
            }
        }

        self.sb.skill_id = "test"
        lambda_handler = self.sb.lambda_handler()

        response_envelope = lambda_handler(event=mock_request_envelope_payload,
                                           context=None)

        assert response_envelope["version"] == RESPONSE_FORMAT_VERSION, (
            "Response Envelope from lambda handler invocation has version "
            "different than expected")
        assert response_envelope["userAgent"] == user_agent_info(
            sdk_version=__version__, custom_user_agent=None
        ), ("Response Envelope from lambda handler invocation has user agent "
            "info different than expected")
        assert response_envelope["response"][
            "outputSpeech"] == "test output speech", (
                "Response Envelope from lambda handler invocation has incorrect "
                "response than built by skill")

    def test_should_append_additional_user_agent(self):
        additional_user_agent = "test_string"
        sdk_user_agent = user_agent_info(sdk_version=__version__)
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        mock_request_handler.can_handle.return_value = True
        mock_response = Response()
        mock_request_handler.handle.return_value = mock_response
        self.sb.add_request_handler(request_handler=mock_request_handler)
        self.sb.add_custom_user_agent(user_agent=additional_user_agent)

        mock_request_envelope_payload = {
            "context": {
                "System": {
                    "application": {
                        "applicationId": "test"
                    }
                }
            }
        }

        self.sb.skill_id = "test"
        lambda_handler = self.sb.lambda_handler()

        response_envelope = lambda_handler(event=mock_request_envelope_payload,
                                           context=None)

        self.assertEqual("{} {}".format(additional_user_agent, sdk_user_agent),
                         response_envelope["userAgent"],
                         "Response envelope doesn't have correct user agent")

    def test_should_append_additional_user_agent_using_userAgentManager(self):
        additional_user_agent = "test_string"
        sdk_user_agent = user_agent_info(sdk_version=__version__)
        mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler)
        mock_request_handler.can_handle.return_value = True
        mock_response = Response()
        mock_request_handler.handle.return_value = mock_response
        self.sb.add_request_handler(request_handler=mock_request_handler)

        mock_request_envelope_payload = {
            "context": {
                "System": {
                    "application": {
                        "applicationId": "test"
                    }
                }
            }
        }

        self.sb.skill_id = "test"
        lambda_handler = self.sb.lambda_handler()

        UserAgentManager.register_component(
            component_name=additional_user_agent)

        response_envelope = lambda_handler(event=mock_request_envelope_payload,
                                           context=None)

        self.assertEqual(
            "{} {}".format(additional_user_agent,
                           sdk_user_agent), response_envelope["userAgent"],
            "Response envelope doesn't have correct user agent when adding "
            "using UserAgentManager")

    def tearDown(self):
        UserAgentManager.clear()
Exemplo n.º 21
0
		return handler_input.response_builder.response

from ask_sdk_core.dispatch_components import AbstractExceptionHandler

class AllExceptionHandler(AbstractExceptionHandler):

	def can_handle(self, handler_input, exception):
		# type: (HandlerInput, Exception) -> bool
		return True

	def handle(self, handler_input, exception):
		# type: (HandlerInput, Exception) -> Response
		# Log the exception in CloudWatch Logs
		print(exception)

		speech = "Sorry, I didn't get it. Can you please say it again!!"
		handler_input.response_builder.speak(speech).ask(speech)
		return handler_input.response_builder.response


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(GetContifyContextHandler())
sb.add_request_handler(NextIntentHandler())
#sb.add_request_handler(LikeActionHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelAndStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

sb.add_exception_handler(AllExceptionHandler())

handler = sb.lambda_handler()
Exemplo n.º 22
0
        # type: (HandlerInput) -> bool
        return is_intent_name("HeroInfo")(handler_input)

    def handle(self, handler_input):
        slots = handler_input.request_envelope.request.intent.slots

        hero_dict = slots['hero']
        hero_name = hero_dict.value
        hero_info = prompts.get_hero_info(hero_name)

        logger.debug("Hero information: {}".format(hero_info))
        return handler_input.response_builder.speak(hero_info).ask(prompts.FALLBACK_REPROMPT).response


# Register intent handlers
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register custom intents handler
sb.add_request_handler(HeroInfoRequest())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# Register request and response interceptors
sb.add_global_request_interceptor(RequestLogger())
sb.add_global_response_interceptor(ResponseLogger())
Exemplo n.º 23
0
        reprompt = "What would you like to do?"

        return (handler_input.response_builder.speak(speech_output).ask(
            reprompt).response)


class RequestLogger(AbstractRequestInterceptor):
    def process(self, handler_input):
        logger.debug("Alexa Request: {}".format(
            handler_input.request_envelope.request))


class ResponseLogger(AbstractResponseInterceptor):
    def process(self, handler_input, response):
        logger.debug("Alexa Response: {}".format(response))


sb = SkillBuilder()
sb.add_request_handler(GetRemoteDataIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequesthandler())

sb.add_exception_handler(CatchAllExceptionHandler())

sb.add_global_request_interceptor(RequestLogger())
sb.add_global_response_interceptor(ResponseLogger())

lambda_handler = sb.lambda_handler()
Exemplo n.º 24
0
    """Log the alexa requests."""
    def process(self, handler_input):
        # type: (HandlerInput) -> None
        logger.debug("Alexa Request: {}".format(
            handler_input.request_envelope.request))


class ResponseLogger(AbstractResponseInterceptor):
    """Log the alexa responses."""
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        logger.debug("Alexa Response: {}".format(response))


# Register intent handlers
sb.add_request_handler(GetNewFactHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# TODO: Uncomment the following lines of code for request, response logs.
# sb.add_global_request_interceptor(RequestLogger())
# sb.add_global_response_interceptor(ResponseLogger())

# Handler name that is used on AWS lambda
lambda_handler = sb.lambda_handler()
Exemplo n.º 25
0
    def handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(EstadisticasdIntentHandler())
sb.add_request_handler(NotificarEmailIntentHandler())
sb.add_request_handler(InfoCovidIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
from intents.launch_request_handler import LaunchRequestHandler
from intents.help_intent_handler import HelpIntentHandler
from intents.cancel_or_stop_intent_handler import CancelOrStopIntentHandler
from intents.session_ended_request_handler import SessionEndedRequestHandler
from intents.catch_all_exception_handler import CatchAllExceptionHandler

from intents.first_order_intent_handler import FirstOrderIntentHandler
from intents.second_order_intent_handler import SecondOrderIntentHandler
from intents.third_order_intent_handler import ThirdOrderIntentHandler

load_dotenv()

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(HelpIntentHandler())

sb.add_request_handler(FirstOrderIntentHandler())
sb.add_request_handler(SecondOrderIntentHandler())
sb.add_request_handler(ThirdOrderIntentHandler())

sb.add_exception_handler(CatchAllExceptionHandler())

app = Flask(__name__)
skill_response = SkillAdapter(skill=sb.create(),
                              skill_id=os.getenv('SKILL_ID'),
                              app=app)
Exemplo n.º 27
0
    """
    def can_handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> bool
        return True

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

        speech = "Sorry, there was some problem. Please try again or ask me for help!"
        handler_input.response_builder.speak(speech).ask(speech)

        return handler_input.response_builder.response


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(NextArticleHandler())
sb.add_request_handler(PreviousArticleHandler())
sb.add_request_handler(FirstArticleHandler())
sb.add_request_handler(ReadNewsHandler())
sb.add_request_handler(ListNewsHandler())
sb.add_request_handler(RequestHeadlineHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemplo n.º 28
0
        #The provided request is not an IntentRequest
        logger.info(ask_utils.get_request_type(handler_input))

        speak_output = "Sorry, I had trouble doing what you asked. Please try again."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(AudioPlayIntentHandler())
sb.add_request_handler(AudioStopIntentHandler())
# ########## AUDIOPLAYER INTERFACE HANDLERS #########################
sb.add_request_handler(PlaybackStartedHandler())
sb.add_request_handler(PlaybackFinishedHandler())
sb.add_request_handler(PlaybackStoppedHandler())
sb.add_request_handler(PlaybackNearlyFinishedHandler())
sb.add_request_handler(PlaybackFailedHandler())
sb.add_request_handler(ExceptionEncounteredHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
Exemplo n.º 29
0

class LambdaCaller():
    def __init__(self, lambda_name):
        self.lambda_name = lambda_name
        self.lambda_client = boto3_client('lambda')

    def call(self, params):
        invoke_response = self.lambda_client.invoke(
            FunctionName=self.lambda_name,
            InvocationType='RequestResponse',
            Payload=json.dumps(params))
        return json.loads(invoke_response['Payload'].read().decode("utf-8"))


# Register intent handlers
sb.add_request_handler(HelloHandler())
sb.add_request_handler(StatusExpenseHandler())
sb.add_request_handler(AskQuestionHandler())
sb.add_request_handler(AddTaskHandler())
sb.add_request_handler(OpenTicketHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Register exception handlers
sb.add_exception_handler(CatchAllExceptionHandler())

# Handler name that is used on AWS lambda
lambda_handler = sb.lambda_handler()
Exemplo n.º 30
0
        return True

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

        speak_output = "Sorry! Something went wrong."

        return (handler_input.response_builder.speak(speak_output).ask(
            speak_output).response)


# The SkillBuilder object acts as the entry point for your skill, routing all request and response
# payloads to the handlers above. Make sure any new handlers or interceptors you've
# defined are included below. The order matters - they're processed top to bottom.

sb = SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(AskDeepPavlovIntentHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

sb.add_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()