def submit_feedback(mycity_request):
    """
    Logs user feedback to the mycity-feedback slack channel.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    print(
        '[module: feedback_intent]',
        '[method: submit_feedback]',
        'MyCityRequestDataModel received:',
        mycity_request.get_logger_string()
    )
    # get the intent_variables object from the request
    intent_variables = mycity_request.intent_variables

    # Build the response.
    #   - if we are missing the feedback type or feedback text, we'll delegate
    #     to the dialog model to request the missing information
    #   - if we have everything we need, we'll pose the message to slack and
    #     confirm to the user
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.should_end_session = False
    if (
            'value' not in intent_variables['FeedbackType'] or
            'value' not in intent_variables['Feedback']
    ):
        mycity_response.intent_variables = intent_variables
        mycity_response.dialog_directive = "Delegate"
        return mycity_response
    else:
        feedback_type = intent_variables['FeedbackType']['value']
        feedback_text = intent_variables['Feedback']['value']

        try:
            status = send_to_slack(
                build_slack_message(feedback_type, feedback_text)
            )
            if status == 200:
                mycity_response.output_speech = speech_constants.BIG_THANKS
            else:
                mycity_response.output_speech = speech_constants.PROBLEM_SAVING_FEEDBACK
        except Exception:
            mycity_response.output_speech = speech_constants.PROBLEM_SAVING_FEEDBACK

        mycity_response.reprompt_text = None
        mycity_response.session_attributes = mycity_request.session_attributes
        mycity_response.card_title = CARD_TITLE
    return mycity_response
def get_address_from_session(mycity_request):
    """
    Looks for a current address in the session attributes and constructs a
    response based on whether one exists or not. If one exists, it is
    preserved in the session.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('MyCityRequestDataModel received:' +
                 mycity_request.get_logger_string())

    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Address"
    mycity_response.reprompt_text = None
    mycity_response.should_end_session = False

    if intent_constants.CURRENT_ADDRESS_KEY in \
            mycity_request.session_attributes:
        current_address = mycity_request.session_attributes[
            intent_constants.CURRENT_ADDRESS_KEY]
        mycity_response.output_speech = "Your address is " + \
                                        current_address + "."
    else:
        mycity_response.output_speech = "I'm not sure what your address is. " \
                                        "You can tell me your address by " \
                                        "saying, \"my address is\" followed " \
                                        "by your address."

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. They will be returned to the top level of the skill and must
    # provide input that corresponds to an intent to continue.

    return mycity_response
def get_alerts_intent(mycity_request):
    """
    Generate response object with information about citywide alerts

    :param mycity_request: MyCityRequestModel object
    :param mycity_response: MyCityResponseModel object
    :return: MyCityResponseModel object
    """
    print(
        '[method: get_alerts_intent]',
        'MyCityRequestDataModel received:\n',
        str(mycity_request)
    )

    mycity_response = MyCityResponseDataModel()
    alerts = get_alerts()
    print("[dictionary with alerts scraped from boston.gov]:\n" + str(alerts))
    alerts = prune_normal_responses(alerts)
    print("[dictionary after pruning]:\n" + str(alerts))

    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name
    mycity_response.reprompt_text = None
    mycity_response.output_speech = alerts_to_speech_output(alerts)
    mycity_response.should_end_session = True   # leave this as True for right now
    return mycity_response
def get_snow_emergency_parking_intent(mycity_request):
    """
    Populate MyCityResponseDataModel with snow emergency parking response information.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    print(
        '[method: get_snow_emergency_parking_intent]',
        'MyCityRequestDataModel received:',
        str(mycity_request)
    )

    mycity_response = MyCityResponseDataModel()
    if intent_constants.CURRENT_ADDRESS_KEY in mycity_request.session_attributes:
        finder = FinderCSV(mycity_request, PARKING_INFO_URL, ADDRESS_KEY, 
                           OUTPUT_SPEECH_FORMAT, format_record_fields)
        print("Finding snow emergency parking for {}".format(finder.origin_address))
        finder.start()
        mycity_response.output_speech = finder.get_output_speech()

    else:
        print("Error: Called snow_parking_intent with no address")

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name
    
    return mycity_response
示例#5
0
def get_crime_incidents_intent(mycity_request):
    """
    Populate MyCityResponseDataModel with crime incidents response information.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('[method: get_crime_incidents_intent]')

    mycity_response = MyCityResponseDataModel()
    if intent_constants.CURRENT_ADDRESS_KEY in \
            mycity_request.session_attributes:
        address = mycity_request. \
            session_attributes[intent_constants.CURRENT_ADDRESS_KEY]
        response = get_crime_incident_response(address)
        mycity_response.output_speech = \
            _build_text_from_response(response)
    else:
        logger.debug("Error: Called crime_incidents_intent with no address")

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = CARD_TITLE_CRIME
    mycity_response.should_end_session = True

    return mycity_response
def request_user_address_response(mycity_request):
    """
    Creates a response to request the user's address

    :param mycity_request: MyCityRequestModel object
    :param mycity_request: MyCityResponseModel object
    :return: MyCityResponseModel object
    """
    print(
        '[module: user_address_intent]',
        '[method: set_address_in_session]',
        'MyCityRequestDataModel received:',
        str(mycity_request)
    )

    mycity_response = MyCityResponseDataModel()
    mycity_request.session_attributes[intent_constants.ADDRESS_PROMPTED_FROM_INTENT] = \
        mycity_request.intent_name
    
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name
    
    mycity_response.output_speech = "I'm not sure what your address is. " \
                                    "You can tell me your address by saying, " \
                                    "\"my address is\" followed by your address."
    mycity_response.should_end_session = False
    mycity_response.reprompt_text = None
    return mycity_response
示例#7
0
def get_welcome_response(mycity_request):
    """
    Welcomes the user and sets initial session attributes. Is triggered on
    initial launch and on AMAZON.HelpIntent.

    If we wanted to initialize the session to have some attributes we could
    add those here.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will initiate
        a welcome process on the user's device
    """
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Welcome"
    mycity_response.output_speech = \
        "Welcome to the Brookline Info skill. How can I help you? "

    # If the user either does not reply to the welcome message or says
    # something that is not understood, they will be prompted again with
    # this text.
    mycity_response.reprompt_text = \
        "You can ask about the nearest city services."
    mycity_response.should_end_session = False
    return mycity_response
示例#8
0
def get_welcome_response(mycity_request):
    """
    Welcomes the user and sets initial session attributes. Is triggered on
    initial launch and on AMAZON.HelpIntent.

    If we wanted to initialize the session to have some attributes we could
    add those here.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will initiate
        a welcome process on the user's device
    """
    logger.debug('')
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Welcome"
    mycity_response.output_speech = LAUNCH_SPEECH
    mycity_response.output_speech_type = "PlainText"

    # If the user either does not reply to the welcome message or says
    # something that is not understood, they will be prompted again with
    # this text.
    mycity_response.reprompt_text = LAUNCH_REPROMPT_SPEECH
    mycity_response.should_end_session = False
    return mycity_response
示例#9
0
def get_welcome_response(mycity_request):
    """
    Welcomes the user and sets initial session attributes. Is triggered on
    initial launch and on AMAZON.HelpIntent.

    If we wanted to initialize the session to have some attributes we could
    add those here.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will initiate
        a welcome process on the user's device
    """
    print(LOG_CLASS, '[method: get_welcome_response]')
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Welcome"
    mycity_response.output_speech = \
        "Welcome to the Boston Public Services skill. How can I help you? "

    # If the user either does not reply to the welcome message or says
    # something that is not understood, they will be prompted again with
    # this text.
    mycity_response.reprompt_text = \
        "For example, you can tell me your address by saying, " \
        "\"my address is\" followed by your address."
    mycity_response.should_end_session = False
    return mycity_response
示例#10
0
 def handle_session_end_request(self, mycity_request):
     mycity_response = MyCityResponseDataModel()
     mycity_response.session_attributes = mycity_request.session_attributes
     mycity_response.card_title = "Boston Public Services - Thanks"
     mycity_response.output_speech = \
         "Thank you for using the Boston Public Services skill. " \
         "See you next time!"
     mycity_response.should_end_session = True
     return mycity_response
示例#11
0
def get_crime_incidents_intent(mycity_request):
    """
    Populate MyCityResponseDataModel with crime incidents response information.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('[method: get_crime_incidents_intent]')

    coordinates = {}
    current_address = None
    if intent_constants.CURRENT_ADDRESS_KEY not in \
            mycity_request.session_attributes:
        coordinates = get_address_coordinates_from_geolocation(mycity_request)

        if not coordinates:
            if mycity_request.device_has_geolocation:
                return request_geolocation_permission_response()

            # Try getting registered device address
            mycity_request, location_permissions \
                = get_address_from_user_device(mycity_request)
            if not location_permissions:
                return request_device_address_permission_response()

    # Convert address to coordinates if we only have user address
    if intent_constants.CURRENT_ADDRESS_KEY \
            in mycity_request.session_attributes:
        current_address = mycity_request.session_attributes[
            intent_constants.CURRENT_ADDRESS_KEY]
        coordinates = gis_utils.geocode_address(current_address)

    # If we don't have coordinates by now, and we have all required
    #  permissions, ask the user for an address
    if not coordinates:
        return request_user_address_response(mycity_request)

    mycity_response = MyCityResponseDataModel()

    # If our address/coordinates are not in Boston, send a response letting
    # the user know the intent only works in Boston.
    if not is_location_in_city(current_address, coordinates):
        mycity_response.output_speech = NOT_IN_BOSTON_SPEECH
    else:
        response = get_crime_incident_response(coordinates)
        mycity_response.output_speech = \
            _build_text_from_response(response)

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = CARD_TITLE_CRIME
    mycity_response.should_end_session = True

    return mycity_response
示例#12
0
def get_fallback_intent_response(mycity_request):
    """
    Returns a generic fallback intent reponse

    :param mycity_request: MyCityRequestDataModel with user's request
    :return MyCityResponseDataModel with reponse for fallback intent
    """
    LOGGER.debug("Fallback intent called")

    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = CARD_TITLE
    mycity_response.output_speech = OUTPUT_SPEECH
    mycity_response.should_end_session = False
    return mycity_response
def unhandled_intent(mycity_request):
    """
    Deals with unhandled intents by prompting the user again
    """
    print('[module: unhandled_intent]', '[method: unhandled_intent]',
          'MyCityRequestDataModel received:', str(mycity_request))
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Unhandled intent"
    mycity_response.reprompt_text = "So, what can I help you with today?"
    mycity_response.output_speech = "I'm not sure what you're asking me. " \
                        "Please ask again."
    mycity_response.should_end_session = False

    return mycity_response
示例#14
0
def handle_session_end_request(mycity_request):
    """
    Ends a user's session (with the Boston Data skill). Called when request
    intent is AMAZON.StopIntent or AMAZON.CancelIntent.
    
    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will end a user's session
    """
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Boston Public Services - Thanks"
    mycity_response.output_speech = \
        "Thank you for using the Boston Public Services skill. " \
        "See you next time!"
    mycity_response.should_end_session = True
    return mycity_response
def get_help_response(mycity_request):
    """
    Provides an overview of the skill. This is triggered by AMAZON.HelpIntent.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will initiate
        a help process on the user's device
    """
    logger.debug('')
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Help"
    mycity_response.output_speech = HELP_SPEECH
    mycity_response.reprompt_text = None
    mycity_response.should_end_session = False
    return mycity_response
示例#16
0
def get_trash_day_info(mycity_request):
    """
    Generates response object for a trash day inquiry.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """

    print('[module: trash_intent]', '[method: get_trash_day_info]',
          'MyCityRequestDataModel received:', str(mycity_request))

    mycity_response = MyCityResponseDataModel()
    if intent_constants.CURRENT_ADDRESS_KEY in mycity_request.session_attributes:
        current_address = \
            mycity_request.session_attributes[intent_constants.CURRENT_ADDRESS_KEY]

        # grab relevant information from session address
        address_parser = StreetAddressParser()
        a = address_parser.parse(current_address)
        # currently assumes that trash day is the same for all units at
        # the same street address
        address = str(a['house']) + " " + str(a['street_name'])

        try:
            trash_days = get_trash_and_recycling_days(address)
            trash_days_speech = build_speech_from_list_of_days(trash_days)

            mycity_response.output_speech = "Trash and recycling is picked up on {}."\
                .format(trash_days_speech)

        except InvalidAddressError:
            mycity_response.output_speech = "I can't seem to find {}. Try another address"\
               .format(address)
        except BadAPIResponse:
            mycity_response.output_speech = "Hmm something went wrong. Maybe try again?"

        mycity_response.should_end_session = False
    else:
        print("Error: Called trash_day_intent with no address")

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name
    return mycity_response
示例#17
0
def handle_session_end_request(mycity_request):
    """
    Ends a user's session (with the Brookline Info skill).
    Called when request intent is AMAZON.StopIntent.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will end a user's session
    """
    logger.debug('Closing')
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Brookline Info - Thanks"
    mycity_response.output_speech = \
        "Thank you for using the Brookline Info skill. " \
        "See you next time!"
    mycity_response.should_end_session = True
    return mycity_response
示例#18
0
def unhandled_intent(mycity_request):
    """
    Deals with unhandled intents by prompting the user again
    
    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('MyCityRequestDataModel received:' +
                 mycity_request.get_logger_string())

    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = CARD_TITLE
    mycity_response.reprompt_text = speech_constants.REPROMPT_TEXT
    mycity_response.output_speech = speech_constants.OUTPUT_SPEECH
    mycity_response.should_end_session = False

    return mycity_response
def request_user_address_response(mycity_request):
    """
    Creates a response to request the user's address

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('MyCityRequestDataModel received:' +
                 mycity_request.get_logger_string())

    mycity_response = MyCityResponseDataModel()

    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.should_end_session = False
    mycity_response.output_speech = "What's your address?"
    mycity_response.card_title = "Address"
    mycity_response.dialog_directive = "Delegate"
    return mycity_response
def get_coronovirus_update(mycity_request):
    """
    Get the latest information about the coronavirus from boston.gov

    :param mycity_request: MyCityRequestDataModel with the user request for information
    :return: MyCityResponseDataModel containing information from boston.gov
    """
    mycity_response = MyCityResponseDataModel()
    mycity_response.card_title = INTENT_CARD_TITLE
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.should_end_session = True
    try:
        mycity_response.output_speech = _construct_output_speech(
            _get_homepage_text(), _get_coronavirus_detail_text())
    except ParseError:
        mycity_response.output_speech = NO_UPDATE_ERROR

    return mycity_response
def get_snow_emergency_parking_intent(mycity_request):
    """
    Populate MyCityResponseDataModel with snow emergency parking response information.

    :param mycity_request: MyCityRequestModel object
    :param mycity_response: MyCityResponseModel object
    :return: MyCityResponseModel object
    """
    print('[method: get_snow_emergency_parking_intent]',
          'MyCityRequestDataModel received:', str(mycity_request))

    mycity_response = MyCityResponseDataModel()
    if intent_constants.CURRENT_ADDRESS_KEY in mycity_request.session_attributes:

        origin_address = _build_origin_address(mycity_request)

        print("Finding snow emergency parking for {}".format(origin_address))

        parking_address, driving_distance, driving_time = \
            _get_snow_emergency_parking_location(origin_address)

        if not parking_address:
            mycity_response.output_speech = "Uh oh. Something went wrong!"
        else:
            mycity_response.output_speech = \
                "The closest snow emergency parking location is at " \
                "{}. It is {} away and should take you {} to drive " \
                "there".format(parking_address, driving_distance, driving_time)

        mycity_response.should_end_session = False
    else:
        print("Error: Called snow_parking_intent with no address")

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name

    return mycity_response
示例#22
0
def request_user_address_response(mycity_request):
    """
    Creates a response to request the user's address

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    print(
        '[module: user_address_intent]',
        '[method: set_address_in_session]',
        'MyCityRequestDataModel received:',
        str(mycity_request)
    )

    mycity_response = MyCityResponseDataModel()

    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.should_end_session = False

    mycity_response.dialog_directive = "Delegate"
    return mycity_response
示例#23
0
def get_help_response(mycity_request):
    """
    Provides an overview of the skill. This is triggered by AMAZON.HelpIntent.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object that will initiate
        a help process on the user's device
    """
    logger.debug('')
    mycity_response = MyCityResponseDataModel()
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Help"
    mycity_response.output_speech = (
        "You are using Boston Info, a skill that provides general information "
        "about Boston. You can currently ask about your trash and recycling "
        "pickup schedule, the location of the nearest snow emergency parking,"
        "and current alerts from Boston.gov. If you have feedback for the "
        "skill, say, 'I have a suggestion.'")
    mycity_response.reprompt_text = None
    mycity_response.should_end_session = False
    return mycity_response
def get_farmers_markets_today(mycity_request):
    """
    Get all available farmers markets today

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseObject
    """
    mycity_response = MyCityResponseDataModel()

    # List all available farmers markets today
    markets = gis_utils.get_features_from_feature_server(BASE_URL, QUERY)

    try:
        # Loop through the list of available farmers markets at a certain day
        markets_today = []
        for m in markets:
            if m not in markets_today and \
                    m['attributes']['Day_of_Week'] == DAY:
                markets_today.append(m)

        response = 'Available farmers markets today are:\n'
        for m in markets_today:
            response += m['attributes']['Name'] + ' located at ' + \
                        m['attributes']['Address'] + ' from ' + \
                        m['attributes']['Hours'] + '. '
        mycity_response.output_speech = response

    except BadAPIResponse:
        mycity_response.output_speech = \
            "Hmm something went wrong. Maybe try again?"

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = "Farmers Markets"
    mycity_response.should_end_session = True

    return mycity_response
示例#25
0
def execute_request(mycity_request):
    """
    Executes a request to the town of Brookline available intents
    :param mycity_request: MyCityRequestDataModel with intent request info
    :return: MyCityResponseDataModel with response to provide to user.
    """

    if mycity_request.is_new_session:
        mycity_request = on_session_started(mycity_request)

    if mycity_request.request_type == "LaunchRequest":
        response = get_welcome_response(mycity_request)
    elif mycity_request.request_type == "IntentRequest":
        response = on_intent(mycity_request)
    elif mycity_request.request_type == "SessionEndedRequest":
        response = on_session_ended(mycity_request)
    else:
        response = MyCityResponseDataModel()
        response.output_speech = "Hello from Brookline! We do not support that yet"

    response.session_attributes = mycity_request.session_attributes
    return response
示例#26
0
def find_closest_police_station(mycity_request):
    """
    Finds the closest police station in Brookline
    to a given address

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('Finding closest police station')

    response = MyCityResponseDataModel()
    set_address_in_session(mycity_request)
    response.session_attributes = mycity_request.session_attributes
    current_address = \
            mycity_request.session_attributes.get(intent_constants.CURRENT_ADDRESS_KEY)
    if current_address is None:
        response.dialog_directive = "Delegate"
    else:
        response.output_speech = _get_output_speech_for_address(
            current_address)

    return response
def get_address_from_session(mycity_request):
    """
    Looks for a current address in the session attributes and constructs a
    response based on whether one exists or not. If one exists, it is
    preserved in the session.

    :param mycity_request: MyCityRequestDataModel
    :param mycity_response: MyCityResponseDataModel
    :return : MyCityResponseModel object
    """
    print(
        '[module: user_address_intent]',
        '[method: get_address_from_session]',
        'MyCityRequestDataModel received:',
        str(mycity_request)
    )

    mycity_response = MyCityResponseDataModel()
    # print("GETTING ADDRESS FROM SESSION")
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = mycity_request.intent_name
    mycity_response.reprompt_text = None
    mycity_response.should_end_session = False

    if intent_constants.CURRENT_ADDRESS_KEY in mycity_request.session_attributes:
        current_address = mycity_request.session_attributes[
            intent_constants.CURRENT_ADDRESS_KEY]
        mycity_response.output_speech = "Your address is " + current_address + "."
    else:
        mycity_response.output_speech = "I'm not sure what your address is. " \
                                        "You can tell me your address by saying, " \
                                        "\"my address is\" followed by your address."

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. They will be returned to the top level of the skill and must
    # provide input that corresponds to an intent to continue.

    return mycity_response
示例#28
0
    def get_welcome_response(self, mycity_request):
        """
        If we wanted to initialize the session to have some attributes we could
        add those here.
        """
        print(
            self.LOG_CLASS,
            '[method: get_welcome_response]'
        )
        mycity_response = MyCityResponseDataModel()
        mycity_response.session_attributes = mycity_request.session_attributes
        mycity_response.card_title = "Welcome"
        mycity_response.output_speech = \
            "Welcome to the Boston Public Services skill. How can I help you? "

        # If the user either does not reply to the welcome message or says
        # something that is not understood, they will be prompted again with
        # this text.
        mycity_response.reprompt_text = \
            "For example, you can tell me your address by saying, " \
            "\"my address is\" followed by your address."
        mycity_response.should_end_session = False
        return mycity_response
示例#29
0
def get_snow_emergency_parking_intent(mycity_request):
    """
    Populate MyCityResponseDataModel with snow emergency parking response information.

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('MyCityRequestDataModel received:' +
                 mycity_request.get_logger_string())

    mycity_response = MyCityResponseDataModel()
    if intent_constants.CURRENT_ADDRESS_KEY in mycity_request.session_attributes:
        try:
            finder = FinderCSV(mycity_request, PARKING_INFO_URL, ADDRESS_KEY,
                               constants.OUTPUT_SPEECH_FORMAT,
                               format_record_fields)
        except InvalidAddressError:
            mycity_response.output_speech = constants.ERROR_INVALID_ADDRESS
        else:
            print("Finding snow emergency parking for {}".format(
                finder.origin_address))
            finder.start()
            mycity_response.output_speech = finder.get_output_speech()

    else:
        print("Error: Called snow_parking_intent with no address")
        mycity_response.output_speech = constants.ERROR_SPEECH

    # Setting reprompt_text to None signifies that we do not want to reprompt
    # the user. If the user does not respond or says something that is not
    # understood, the session will end.
    mycity_response.reprompt_text = None
    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = SNOW_PARKING_CARD_TITLE
    mycity_response.should_end_session = True

    return mycity_response
def get_alerts_intent(mycity_request):
    """
    Generate response object with information about citywide alerts

    :param mycity_request: MyCityRequestDataModel object
    :return: MyCityResponseDataModel object
    """
    logger.debug('MyCityRequestDataModel received:' +
                 mycity_request.get_logger_string())

    mycity_response = MyCityResponseDataModel()
    alerts = get_alerts()
    logger.debug("[dictionary with alerts scraped from boston.gov]:\n" +
                 str(alerts))

    alerts = prune_normal_responses(alerts)
    logger.debug("[dictionary after pruning]:\n" + str(alerts))

    mycity_response.session_attributes = mycity_request.session_attributes
    mycity_response.card_title = ALERTS_INTENT_CARD_TITLE
    mycity_response.reprompt_text = None
    mycity_response.output_speech = alerts_to_speech_output(alerts)
    mycity_response.should_end_session = True  # leave this as True for right now
    return mycity_response