Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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 mycity_request.intent_name == "SetAddressIntent":
        set_address_in_session(mycity_request)
        return get_address_from_session(mycity_request)

    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 request_user_address_response(mycity_request) \
            if intent_constants.CURRENT_ADDRESS_KEY \
            not in mycity_request.session_attributes \
            else get_trash_day_info(mycity_request)
    elif mycity_request.intent_name == "SnowParkingIntent":
        return request_user_address_response(mycity_request) \
            if intent_constants.CURRENT_ADDRESS_KEY \
            not in mycity_request.session_attributes \
            else get_snow_emergency_parking_intent(mycity_request)
    elif mycity_request.intent_name == "CrimeIncidentsIntent":
        return request_user_address_response(mycity_request) \
            if intent_constants.CURRENT_ADDRESS_KEY \
            not in mycity_request.session_attributes \
            else get_crime_incidents_intent(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":
        return handle_session_end_request(mycity_request)
    elif mycity_request.intent_name == "FeedbackIntent":
        return submit_feedback(mycity_request)
    elif mycity_request.intent_name == "UnhandledIntent":
        return unhandled_intent(mycity_request)
    elif mycity_request.intent_name == "LatestThreeOneOne":
        return get_311_requests(mycity_request)
    else:
        raise ValueError("Invalid intent")