def get_slot_values()

in functions/source/kendra_search_intent_handler_lambda/helpers.py [0:0]


def get_slot_values(slot_values, intent_request):
    """
    Get slot values for each slot.
    :param slot_values: Slot values
    :param intent_request: Requested Intent
    :return: Slot values
    """
    if slot_values is None:
        slot_values = {key: None for key in help_desk_config.SLOT_CONFIG}

    slots = intent_request['currentIntent']['slots']

    for key, config in help_desk_config.SLOT_CONFIG.items():
        slot_values[key] = slots.get(key)
        logger.debug('<<help_desk_bot>> retrieving slot value for %s = %s', key, slot_values[key])
        if slot_values[key]:
            if config.get(
                    'type', help_desk_config.ORIGINAL_VALUE) == help_desk_config.TOP_RESOLUTION:
                # get the resolved slot name of what the user said/typed
                if len(intent_request['currentIntent']['slotDetails'][key]['resolutions']) > 0:
                    slot_values[key] = intent_request['currentIntent'][
                        'slotDetails'][key]['resolutions'][0]['value']
                else:
                    error_msg = help_desk_config.SLOT_CONFIG[key].get(
                        'error', 'Sorry, I don\'t understand "{}".')
                    raise help_desk_config.SlotError(error_msg.format(slots.get(key)))

    return slot_values