Python Amazon lex未保存未定义的自定义插槽值

Python Amazon lex未保存未定义的自定义插槽值,python,aws-lambda,amazon-lex,Python,Aws Lambda,Amazon Lex,我正在尝试建立一个机器人,可以告诉学生餐厅的菜单日期和膳食。我在Python3中使用了一个lambda函数来验证自定义插槽的用户输入,但似乎lex没有将输入从null更改为用户输入并传递给函数,因此它没有提示错误消息。我假设错误不在lambda函数中,因为它在测试中正确地提示了错误消息 例如,在我输入日期后,机器人会问我“要哪顿饭”。如果我说“早餐”、“午餐”或“晚餐”,机器人会继续问我哪个餐厅。但是如果我有一个拼写错误,并且我输入了“lumch”而不是“午餐”,我希望它会提示“请输入有效的膳食

我正在尝试建立一个机器人,可以告诉学生餐厅的菜单日期和膳食。我在Python3中使用了一个lambda函数来验证自定义插槽的用户输入,但似乎lex没有将输入从null更改为用户输入并传递给函数,因此它没有提示错误消息。我假设错误不在lambda函数中,因为它在测试中正确地提示了错误消息

例如,在我输入日期后,机器人会问我“要哪顿饭”。如果我说“早餐”、“午餐”或“晚餐”,机器人会继续问我哪个餐厅。但是如果我有一个拼写错误,并且我输入了“lumch”而不是“午餐”,我希望它会提示“请输入有效的膳食类型。早餐、午餐或晚餐”,但它只是不断提示“哪种膳食?”。同样的事情也发生在我的位置槽上。当我输入一个无效的位置时,例如“nyc hall”,lex会询问“哪个餐厅”,而不是提示“学校没有这样的餐厅。请重试”。我的自定义插槽类型MealType DinningHalls在插槽解析时都设置为“expand Value”,相应的插槽名称为“Dine”和“location”

我的代码的验证部分:

def validate_get_menu(meal, location):  
    meal_types = ["breakfast", "lunch", "dinner", "supper"]
                
    cal_synonyms = ["california avenue dinning hall", "california hall", "cal hall"]
    ny_synonyms = ["new york street dinning hall", "new york hall", "ny hall"]
        
    if (meal is not None and meal.lower() not in meal_types):
        return build_validation_result(False, "Meal", "Please enter a valid meal type. Breakfast, lunch, or dinner.")
           
    if (location is not None):
        
        location = location.lower()

        if (location not in cal_synonyms and location not in ny_synonyms):
            return build_validation_result(False, "Location", "There is not such dinning hall at the school. Try again.")
            
        if (meal is not None and meal.lower() == 'breakfast' and (location in cal_synonyms)):
            return build_validation_result(False, "Location", "This location does not serve breakfast. Which other dinning halls are you interested in?")
    
    return build_validation_result(True, None, None)


def fetch_menu(intent_request):
    slots = get_slots(intent_request)
    date = slots['Date']
    meal = slots['Meal']
    location = slots['Location']
    source = intent_request['invocationSource']
    
    if (source == "DialogCodeHook"):
        # begin validation
        validation_result = validate_get_menu(date, meal, location)
         
        if (not validation_result['isValid']):
            # faulty input 
            slots[validation_result['violatedSlot']] = None
            return elicit_slot(intent_request['sessionAttributes'], 
                                intent_request['currentIntent']['name'],
                                slots,
                                validation_result['violatedSlot'],
                                validation_result['message'])
        
        output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}

        return delegate(output_session_attributes, get_slots(intent_request))
    
    # In a real bot, this will involve a call to a backend service.
    if (meal is not None):
        menu = build_menu(meal.lower())
        
    return close(intent_request['sessionAttributes'],
                 'Fulfilled',
                 {'contentType': 'PlainText',
                  'content': 'The {} menu for {} at {} are {}.'.format(meal, date, location, menu)})