amazon-web-services - 将 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?此外,我确实需要将插槽传回,我希望新意图使用它自己的提示来填充与该意图相关的插槽。
谢谢
解决方案
您应该使用ConfirmIntent
并提供要切换到的意图的intentName
and 。slots
ConfirmIntent — 通知 Amazon Lex,用户应该给出是或否的答案来确认或拒绝当前的意图。
您必须包含 intentName 和 slot 字段。slot 字段必须包含为指定意图配置的每个插槽的条目。如果插槽的值未知,则必须将其设置为 null。如果意图的确认提示字段为空,则必须包含消息字段。如果您同时指定消息字段和确认提示字段,则响应将包含确认提示字段的内容。responseCard 字段是可选的。
因此,您可以提供自己的信息,但请确保将其写为是/否问题。因为ConfirmIntent
会期待用户的是/否响应。
这种方法将始终触发您在intentName
. 因此,您必须在那里处理用户的响应。
如果用户说“是”,那么confirmationStatus
将保留该值Confirmed
。
如果用户说“不”,confirmationStatus
则将保留该值Denied
。
确保您传回的插槽对于该新意图是正确的。您可以将它们预先填充以使用用户已经给您的内容;或设置为null
允许新意图要求用户再次填充这些插槽。
推荐阅读
- node.js - 无法使用 mongoose 连接到 mongoDB 客户端
- node.js - Nodejs 服务器 (AWS) 中的 ERR_HTTP_HEADERS_SENT
- ruby-on-rails - 在活动邮件 smtp 设置中使用 `:plain` 与 `:login` 有什么区别?
- javascript - 如何使用 Button 将函数从一个组件调用到另一个组件
- android - Firebase Uploader AsyncTask doinBackground()错误android
- python - Django模板中的字符串到整数
- angular - 无法解析 AuthService 中的所有参数
- asp.net - 在不同的 Web 应用程序中面临 clr.dll 崩溃
- google-chrome - 从所有浏览器到 Android 上的 google chrome 的深层链接
- javascript - 使用jquery单击加号时如何展开最近的div?