我使用正则表达式代码在 lambda 中验证电子邮件和电话号码以验证 AWS lexbot,但它引发了错误(发生错误:无效的 Lambda 响应:从 Lambda 接收到错误响应:未处理)。
我在这个特定的机器人中创建了 3 个意图。在这 2 个意图中,但由于这个正则表达式验证代码,一个意图根本没有被检测到。如果我删除这个正则表达式验证代码,它工作正常。
这是我遇到错误的 lambda 意图代码。
""" --- Start greeting --- """
def validate_greeting_intent(usermood,phonenumber,email):
UserMood = ['okay', 'better', 'too gud', 'fine', 'gud', 'happy', 'good', 'great']
if usermood is not None and usermood.lower() not in UserMood:
return build_validation_result(False,
'UserMood',
'Hey start with good greeting conversation, please'
)
if not PHONE_REGEX.match(phonenumber):
return build_validation_result(
False,
'PhoneNumber',
'Please enter valid phone number which contains 10 digits'
)
if not EMAIL_REGEX.match(email):
return build_validation_result(
False,
'Email',
'Please enter valid email address'
)
return build_validation_result(True, None, None)
def greeting_intent(intent_request):
usermood = get_slots(intent_request)['UserMood']
phonenumber = get_slots(intent_request)['PhoneNumber']
email = get_slots(intent_request)['Email']
source = intent_request['invocationSource']
if source == 'DialogCodeHook':
slots = get_slots(intent_request)
validation_result = validate_greeting_intent(usermood,phonenumber,email)
if not validation_result['isValid']:
slots[validation_result['violatedSlot']] = None
return elicit_slot(intent_request['sessionAttributes'],
intent_request['currentIntent']['name'],
slots,
validation_result['violatedSlot'],
validation_result['message'])
# Pass the price of the pizza back through session attributes to be used in various prompts defined
# on the bot model.
output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
if usermood is not None:
output_session_attributes['Price'] = len(usermood) * 5 # Elegant pricing model
return delegate(output_session_attributes, get_slots(intent_request))
return close(intent_request['sessionAttributes'],
'Fulfilled',
{'contentType': 'PlainText',
'content': 'What you want to order'})
""" --- End Greeting --- """