【问题标题】:How to use Amazon Lex to capture user's random string input如何使用 Amazon Lex 捕获用户的随机字符串输入
【发布时间】:2020-11-11 04:31:25
【问题描述】:

我需要接受可以是任何字符串的用户输入,但 Lex 不支持 AMAZON.Literal 类型。我看过其他文章谈论使用intent_request,但我无法使其工作。

在我的设置中,我只有一个话语:{string}。 我还将“字符串”定义为使用 AlphaNumeric 类型的插槽,未选中“必需”。 (我什至应该使用 AlphaNumeric 吗?)

在我的初始化和验证 Lambda 函数中,我有这个:

def delegate(session_attributes, slots):
    return {
        'sessionAttributes': session_attributes,
        'dialogAction': {
            'type': 'Delegate',
            'slots': slots
        }
    }

def perform_action(intent_request):
    source = intent_request['invocationSource']
    slots = intent_request['currentIntent']['slots']
    if source == 'DialogCodeHook':
        slots['string'] = intent_request['inputTranscript']
        return delegate({}, slots)

def dispatch(intent_request):
    return perform_action(intent_request)

def lambda_handler(event, context):
    return dispatch(event)

如果我输入“abc”之类的内容,就可以了(因为它是纯 AlphaNumeric)。但是,如果我输入“这是什么”之类的内容,那么它总是会返回“对不起,你能重复一遍吗?”。看来,即使使用 Lambda 函数,槽类型“AlphaNumeric”仍然可以发挥作用。我尝试了其他几种类型,但没有任何效果。

我在这里缺少什么?如何让它接受任何随机字符串?

谢谢。

【问题讨论】:

    标签: aws-lambda amazon-lex


    【解决方案1】:
    • 目前还不支持捕获随机字符串。
    • 但您可以使用 Amazon.organization 来捕获随机字符串
    • 否则,您需要编写自定义代码,例如如果它进入 Fallback 意图,我们需要检查之前的状态。如果先前的状态是您的插槽,则使用用户语句填充插槽值

    【讨论】:

    • 您有自定义代码的示例吗?
    猜你喜欢
    • 2013-10-29
    • 2019-08-05
    • 1970-01-01
    • 2020-12-10
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多