首页 > 解决方案 > 将 Lex 引导至新意图的 Lambda 函数

问题描述

我正在尝试使用 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?此外,我确实需要将插槽传回,我希望新意图使用它自己的提示来填充与该意图相关的插槽。

谢谢

标签: amazon-web-servicesamazon-lex

解决方案


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

Lex 响应格式文档

ConfirmIntent — 通知 Amazon Lex,用户应该给出是或否的答案来确认或拒绝当前的意图。
您必须包含 intentName 和 slot 字段。slot 字段必须包含为指定意图配置的每个插槽的条目。如果插槽的值未知,则必须将其设置为 null。如果意图的确认提示字段为空,则必须包含消息字段。如果您同时指定消息字段和确认提示字段,则响应将包含确认提示字段的内容。responseCard 字段是可选的。

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

这种方法将始终触发您在intentName. 因此,您必须在那里处理用户的响应。
如果用户说“是”,那么confirmationStatus将保留该值Confirmed
如果用户说“不”,confirmationStatus则将保留该值Denied

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


推荐阅读