提供特定插槽的插槽值作为响应并恢复对话 [英] provide slot value for specific slot in response and resume the conversation

查看:116
本文介绍了提供特定插槽的插槽值作为响应并恢复对话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究lex,想在响应中提供slot值,仅在用户是否在前一个slot值中输入了特定的输入时才会询问.我正在尝试某些东西,但是我做对或做不对.

I am working on lex and want to give slot value in the response which will only be asked if the user enters specific input in the previous slot value. I am trying something but I don't I am doing right or not.

我在lex中有以下插槽.

i have following slots in lex.

  1. 出发城市
  2. 到达城市
  3. 出发(单程或往返)
  4. ReturnDate
  5. 日期(DepartureDate)
  6. 航班时刻表

例如如果用户选择往返,则要求返回日期,否则跳过该时段并通过询问剩余时段的值来继续进行操作

e.g. if user select Roundtrip then ask for the return date otherwise skip that slot and continue the flow by asking value of the remaining of slots

这是我为实现这种情况而要做的代码.

here is the piece of code that I am doing to fulfill this scenario.

"use strict";

const lexResponses = require("./lexResponse");

const depart = ["one-way", "oneway"];

const buildValidationResult = (isValid, violatedSlot, messageContent) => {
  if (messageContent == null) {
    return {
      isValid: isValid,
      violatedSlot: violatedSlot,
    };
  }
  return {
    isValid: isValid,
    violatedSlot: violatedSlot,
    message: { contentType: "PlainText", content: messageContent },
  };
};

function validateBookaflight(
  Departing,
  ReturnDate
) {
  if (Departing && depart.indexOf(Departing.toLowerCase()) === -1) {
   
     return {
          dialogAction: {
            type: "ElicitSlot",
            intentName: "Bookaflight",
            slots: {
              Departure_city: Departure_city,
              Arrival_city: Arrival_city,
              Departing: Departing,
              ReturnDate: ReturnDate,
            },
            slotToElicit: "ReturnDate",
            message: {
              contentType: "PlainText",
              content: "Please enter return date,(yyyy-mm-dd)",
            },
          },
        }
    };
     return buildValidationResult(true, null, null);
}

function buildFulfilmentResult(fullfilmentState, messageContent) {
  return {
    fullfilmentState,
    message: { contentType: "PlainText", content: messageContent },
  };
}

错误:

An error has occurred: Invalid Lambda 
Response: Received invalid response from 
Lambda: Can not construct instance of 
ElicitSlotDialogAction, problem: 
slotToElicit must not be blank in ElicitSlot 
dialog action at 
[Source: {"sessionAttributes":{},"dialogAction":{"type":"ElicitSlot","intentName":"Bookaflight",
"slots":{"ReturnDate":null,"Departure_city":"london","Flight_schedule":null,"Arrival_city":"lahore","Date":null,
"Departing":"roundtrip",
"undefined":null}}}; line: 1, column: 241]

请告诉我我在做错什么,或者您在理解我的要求时是否有任何问题.

please tell what i am doing wrong or if you have any issue understanding my requirement.

推荐答案

您看到的问题似乎是由于 slotToElicit 参数由于某种原因未返回给Lex引起的.要确认Lambda返回Lex的内容,请尝试使用Lex bot传递的相同输入来运行该函数的测试调用.

The issue you're seeing seems to be caused due to the slotToElicit parameter not being returned to Lex for some reason. To confirm what the Lambda returns to Lex, try running a test invoke of the function using the same input that's passed by the Lex bot.

此外,在Lambda响应中返回插槽的值时,如果不返回其他插槽的值,则Lex会将它们视为null.因此,请确保返回的所有插槽值都不为 null ,并且包含用户输入的值.

Additionally, when returning the values of the slots in the Lambda response, if you do not return the values for the other slots, Lex treats them as null. Thus ensure that all slot values that are returned are not null and contain the values entered by the user.

这篇关于提供特定插槽的插槽值作为响应并恢复对话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆