Last active
August 26, 2021 08:51
-
-
Save sjwaight/69c9bfb19bb9b01ac6080dcf29f1f85b to your computer and use it in GitHub Desktop.
Sample Launch Request and Exception Catch All handlers for an Alexa Skill.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LaunchRequestHandler(AbstractRequestHandler): | |
"""Handler for LaunchRequest.""" | |
def can_handle(self, handler_input): | |
return ask_utils.is_request_type("LaunchRequest")(handler_input) | |
def handle(self, handler_input): | |
logging.info("Called Skill Handler for LaunchRequest Intent.") | |
speak_output = "Hi there! I'm the Azure news service and I can read you the latest Azure cloud news.\r\nYou can ask for the latest news by saying <break time='0.5s'/>'latest news', or ask for the top news items from a specific date by saying <break time='0.5s'/>'top news from'<break time='0.5s'/> and then the date, making sure to include the year." | |
return ( | |
handler_input.response_builder | |
.speak(speak_output) | |
.ask(speak_output) | |
.response | |
) | |
class CatchAllExceptionHandler(AbstractExceptionHandler): | |
"""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. | |
""" | |
def can_handle(self, handler_input, exception): | |
return True | |
def handle(self, handler_input, exception): | |
logging.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 | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment