正则表达式验证代码不接受AWS lexbot验证

时间:2017-08-31 10:28:48

标签: regex validation amazon-web-services amazon-lex

我使用正则表达式代码验证lambda中的电子邮件和电话号码以验证AWS lexbot但是它发生错误(发生错误:Lambda响应无效:Lambda收到错误响应:未处理)。

enter image description here

我在这个特定的机器人中创建了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 --- """

0 个答案:

没有答案