I'm building the AWS Lex chat bot right now and faced some issue on the lambda function settings. According to the sample code, it used this lambda function at the end of the conversation. That's why the code was like : function close(.....)
'use strict';
// Close dialog with the customer, reporting fulfillmentState of Failed
or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
However what I would like to do is using the DialogCodeHook instead of this FulfillmentCodeHook.
The simplest logic inside Lex is asking question 1-->get answer 1-->asking question 2-->get answer 2-->asking question 2-->get answer 3; What i wanna do is Ask Question 1- Response Value allowed are 1.1, 1.2 If Response Value= Value 1.1 Ask Question 2 If Response Value= Value 1.2 Ask Question 3 Ask Question 4- Value 4.1, Value 4.2 .. so on
On AWS discussion forum, an answer is like: Yes, you can use Lambda to implement the decision tree. Lambda allows you to set a specific message and elicit a slot using 'dialogAction'.
For this specific conversation flow
if (response_value = 1.1) {
// set dialogAction.message = "Question 2"
...
// set type = ElicitSlot
...
// slotToElicit = answer2"
}
Similarly you would define conditions to ask Question 3, 4 etc.
But I am not sure where should I put this If..... at and how to use this ElicitSlot function.
Full version of the sample code for the close function is:
'use strict';
// Close dialog with the customer, reporting fulfillmentState of Failed or Fulfilled ("Thanks, your pizza will arrive in 20 minutes")
function close(sessionAttributes, fulfillmentState, message) {
return {
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
},
};
}
// --------------- Events -----------------------
function dispatch(intentRequest, callback) {
console.log('request received for userId=${intentRequest.userId}, intentName=${intentRequest.currentIntent.intentName}');
const sessionAttributes = intentRequest.sessionAttributes;
const slots = intentRequest.currentIntent.slots;
const crust = slots.crust;
const size = slots.size;
const pizzaKind = slots.pizzaKind;
callback(close(sessionAttributes, 'Fulfilled',
{'contentType': 'PlainText', 'content': `Okay, I have ordered your ${size} ${pizzaKind} pizza on ${crust} crust`}));
}
// --------------- Main handler -----------------------
// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
try {
dispatch(event,
(response) => {
callback(null, response);
});
} catch (err) {
callback(err);
}
};
Hope someone can help! Thank you so much!!!!!!!!!!!!!!!!!!!!!