【问题标题】:AWS Lex - How to share values from one intent to other intentsAWS Lex - 如何将值从一个意图共享到其他意图
【发布时间】:2019-06-19 20:05:38
【问题描述】:

在将 Lambda 与 Lex 和一般脚本结合使用时,我还是个新手。在一个意图中,我要求用户提供他们的名字、姓氏和组织。我想知道是否有一种方法可以在同一个聊天机器人中的其他意图之间共享此信息?例如,当以另一个意图响应用户时,我希望能够在回复给他们的响应中使用他们的名字。我在网上看过,我对如何实现这一点感到非常困惑。任何帮助都非常感谢。提前谢谢你。

【问题讨论】:

  • 这个问题太宽泛了。能否提供具体的代码示例?

标签: aws-lambda chatbot aws-lex


【解决方案1】:

要跨多个意图存储值,请使用SessionAttributes

在 SessionAttributes 中备份槽值是很常见的,这样你就可以在其他意图中使用它们,或者能够返回到原始意图并恢复槽以从用户离开的地方继续。

意图 A 中的示例:

//get the values of the slots, use your slot names at the end
var first_name = event.currentIntent.slots.first_name;
var last_name = event.currentIntent.slots.last_name;
var organization = event.currentIntent.slots.organization;

//insert slot values into sessionAttributes
event.sessionAttributes = {
    "first_name": first_name,
    "last_name": last_name,
    "organization": organization,
};

当您使用更新的 sessionAttributes 响应 lex 时,这些值将被保存并在其他意图中可用。

现在在意图 B:

var first_name = event.sessionAttributes.first_name; 

var response_message = "Hello, "+ first_name +". I can help you to ...";

【讨论】:

  • @Tayyab 你应该问一个新问题,解释你尝试了什么,你可以链接到这个答案,然后解释并显示你尝试过的代码,你得到的结果,以及任何错误.然后我或其他人可以在那里为您提供帮助。
  • 你能回答这个问题吗stackoverflow.com/questions/64718778/…
【解决方案2】:

在 Amazon lex 中捕获的用户输入是使用 SLOTS 处理的。当您的 AWS Lambda 代码处理请求时,您可以将此捕获的数据存储在您希望使用的任何 Intent 中。

【讨论】:

  • 我们该怎么做呢?你能详细说明一下吗?
【解决方案3】:

(一种方式)这可以使用上下文来完成,在意图询问名称时初始化输出上下文“first_name”,并将所有其他意图输入上下文作为“first_name”。因此,当“first_name”被填充时,它会变得活跃,并且所有其他意图都可以识别。

【讨论】:

    猜你喜欢
    • 2018-08-02
    • 2018-06-17
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多