def handle(self, handler_input): attributes_manager = handler_input.attributes_manager # Get History from Session Attributes for replay session_attr = attributes_manager.session_attributes actionnable_history = list() if('actionable_history' in session_attr.keys()): actionnable_history = session_attr.actionnable_history # First actionable request is the one that is currently displayed or heard # So we need to track when that is found so we can go back to the previous one found_actionnable_request_in_history = False replay_request = None while len(actionnable_history) > 0: # Get previous action replay_request = actionnable_history.pop() # Check if the action can be replayed if(replay_request and replay_request.actionable and found_actionnable_request_in_history): if((replay_request['type'] == 'IntentRequest' and replay_request.intent['name'] == 'RecipeIntent') or (replay_request['type'] == 'Alexa.Presentation.APL.UserEvent')): # Re-Add the actionnable request in history to remember the latest displayed or heard actionnable_history.append(replay_request) # Get sauce item from the request history not current request sauce_item = recipe_utils.get_suace_item(replay_request) return RecipeIntentHandler().generate_recipe_output(handler_input, sauce_item) if(replay_request['type'] == 'IntentRequest' and replay_request.intent['name'] == 'AMAZON.HelpIntent'): # Re-Add the actionnable request in history to remember the latest displayed or heard actionnable_history.append(replay_request) # Call AMAZON.HelpIntent handler return HelpIntentHandler().handle(handler_input) # Note: we don't manage LaunchRequest here as it will be the default actionnable request # We can break the iteration break # Update flag when an actionnable request is found # Next actionnable request in history (if any) will be replayed found_actionnable_request_in_history = replay_request.actionable # No actionable history ? so just go to launch return LaunchRequestIntentHandler().handle(handler_input)
def handle(self, handler_input): # Get slot item sauce_item = recipe_utils.get_suace_item( handler_input.request_envelope.request) # Generate output to include a recipe with or without APL return self.generate_recipe_output(handler_input, sauce_item)