def on_intent(mycity_request): """ If the event type is "request" and the request type is "IntentRequest", this function is called to execute the logic associated with the provided intent and build a response. Checks for required session_attributes when applicable. :param mycity_request: MyCityRequestDataModel object with request_type IntentRequest :return: MyCityRequestDataModel object corresponding to the intent_name :raises: ValueError """ logger.debug('MyCityRequestDataModel received:' + mycity_request.get_logger_string()) if "Address" in mycity_request.intent_variables \ and "value" in mycity_request.intent_variables["Address"]: # Some of our intents have an associated address value. # Capture that into session data here set_address_in_session(mycity_request) if "Zipcode" in mycity_request.intent_variables \ and "value" in mycity_request.intent_variables["Zipcode"]: set_zipcode_in_session(mycity_request) # session_attributes = session.get("attributes", {}) if mycity_request.intent_name == "GetAddressIntent": return get_address_from_session(mycity_request) elif mycity_request.intent_name == "TrashDayIntent": return get_trash_day_info(mycity_request) elif mycity_request.intent_name == "SnowParkingIntent": return get_snow_emergency_parking_intent(mycity_request) elif mycity_request.intent_name == "CrimeIncidentsIntent": return get_crime_incidents_intent(mycity_request) elif mycity_request.intent_name == "FoodTruckIntent": return get_nearby_food_trucks(mycity_request) elif mycity_request.intent_name == "GetAlertsIntent": return get_alerts_intent(mycity_request) elif mycity_request.intent_name == "AMAZON.HelpIntent": return get_help_response(mycity_request) elif mycity_request.intent_name == "AMAZON.StopIntent" or \ mycity_request.intent_name == "AMAZON.CancelIntent" or \ mycity_request.intent_name == "AMAZON.NavigateHomeIntent": return handle_session_end_request(mycity_request) elif mycity_request.intent_name == "FeedbackIntent": return submit_feedback(mycity_request) elif mycity_request.intent_name == "AMAZON.FallbackIntent": return fallback_intent(mycity_request) elif mycity_request.intent_name == "LatestThreeOneOne": return get_311_requests(mycity_request) elif mycity_request.intent_name == "InclementWeatherIntent": return get_inclement_weather_alert(mycity_request) elif mycity_request.intent_name == "FarmersMarketIntent": return get_farmers_markets_today(mycity_request) elif mycity_request.intent_name == "CoronavirusUpdateIntent": return get_coronovirus_update(mycity_request) else: raise ValueError("Invalid intent")
def test_that_get_alerts_intent_will_end_session(self): response = get_alerts_intent.get_alerts_intent( self.request, self.stub_get_alerts, self.stub_prune_normal_responses, self.stub_alerts_to_speech ) self.assertTrue(response.should_end_session)
def test_that_get_alerts_intent_sets_reponse_output_speech_with_return_value_of_alerts_to_speech( self): output_speech = 'Bingo' self.alerts_to_speech_return_string = output_speech response = get_alerts_intent.get_alerts_intent( self.request, self.stub_get_alerts, self.stub_prune_normal_responses, self.stub_alerts_to_speech) self.assertEqual(output_speech, response.output_speech)