amazon-web-services - Lambda 函数将 Lex 引导至新意图

标签 amazon-web-services amazon-lex

我正在尝试使用 lambda 函数根据传入插槽的值将 lex 发送到新意图:

像这样

 public override LexResponse Process(LexEvent lexEvent, ILambdaContext context)
    {
        var slots = lexEvent.CurrentIntent.Slots;
        var sessionAttributes = lexEvent.SessionAttributes ?? new Dictionary<string, string>();
        DesiredVehicleYesNo type;
        if (slots.ContainsKey("DesiredVehicleYesNo"))
        {
            Enum.TryParse(slots["DesiredVehicleYesNo"], out type);
        }
        else
        {
            type = DesiredVehicleYesNo.Null;
        }

        switch (type)
        {
            case DesiredVehicleYesNo.YES:
                Dictionary<string, string> s = new Dictionary<string, string>();
                s.Add("DesiredVehicle", null);
                //return ConfirmIntent(sessionAttributes, "DesiredVehicleYes", s, new LexResponse.LexMessage() { Content = "That's great! Let's get started.", ContentType = MESSAGE_CONTENT_TYPE });
                //return ElicitSlot(sessionAttributes,"DesiredVehicleYes",null,"DesiredVehicle", new LexResponse.LexMessage() { Content = "That's great! Let's get started.", ContentType = MESSAGE_CONTENT_TYPE });

            case DesiredVehicleYesNo.NO:
                return ConfirmIntent(sessionAttributes, "DesiredVehicleNo", new Dictionary<string,string>(), new LexResponse.LexMessage() { Content = "Well, that's ok, I can help you choose", ContentType = MESSAGE_CONTENT_TYPE });

        }

我只是不确定我应该为此使用什么返回类型? ConfirmIntent、ElicitSlot、ElicitIntent?此外,我确实需要将插槽传回,我希望新意图使用它自己的提示来填充与该意图相关的插槽。

谢谢

最佳答案

您应该使用 ConfirmIntent并供应 intentNameslots您要切换到的意图。

Lex Response Format Docs

ConfirmIntent — Informs Amazon Lex that the user is expected to give a yes or no answer to confirm or deny the current intent.
You must include the intentName and slots fields. The slots field must contain an entry for each of the slots configured for the specified intent. If the value of a slot is unknown, you must set it to null. You must include the message field if the intent's confirmationPrompt field is null. If you specify both the message field and the confirmationPrompt field, the response includes the contents of the confirmationPrompt field. The responseCard field is optional.



因此,您可以提供自己的信息,但请确保将其写为是/否问题。因为 ConfirmIntent将期待用户的 Yes/No 响应。

此方法将始终触发您在 intentName 中提供的意图.所以你必须在那里处理用户的响应。
如果用户说"is",那么 confirmationStatus将持有值 Confirmed .
如果用户说“不”,那么 confirmationStatus将持有值 Denied .

确保您传回的插槽对于该新意图是正确的。你可以通过它们预先填充来使用用户已经给你的东西;或设置为 null允许新意图要求用户再次填充这些插槽。

关于amazon-web-services - Lambda 函数将 Lex 引导至新意图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52073753/

相关文章:

amazon-web-services - 如何在 heroku 上正确配置 Rails 5、paperclip 5、aws-sdk 2?

java - AWS Elastic BeansTalk Nginx 超时 504 错误网关 - Java Servlet AsyncContext

Amazon S3 上的 SSL 为 "static website"

amazon-lex - 如何通过 .NET SDK 构建 aws lex bot

java - 无法构造 IntentResponse 实例,已验证的对象为 null

amazon-web-services - 尽管输入了准确的话语,AWS Lex 仍匹配错误的意图

python - 从 cyptography.hazmat.bindings._constant_time 导入库导入错误

amazon-web-services - 为什么我无法远程登录我的 aws 实例?

python - 我是否正确地从默认代码迁移到测试代码?

ibm-watson - IBM Watson 与 Amazon Lex(聊天机器人)