def get_address_from_session(intent, session):
    """
    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.
    """
    # print("GETTING ADDRESS FROM SESSION")
    session_attributes = {}
    reprompt_text = None

    if alexa_constants.CURRENT_ADDRESS_KEY in session.get('attributes', {}):
        current_address = session['attributes'][
            alexa_constants.CURRENT_ADDRESS_KEY]
        speech_output = "Your address is " + current_address + \
                        "."
        session_attributes = session.get('attributes', {})
        should_end_session = False
    else:
        speech_output = "I'm not sure what your address is. " \
                        "You can tell me your address by saying, " \
                        "my address is 123 Main St., apartment 3."
        should_end_session = False

    # 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.
    return build_response(
        session_attributes,
        build_speechlet_response(intent['name'], speech_output, reprompt_text,
                                 should_end_session))
Exemplo n.º 2
0
def get_snow_emergency_parking_intent(intent, session):

    if alexa_constants.CURRENT_ADDRESS_KEY in session.get('attributes', {}):

        origin_address = _build_origin_address(session)

        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:
            speech_output = "Uh oh. Something went wrong!"
        else:
            speech_output = \
                "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)

        session_attributes = session.get('attributes', {})
        should_end_session = True
    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.
    reprompt_text = None
    return build_response(
        session_attributes,
        build_speechlet_response(intent['name'], speech_output, reprompt_text,
                                 should_end_session))
Exemplo n.º 3
0
def set_address_in_session(intent):
    """
    Sets the address in the session and prepares the speech to reply to the
    user.
    """
    # print("SETTING ADDRESS IN SESSION")
    card_title = intent['name']
    session_attributes = {}
    should_end_session = False

    if 'Address' in intent['slots']:
        current_address = intent['slots']['Address']['value']
        session_attributes = create_current_address_attributes(current_address)
        speech_output = "I now know your address is " + \
                        current_address + \
                        ". Now you can ask questions related to your address" \
                        ". For example, when is trash day?"
        reprompt_text = "You can find out when trash is collected for your " \
                        "address by saying, when is trash day?"
    else:
        speech_output = "I'm not sure what your address is. " \
                        "Please try again."
        reprompt_text = "I'm not sure what your address is. " \
                        "You can tell me your address by saying, " \
                        "my address is 123 Main St., apartment 3."
    return build_response(
        session_attributes,
        build_speechlet_response(card_title, speech_output, reprompt_text,
                                 should_end_session))
Exemplo n.º 4
0
def handle_session_end_request():
    card_title = "Boston Public Services - Thanks"
    speech_output = "Thank you for using the Boston Public Services skill. " \
                    "See you next time!"
    should_end_session = True
    return build_response({},
                          build_speechlet_response(card_title, speech_output,
                                                   None, should_end_session))
Exemplo n.º 5
0
def unhandled_intent(intent, session):
    """
    Deals with unhandled intents by prompting the user again
    """
    reprompt_text = "So, what can I help you with today?"
    speech_output = "I'm not sure what you're asking me. " \
                    "Please ask again."
    session_attributes = session.get('attributes', {})
    should_end_session = False

    return build_response(
        session_attributes,
        build_speechlet_response(intent['name'], speech_output, reprompt_text,
                                 should_end_session))
Exemplo n.º 6
0
def get_trash_day_info(intent, session):
    """
    Generates response object for a trash day inquiry.
    """
    reprompt_text = None
    print("IN GET_TRASH_DAY_INFO, SESSION: " + str(session))

    if alexa_constants.CURRENT_ADDRESS_KEY in session.get('attributes', {}):
        current_address = \
            session['attributes'][alexa_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'])

        # rest call to data.boston.gov for trash/recycle information
        url = 'https://data.boston.gov/api/action/datastore_search?' + \
              'resource_id=fee8ee07-b8b5-4ee5-b540-5162590ba5c1&q=' + \
              '{{"Address":"{}"}}'.format(address)
        resp = requests.get(url).json()
        print("RESPONSE FROM DATA.BOSTON.GOV: " + str(resp))

        # format script of response
        record = resp['result']['records'][0]
        speech_output = "Trash is picked up on the following days, " + \
            ", ".join(parse_days(record['Trash'])) + \
            ". Recycling is picked up on the following days, " + \
            " ,".join(parse_days(record['Recycling']))

        session_attributes = session.get('attributes', {})
        should_end_session = True
    else:
        session_attributes = session.get('attributes', {})
        speech_output = "I'm not sure what your address is. " \
                        "You can tell me your address by saying, " \
                        "my address is 123 Main St., apartment 3."
        should_end_session = False

    # 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.
    return build_response(
        session_attributes,
        build_speechlet_response(intent['name'], speech_output, reprompt_text,
                                 should_end_session))
def request_user_address_response(intent, session):
    """
    Creates a response to request the user's address
    :param intent: Intent that reqested the user address
    :param session: Current session object
    :return: Alexa response object
    """
    session_attributes = session.get('attributes', {})
    session_attributes[alexa_constants.ADDRESS_PROMPTED_FROM_INTENT] \
        = intent["name"]
    speech_output = "I'm not sure what your address is. " \
                    "You can tell me your address by saying, " \
                    "my address is 123 Main St., apartment 3."
    should_end_session = False
    reprompt_text = None
    return build_response(
        session_attributes,
        build_speechlet_response(intent['name'], speech_output, reprompt_text,
                                 should_end_session))
def create_set_address_intent_response(intent, session):
    card_title = intent['name']
    session_attributes = session["attributes"]
    should_end_session = False

    if 'Address' in intent['slots']:
        current_address = intent['slots']['Address']['value']
        speech_output = "I now know your address is " + \
                        current_address
        reprompt_text = "You can find out when trash is collected for your " \
                        "address by saying, when is trash day?"
    else:
        speech_output = "I'm not sure what your address is. " \
                        "Please try again."
        reprompt_text = "I'm not sure what your address is. " \
                        "You can tell me your address by saying, " \
                        "my address is 123 Main St., apartment 3."
    return build_response(
        session_attributes,
        build_speechlet_response(card_title, speech_output, reprompt_text,
                                 should_end_session))
Exemplo n.º 9
0
def get_welcome_response():
    """
    If we wanted to initialize the session to have some attributes we could
    add those here.
    """

    session_attributes = {}
    card_title = "Welcome"
    speech_output = "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.
    reprompt_text = "For example, if your address is 1 Elm Street, " \
                    "apartment 2, say my address is one elm street " \
                    "apartment 2."
    should_end_session = False
    return build_response(
        session_attributes,
        build_speechlet_response(card_title, speech_output, reprompt_text,
                                 should_end_session))