コード例 #1
0
def platform_to_mycity_request(event):
    """
    Translates from Amazon platform request to MyCityRequestDataModel

    :param event: JSON object containing the raw request information received
        from the Alexa service platform
    :return: MyCityRequestDataModel object (formatted to be understood and
        acted on by mycity_controller)
    """
    print("\n\n[module: lambda_function]",
          "[function: platform_to_mycity_request]",
          "Amazon request received:\n", str(event))
    mycity_request = MyCityRequestDataModel()
    mycity_request.request_type = event['request']['type']
    mycity_request.request_id = event['request']['requestId']
    mycity_request.is_new_session = event['session']['new']
    mycity_request.session_id = event['session']['sessionId']
    if 'attributes' in event['session']:
        mycity_request.session_attributes = event['session']['attributes']
    else:
        mycity_request.session_attributes = {}
    mycity_request.application_id = event['session']['application'][
        'applicationId']
    if 'intent' in event['request']:
        mycity_request.intent_name = event['request']['intent']['name']
        if 'slots' in event['request']['intent']:
            mycity_request.intent_variables = event['request']['intent'][
                'slots']
    else:
        mycity_request.intent_name = None
    mycity_request.output_speech = None
    mycity_request.reprompt_text = None
    mycity_request.should_end_session = False

    return mycity_request
コード例 #2
0
def platform_to_mycity_request(event):
    """
    Translates from Amazon platform request to MyCityRequestDataModel

    :param event:
    :return:
    """
    print("\n\n[module: lambda_function]",
          "[function: platform_to_mycity_request]",
          "Amazon request received:\n", str(event))
    mycity_request = MyCityRequestDataModel()
    mycity_request.request_type = event['request']['type']
    mycity_request.request_id = event['request']['requestId']
    mycity_request.is_new_session = event['session']['new']
    mycity_request.session_id = event['session']['sessionId']
    if 'attributes' in event['session']:
        mycity_request.session_attributes = event['session']['attributes']
    else:
        mycity_request.session_attributes = {}
    mycity_request.application_id = event['session']['application'][
        'applicationId']
    if 'intent' in event['request']:
        mycity_request.intent_name = event['request']['intent']['name']
        if 'slots' in event['request']['intent']:
            mycity_request.intent_variables = event['request']['intent'][
                'slots']
    else:
        mycity_request.intent_name = None
    mycity_request.output_speech = None
    mycity_request.reprompt_text = None
    mycity_request.should_end_session = False

    return mycity_request
コード例 #3
0
def platform_to_mycity_request(event):
    """
    Translates from Amazon platform request to MyCityRequestDataModel

    :param event: JSON object containing the raw request information received
        from the Alexa service platform
    :return: MyCityRequestDataModel object (formatted to be understood and
        acted on by mycity_controller)
    """
    logger.debug('Amazon request received: ' + str(event))
    mycity_request = MyCityRequestDataModel()

    # Get base request information
    mycity_request.request_type = event['request']['type']
    mycity_request.request_id = event['request']['requestId']

    # Get session information
    mycity_request.is_new_session = event['session']['new']
    mycity_request.session_id = event['session']['sessionId']
    mycity_request.application_id = \
        event['session']['application']['applicationId']

    # Get device information
    system_context = event['context']['System']
    device_context = system_context.get('device', {})
    mycity_request.device_id = device_context.get('deviceId', "unknown")
    mycity_request.api_access_token = \
        system_context.get('apiAccessToken', "none")

    # Get location services info
    mycity_request = _get_location_services_info(event, mycity_request)

    if 'attributes' in event['session']:
        mycity_request.session_attributes = event['session']['attributes']
    else:
        mycity_request.session_attributes = {}

    if 'intent' in event['request']:
        mycity_request.intent_name = event['request']['intent']['name']
        if 'slots' in event['request']['intent']:
            mycity_request.intent_variables = \
                event['request']['intent']['slots']
    else:
        mycity_request.intent_name = None
    mycity_request.output_speech = None
    mycity_request.reprompt_text = None
    mycity_request.should_end_session = False

    return mycity_request