provide slot value for specific slot in response and resume the conversation

喜夏-厌秋 提交于 2020-11-30 00:01:57

问题


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.

i have following slots in lex.

  1. Departure_city
  2. Arrival_city
  3. Departing (oneway or roundtrip)
  4. ReturnDate
  5. Date (DepartureDate)
  6. Flight Schedule

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 },
  };
}

error:

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/64718778/provide-slot-value-for-specific-slot-in-response-and-resume-the-conversation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!