简体   繁体   中英

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

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

eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM