问题
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.
- Departure_city
- Arrival_city
- Departing (oneway or roundtrip)
- ReturnDate
- Date (DepartureDate)
- 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