使用CodeHook验证时,Amazon Lex不提示缺少变量 [英] Amazon Lex not prompting for missing variables when using CodeHook Validation

查看:65
本文介绍了使用CodeHook验证时,Amazon Lex不提示缺少变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Amazon Lex中建立具有3个目的的代理.所有这三个intent都有一个已被标记为"required"的变量,这意味着代理在用户查询丢失时必须提示输入这些变量.

I am building an agent in Amazon Lex with around 3 intents. All the 3 intents have a variable which has been ticked as 'required', meaning the agent has to prompt for those variables when the user query is missing it.

但是,当我使用lambda函数作为代码钩子验证时,会触发,而无需提示缺少变量.

However when I am using a lambda function as codehook validation the , function gets triggered without prompting for the missing variable.

例如:Intent,用于描述与特定人员的通话中的通话记录:

For example: Intent which describes call notes from a call with a specific person:

提示是指定要查看其笔记的人的名字.

The prompt is " Specify the name of the person whose notes you want to see'

lambda函数的目的是打印出该人的通话记录为XYZ'

The objective of the lambda function is to print out "Call notes for the person is XYZ'

当我不通过代码钩子验证使用任何lambda函数时,我会提示输入人名,

When I don't use any lambda function through codehook validation, I get a prompt for the name of the person,

但是当我使用codehook验证时,lambda函数被触发,并且得到的答复为无呼叫的注释为XYZ".

but when I use codehook validation, the lambda function gets triggered and I get the reply as "Call notes for None is XYZ".

没有,因为,用户查询中没有提及此人的名字,也没有提示我输入该人的名字.

None because , there wasn't any mention of the person's name in the user query nor am I getting prompted for the person's name.

有人可以为此提供帮助吗?我已经尝试过对lambda函数进行各种修改,但是提示是否不应该是独立于lambda函数的功能?

Can anybody help regarding this? I have tried all sorts of modifications in the lambda function , but shouldn't the prompt be an independent functionality from the lambda function?

从2到3天以来,我一直在浏览和尝试与此有关的事情,但都陷入了僵局.

I have been browsing and trying things regarding this since 2~3 days and have hit a dead end.

推荐答案

之所以发生这种情况,是因为 Lambda初始化和验证发生在Amazon Lex中的插槽填充之前. 您仍然可以检查用户是否在DialogCodeHook中提供了"person"插槽,即验证部分. 下面的代码将帮助您完成工作:

This is happening because Lambda initialization and validation happens before Slot filling in Amazon Lex. You can still check that user have provided the "person" slot in DialogCodeHook i.e validation part. Something like below code will get your work done:

def build_validation_result(is_valid, violated_slot, message_content):
    if message_content == None:
        return {
            'isValid': is_valid,
            'violatedSlot': violated_slot
        }
    return {
        'isValid': is_valid,
        'violatedSlot': violated_slot,
        'message': {'contentType': 'PlainText', 'content': message_content}
    }


def validate_person(person):
    # apply validations here
    if person is None:
        return build_validation_result(False, 'person', 'Please enter the person name')
    return build_validation_result(True, None, None)


def get_notes(intent_request):
    source = intent_request['invocationSource']
    output_session_attributes = intent_request['sessionAttributes'] if intent_request['sessionAttributes'] is not None else {}
    slots = intent_request['currentIntent']['slots']
    person = slots['person']
    if source == 'DialogCodeHook':
        # check existence of "person" slot
        validation_result = validate_person(person)
        if not validation_result['isValid']:
            slots[ticket_validation_result['violatedSlot']] = None
            return elicit_slot(
                output_session_attributes,
                intent_request['currentIntent']['name'],
                slots,
                validation_result['violatedSlot'],
                validation_result['message']
            )
        return delegate(output_session_attributes, slots)

如果人员"插槽为空,将提示用户错误消息.这样,您无需在广告位上的必填"上打钩. 这是我在使用DialogCodeHook时遇到此问题时唯一想到的解决方法. 希望对您有所帮助.

If the "person" slot is empty, user will be prompted the error message. This way you don't need to tick on "Required" on the slot. This was the only workaround I could think of when I faced this problem while using DialogCodeHook. Hope it helps.

这篇关于使用CodeHook验证时,Amazon Lex不提示缺少变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆