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 = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(GetCityIntentHandler())
sb.add_request_handler(GetMoreCitiesIntentHandler())
sb.add_request_handler(NoMoreCitiesIntentHandler())
sb.add_request_handler(GetVacationDaysIntentHandler())
sb.add_request_handler(GetBudgetIntentHandler())
sb.add_request_handler(SetBudgetIntentHandler())
sb.add_request_handler(CheckTripsIntentHandler())
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()
def is_warning_needed(current_wealth, current_energy):
    if current_wealth <= 10 or current_energy <= 10:
        return True
    else:
        return False


# 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.

# Skill Builder object
sb = CustomSkillBuilder(api_client=DefaultApiClient())

# Add all request handlers to the skill.
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(StartAdventureIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(YesIntentHandler())
sb.add_request_handler(NoIntentHandler())

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

# Add request and response interceptors
sb.add_global_response_interceptor(LoggingResponseInterceptor())
sb.add_global_request_interceptor(LoggingRequestInterceptor())
        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 = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(RodarRoletaIntentHandler())
sb.add_request_handler(CriarRoletaIntentHandler())
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()
"""Generic error handling to capture any syntax or routing errors. If you receive an error stating the request handler chain is 
not found, you have not implemented a handler for the intent being invoked or included it in the skill builder below."""
class CatchAllExceptionHandler(AbstractExceptionHandler):
    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)
        return handler_input.response_builder.speak(data.ISSUE_MESSAGE).ask(data.ISSUE_MESSAGE).response

#Processed top to bottom

sb = CustomSkillBuilder(persistence_adapter=s3_adapter)#SkillBuilder()

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(CaptureQuestionTypeIntentHandler())
sb.add_request_handler(RepeatQIntentHandler())
sb.add_request_handler(GetAnswerIntentHandler())
sb.add_request_handler(CaptureUserAnswerIntent())
#sb.add_request_handler(CaptureGradeLevelIntentHandler())
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()
Exemple #5
0
import logging
from ask_sdk_core.skill_builder import CustomSkillBuilder
from ask_sdk_core.api_client import DefaultApiClient
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
from ask_sdk_core.dispatch_components import AbstractResponseInterceptor
from ask_sdk_core.dispatch_components import AbstractRequestInterceptor
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_core.exceptions import AskSdkException
import ask_sdk_core.utils as ask_utils

from handlers.exports import request_handlers
from interceptors import LoggingRequestInterceptor, LoggingResponseInterceptor
from handlers.core.errorhandlers import CatchAllExceptionHandler

sb = CustomSkillBuilder(api_client=DefaultApiClient())

for h in request_handlers:
    sb.add_request_handler(h)

sb.add_exception_handler(CatchAllExceptionHandler())
sb.add_global_response_interceptor(LoggingResponseInterceptor())
sb.add_global_request_interceptor(LoggingRequestInterceptor())

# This is the exported entry point.
lambda_handler = sb.lambda_handler()

class ResponseLogger(AbstractResponseInterceptor):
    """Log the alexa responses."""
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        logger.debug("Alexa Response: {}".format(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 = CustomSkillBuilder(persistence_adapter=dynamodb_adapter)
sb.add_request_handler(PromptQuestionHandler())
sb.add_request_handler(RestaurantIntentHandler())
sb.add_request_handler(TrainIntentHandler())
sb.add_request_handler(AirportIntentHandler())
sb.add_request_handler(MeetingIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(GetAnswerHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_exception_handler(CatchAllExceptionHandler())
sb.add_request_handler(
    IntentReflectorHandler()
)  # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

# Register request and response interceptors
Exemple #7
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)
        logger.info("Original request was {}".format(
            handler_input.request_envelope.request))

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

        return handler_input.response_builder.response


# Add all request handlers to the skill.
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(YesMoreInfoIntentHandler())
sb.add_request_handler(NoMoreInfoIntentHandler())
sb.add_request_handler(NextTrainIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(ExitIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

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

# Expose the lambda handler to register in AWS Lambda.
lambda_handler = sb.lambda_handler()
Exemple #8
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!!"
        handler_input.response_builder.speak(speech).ask(speech)

        return handler_input.response_builder.response


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelloWorldIntentHandler())
sb.add_request_handler(NoTransactionIntentHandler())
sb.add_request_handler(YesTransactionIntentHandler())
sb.add_request_handler(SplitwiseIntentHandler())
sb.add_request_handler(CreditScoreIntentHandler())
sb.add_request_handler(BalanceIntentHandler())
sb.add_request_handler(RewardPointsIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

sb.add_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemple #9
0
        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 = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(CaptureDistrictIntentHandler())
sb.add_request_handler(SchoolsOpenIntentHandler())
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()
Exemple #10
0
            )
        )
        return response_builder.response
    except ServiceException as e:
        response_builder.speak(ERROR)
        response_builder.set_card(
            ui.StandardCard(
                title="Error Sending Message",
                text=f"ServiceException: {e}",
                # image=ui.Image(
                #     small_image_url="<Small Image URL>",
                #     large_image_url="<Large Image URL>"
                # )
            )
        )
        return response_builder.response
    except Exception as e:
        raise e


sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(SleepIntentHandler())
sb.add_request_handler(MuteIntentHandler())
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())

lambda_handler = sb.lambda_handler()
Exemple #11
0
ENV = os.environ.get('ENV')
adapter_config = {
    "table_name": settings.STORAGE['session_table'],
    "create_table": ENV == 'DEV',
}
if ENV == 'DEV':
    localhost = 'http://localhost:8000'
    adapter_config["dynamodb_resource"] = boto3.resource("dynamodb", endpoint_url=localhost)
else:
    adapter_config["dynamodb_resource"] = boto3.resource("dynamodb")


sb = CustomSkillBuilder(persistence_adapter=DynamoDbAdapter(**adapter_config))
sb.skill_id = settings.APP_ID

sb.add_request_handler(game_play_handlers.AnswerHandler())
sb.add_request_handler(game_play_handlers.DontKnowNextHandler())
sb.add_request_handler(game_play_handlers.GameEventHandler())
sb.add_request_handler(game_play_handlers.PlayGameHandler())
sb.add_request_handler(game_play_handlers.EndGameHandler())
sb.add_request_handler(game_play_handlers.YesHandler())
sb.add_request_handler(roll_call_handlers.YesHandler())
sb.add_request_handler(roll_call_handlers.NoHandler())
sb.add_request_handler(roll_call_handlers.GameEventHandler())
sb.add_request_handler(start_handlers.PlayerCountHandler())
sb.add_request_handler(start_handlers.YesHandler())
sb.add_request_handler(start_handlers.NoHandler())
sb.add_request_handler(start_handlers.LaunchPlayGameHandler())
sb.add_request_handler(start_handlers.StartNewGameHandler())
sb.add_request_handler(global_handlers.HelpHandler())
sb.add_request_handler(global_handlers.StopCancelHandler())
        data = language_data[skill_locale[:2]]
        # if a more specialized translation exists, then select it instead
        # example: "fr-CA" will pick "fr" translations first, but if "fr-CA" translation exists,
        #          then pick that instead
        if skill_locale in language_data:
            data.update(language_data[skill_locale])
        handler_input.attributes_manager.request_attributes["_"] = data

        # configure the runtime to treat time according to the skill locale
        skill_locale = skill_locale.replace('-', '_')
        locale.setlocale(locale.LC_TIME, skill_locale)


sb = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(AddFriendIntentHandler())
sb.add_request_handler(AddFriendBirthdayIntentHandler())
sb.add_request_handler(SpeakAllFriendNamesIntentHandler())
sb.add_request_handler(ListAllBirthdaysIntentHandler())
sb.add_request_handler(DeleteAllIntentHandler())
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())

sb.add_global_request_interceptor(LocalizationInterceptor())
        data = language_data[skill_locale[:2]]
        # if a more specialized translation exists, then select it instead
        # example: "fr-CA" will pick "fr" translations first, but if "fr-CA" translation exists,
        #          then pick that instead
        if skill_locale in language_data:
            data.update(language_data[skill_locale])
        handler_input.attributes_manager.request_attributes["_"] = data

        # configure the runtime to treat time according to the skill locale
        skill_locale = skill_locale.replace('-', '_')
        locale.setlocale(locale.LC_TIME, skill_locale)


sb = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(RoomSearchIntentHandler())
sb.add_request_handler(RoomSearchNowIntentHandler())
sb.add_request_handler(ReserveRoomIntentHandler())
sb.add_request_handler(RemoveReservationIntentHandler())
sb.add_request_handler(YesHandler())
sb.add_request_handler(NoHandler())
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())
# Request and Response loggers
class RequestLogger(AbstractRequestInterceptor):
    """Log the alexa requests."""
    def process(self, handler_input):
        logger.debug("Alexa Request: {}".format(
            handler_input.request_envelope.request))


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


# Register intent handlers
sb.add_request_handler(LaunchHandler())
sb.add_request_handler(AddressIntentHandler())
sb.add_request_handler(ElectionIntentHandler())
sb.add_request_handler(PollingIntentHandler())
sb.add_request_handler(CandidateIntentHandler())
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())
Exemple #15
0
    def handle(self, handler_input, exception):
        # type: (HandlerInput, Exception) -> Response
        logger.info("In CatchAllExceptionHandler")
        logger.error(exception, exc_info=True)

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

        return handler_input.response_builder.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.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(GravityIntentHandler())
sb.add_request_handler(CalibrateIntentHandler())
sb.add_request_handler(RepeatHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(ExitIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

sb.add_exception_handler(CatchAllExceptionHandler())

# sb.add_global_request_interceptor(RequestLogger())
# sb.add_global_request_interceptor(ResponseLogger())

lambda_handler = sb.lambda_handler()
Exemple #16
0
        # type: (HandlerInput, Exception) -> Response
        logger.error(exception, exc_info=True)
        
        return (
            handler_input.response_builder
            .speak("Uh Oh. Looks like something went wrong.")
            .ask("Uh Oh. Looks like something went wrong.")
            .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 = CustomSkillBuilder(api_client=DefaultApiClient())

sb.add_request_handler(LaunchRequestHandler())

sb.add_request_handler(TimerIntentHandler())
sb.add_request_handler(AcceptGrantResponseHandler())
sb.add_request_handler(ConnectionsResponsehandler())
sb.add_request_handler(SessionResumedHandlerRequest())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

# Adding Request and Response interceptor
sb.add_global_request_interceptor(LoggingRequestInterceptor())
sb.add_global_response_interceptor(LoggingResponseInterceptor())

handler = sb.lambda_handler()
Exemple #17
0
        # type: (HandlerInput, Response) -> None
        handler_input.attributes_manager.save_persistent_attributes()

# ###################################################################
# 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.


s3_adapter = S3Adapter(bucket_name=os.environ["S3_PERSISTENCE_BUCKET"])
sb = CustomSkillBuilder(persistence_adapter=s3_adapter,api_client=DefaultApiClient())

# ############# REGISTER HANDLERS #####################
# Request Handlers

sb.add_request_handler(CheckAudioInterfaceHandler())
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(ExceptionEncounteredHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(TodayIntentHandler())
sb.add_request_handler(playAudioIntentHandler())
sb.add_request_handler(qayaamIntentHandler())
sb.add_request_handler(rozaNiyatIntentHandler())
sb.add_request_handler(moharramIntentHandler())
sb.add_request_handler(NamaazTimesIntentHandler())
sb.add_request_handler(MeeqaatIntentHandler())
sb.add_request_handler(sadqahIntentHandler())
sb.add_request_handler(MiscIntentHandler())
sb.add_request_handler(NmzReminderIntentHandler())
sb.add_request_handler(ResumeIntentHandler())
Exemple #18
0
# -*- coding: utf-8 -*-

from ask_sdk_core.skill_builder import CustomSkillBuilder

from handlers import *
import utils

# 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 = CustomSkillBuilder(persistence_adapter=utils.s3_adapter())

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(RegisterPressureIntentHandler())
sb.add_request_handler(ReadLastPressureIntentHandler())
sb.add_request_handler(RemoveLastPressureIntentHandler())
sb.add_request_handler(EditLastPressureIntentHandler())
sb.add_request_handler(ReportLatestPressuresIntentHandler())
sb.add_request_handler(AddReminderIntentHandler())
# sb.add_request_handler(RemoveReminderIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
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_exception_handler(CatchAllExceptionHandler())

lambda_handler = sb.lambda_handler()
Exemple #19
0
    def handle(self, handler_input):
        speak_output = "Goodbye!"
        handler_input.response_builder.speak(speak_output)
        return handler_input.response_builder.response


class SessionEndedRequestHandler(AbstractRequestHandler):
    """
    Handler for SessionEndedRequest
    """
    def can_handle(self, handler_input):
        return is_request_type("SessionEndedRequest")(handler_input)

    def handle(self, handler_input):
        # Any cleanup logic goes here
        return handler_input.response_builder.response


# register request / intent handlers
sb.add_request_handler(HasBirthdayLaunchRequestHandler())
sb.add_request_handler(LaunchRequestIntentHandler())
sb.add_request_handler(BirthdayIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelAndStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

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

lambda_handler = sb.lambda_handler()
    Add function to request attributes, that can load locale specific data
    """
    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.add_request_handler(LaunchRequestHandler())

sb.add_request_handler(LoginIntentHandler())
sb.add_request_handler(CreateMedicineReminderHandler())
sb.add_request_handler(GetMedDataIntentHandler())
sb.add_request_handler(GetSideEffectsIntentHandler())
sb.add_request_handler(GetNextDoseIntentHandler())
sb.add_request_handler(GetRemainingStockIntentHandler())
sb.add_request_handler(ReorderMedicinesIntentHandler())

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

# make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
sb.add_request_handler(IntentReflectorHandler())
    def process(self, handler_input, response):
        # type: (HandlerInput, Response) -> None
        session_attr = handler_input.attributes_manager.session_attributes
        session_attr["speech"] = response.output_speech
        session_attr["reprompt"] = response.reprompt


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


# register request / intent handlers
sb.add_request_handler(LaunchRequestIntentHandler())
sb.add_request_handler(RecipeIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(PreviousHandler())
sb.add_request_handler(RepeatIntentHandler())
sb.add_request_handler(ExitIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())

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

# register response interceptors
sb.add_global_request_interceptor(LocalizationInterceptor())
sb.add_global_request_interceptor(RequestLogger())
sb.add_global_response_interceptor(CacheResponseForRepeatInterceptor())
sb.add_global_response_interceptor(ResponseLogger())
        logger.info('Request recieved: {}'.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 generated: {}'.format(response))


# Skillbuilder
sb = CustomSkillBuilder(api_client=DefaultApiClient())

# Custom
sb.add_request_handler(createWorkoutAPIHandler())
sb.add_request_handler(GetRecommendationAPIHandler())
sb.add_request_handler(GetDescriptionAPIHandler())

# Standard
sb.add_request_handler(SessionEndedRequestHandler())

# Exceptions
sb.add_exception_handler(CatchAllExceptionHandler())

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

# Lambda Handler
lambda_handler = sb.lambda_handler()
class LoggingRequestInterceptor(AbstractRequestInterceptor):
    """Invoked immediately before execution of the request handler for an incoming request. 
    Used to print request for logging purposes
    """
    def process(self, handler_input):
        logger.debug("Request received by LoggingRequestInterceptor: {}".format(handler_input.request_envelope))

# 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.

# Skill Builder object
sb = CustomSkillBuilder(api_client=DefaultApiClient())

# Add all request handlers to the skill.
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(StartJapanExplorerIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(FallbackIntentHandler())

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

# Add request and response interceptors
sb.add_global_response_interceptor(LoggingResponseInterceptor())
sb.add_global_request_interceptor(LoggingRequestInterceptor())

# Expose the lambda handler function that can be tagged to AWS Lambda handler
handler = sb.lambda_handler()
Exemple #24
0
    def process(self, handler_input, response):
        session_attributes = handler_input.attributes_manager.session_attributes
        session_attributes["repeat_speech_output"] = response.output_speech.ssml.replace("<speak>","").replace("</speak>","")
        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 = CustomSkillBuilder (persistence_adapter = s3_adapter)
sb.add_request_handler(InvalidConfigHandler())
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(MyNameIsIntentHandler())
sb.add_request_handler(LearnMoreIntentHandler())
sb.add_request_handler(YesNoIntentHandler())
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_request_interceptor(InvalidConfigInterceptor())
sb.add_global_response_interceptor(RepeatInterceptor())
Exemple #25
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.
try:
    s3_adapter = S3Adapter(bucket_name=AWS_S3_BUCKET)

    sb = CustomSkillBuilder(persistence_adapter=s3_adapter)

    sb.add_request_handler(LaunchRequestHandler())

    sb.add_request_handler(SetRoomIntentHandler())
    sb.add_request_handler(PauseIntentHandler())
    sb.add_request_handler(PlayIntentHandler())
    sb.add_request_handler(StopIntentHandler())
    sb.add_request_handler(SetVolumeIntentHandler())
    sb.add_request_handler(PreviousIntentHandler())
    sb.add_request_handler(NextIntentHandler())

    sb.add_request_handler(RestartIntentHandler())
    sb.add_request_handler(PlayTrailerIntentHandler())
    sb.add_request_handler(PlayOnAppIntentHandler())

    sb.add_request_handler(HelpIntentHandler())
    sb.add_request_handler(CancelIntentHandler())
        return handler_input.response_builder.response


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) -> Response
        logger.exception(
            "Encountered following exception: {}".format(exception),
            exc_info=True)

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

        return handler_input.response_builder.response


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_exception_handler(CatchAllExceptionHandler())

handler = sb.lambda_handler()
Exemple #27
0
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
        logging.error(exception, exc_info=True)
        handler_input.response_builder.speak(ERROR).set_should_end_session(
            True)

        return handler_input.response_builder.response


# Register handlers
sb.add_request_handler(CanFulfillIntentRequestHandler())
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(SensorDetailHandler())
sb.add_request_handler(AirQualityHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(FallbackIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IndoorIntentHandler())
sb.add_exception_handler(CatchAllExceptionHandler())
handler = sb.lambda_handler()
Exemple #28
0
        data = language_data[skill_locale[:2]]
        # if a more specialized translation exists, then select it instead
        # example: "fr-CA" will pick "fr" translations first, but if "fr-CA" translation exists,
        #          then pick that instead
        if skill_locale in language_data:
            data.update(language_data[skill_locale])
        handler_input.attributes_manager.request_attributes["_"] = data

        # configure the runtime to treat time according to the skill locale
        skill_locale = skill_locale.replace('-', '_')
        locale.setlocale(locale.LC_TIME, skill_locale)


sb = CustomSkillBuilder(persistence_adapter=s3_adapter)

sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(MeditationIntentHandler())
sb.add_request_handler(MedicationIntentHandler())
sb.add_request_handler(CheckMedicationIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(PanicAttackIntentHandler())
sb.add_request_handler(YesIntentHandler())
sb.add_request_handler(NoIntentHandler())
sb.add_request_handler(ResourcesIntentHandler())
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())
Exemple #29
0
                language_prompts = json.load(language_data)
        except:
            with open("languages/" + str(locale[:2]) +
                      ".json") as language_data:
                language_prompts = json.load(language_data)

        handler_input.attributes_manager.request_attributes[
            "_"] = language_prompts


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

sb = CustomSkillBuilder(persistence_adapter=dynamodb_adapter)
sb.add_request_handler(CheckAudioInterfaceHandler())
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(PlayNewestEpisodeIntentHandler())
sb.add_request_handler(PlayOldestEpisodeIntentHandler())
sb.add_request_handler(ChooseEpisodeIntentHandler())
sb.add_request_handler(PauseIntentHandler())
sb.add_request_handler(ResumeIntentHandler())
sb.add_request_handler(NoIntentHandler())
sb.add_request_handler(NextIntentHandler())
sb.add_request_handler(PreviousIntentHandler())
sb.add_request_handler(RepeatIntentHandler())
sb.add_request_handler(ShuffleOnIntentHandler())
sb.add_request_handler(ShuffleOffIntentHandler())
sb.add_request_handler(LoopOnIntentHandler())
sb.add_request_handler(LoopOffIntentHandler())
sb.add_request_handler(PlaybackStartedEventHandler())
Exemple #30
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 = CustomSkillBuilder()

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(GiveClueHandler())
sb.add_request_handler(GlobeHandler())
sb.add_request_handler(SafeHandler())
sb.add_request_handler(Door2Handler())
sb.add_request_handler(RetrievePrototypeHandler())
sb.add_request_handler(PrototypeHandler())
sb.add_request_handler(OverrideServerHandler())
sb.add_request_handler(YesHandler())
sb.add_request_handler(NoHandler())
sb.add_request_handler(
    IntentReflectorHandler()