0
votes

I am using Amazon lex with AWS lambda as a validation Codehook. When I was trying to pass a value with a response card dynamically generated, it is showing null value in the AppointmentTime Slot but the original value is showing value in slotDetails. Here is the request sent through lex:

{
"messageVersion": "1.0",
"invocationSource": "DialogCodeHook",
"userId": "prwna44b91sbr4w7d2pwwva59anaqzqx",
"sessionAttributes": {
    "store_id": "26",
    "address": "Quark Atrium, A‐45, Phase VIII Extension,Industrial Focal Point,Sahibzada Ajit Singh Nagar, Punjab 160071,India",
    "closingTime": "19:00:00",
    "city": "Mohali",
    "phone": "9718409751",
    "bookingDateTime": "2018-05-27T21:25:46+05:30",
    "openingTime": "10:00:00",
    "state": "PB",
    "email": "[email protected]",
    "zip_code": "44545"
},
"requestAttributes": null,
"bot": {
    "name": "ScheduleRide",
    "alias": "$LATEST",
    "version": "$LATEST"
},
"outputDialogMode": "Text",
"currentIntent": {
    "name": "BookAppointment",
    "slots": {
        "CustomerAgreement": null,
        "DropLocationPrompt": "yes",
        "PickupAddress": "Unnamed Road, Industrial Area, Sector 74, Sahibzada Ajit Singh Nagar, Punjab 140308, India",
        "RequiredService": null,
        "AppointmentTime": null,
        "DropAddress": null,
        "PhoneNumber": null,
        "AppointmentDate": "2018-05-28"
    },
    "slotDetails": {
        "CustomerAgreement": {
            "resolutions": [],
            "originalValue": null
        },
        "DropLocationPrompt": {
            "resolutions": [
                {
                    "value": "yes"
                }
            ],
            "originalValue": "yes"
        },
        "PickupAddress": {
            "resolutions": [],
            "originalValue": "Unnamed Road, Industrial Area, Sector 74, Sahibzada Ajit Singh Nagar, Punjab 140308, India"
        },
        "RequiredService": {
            "resolutions": [],
            "originalValue": null
        },
        "AppointmentTime": {
            "resolutions": [
                {
                    "value": "00:00"
                },
                {
                    "value": "12:00"
                }
            ],
            "originalValue": "14:00:00"
        },
        "DropAddress": {
            "resolutions": [],
            "originalValue": null
        },
        "PhoneNumber": {
            "resolutions": [],
            "originalValue": null
        },
        "AppointmentDate": {
            "resolutions": [],
            "originalValue": "28 may"
        }
    },
    "confirmationStatus": "None"
},
"inputTranscript": "14:00:00"

} Here is the request passed to the lex, see the AppointmentTime in the slots object, it is showing null and in the slotDetails object, it is showing value. Here is the array of buttons which i pass from the response card object:

 [ { text: '1:00 PM', value: '13:00:00' },
   { text: '1:30 PM', value: '13:30:00' },
   { text: '2:00 PM', value: '14:00:00' },
   { text: '2:30 PM', value: '14:30:00' },
   { text: '3:00 PM', value: '15:00:00' },
   { text: '3:30 PM', value: '15:30:00' },
   { text: '4:00 PM', value: '16:00:00' },
   { text: '4:30 PM', value: '16:30:00' },
   { text: '5:00 PM', value: '17:00:00' },
   { text: '5:30 PM', value: '17:30:00' },
   { text: '6:00 PM', value: '18:00:00' },
   { text: '6:30 PM', value: '18:30:00' } ]

Here is the function of buildResponseCard:

  function buildResponseCard(title, subTitle, options){
let buttons = null;
console.log(options);
let genericAttachments = [];
if (options != null){
    buttons = [];
    for(let i = 0; i < (options.length); i++){
        buttons.push(options[i]);
        if(i%3 === 2){
            genericAttachments.push({
             title,
             subTitle,
             buttons
            });
            buttons = [];
        }
    }
}
return {
    version: 1,
    contentType: "application/vnd.amazonaws.card.generic",
    genericAttachments
};
}

The reason I want AppointmentTime slot value on slot object to be shown on is that whenever the value in the slot is invalid through validation, I will set it to null and will callback it through lambda function and i will not be able to callback the slotDetails object in the response. Can anyone tell me how can i achieve this?

1

1 Answers

0
votes

For the AMAZON.TIME built-in slot:

When a user enters an ambiguous time, Amazon Lex uses the slotDetails attribute of a Lambda event to pass resolutions for the ambiguous times to your Lambda function. ... In this case, the value in the slots map is null, and the slotDetails entity contains the two possible resolutions of the time.

Your input of "14:00:00" is not understood as an unambiguous time, and Lex tries to resolve it to either noon or midnight, which is obviously wrong. This is probably because the Lex Time slot is expecting only hours and minutes (hh:mm) but not seconds (hh:mm:ss).

So if it is possible for you, one solution is to remove the seconds digits from your time values. For example:

[ { text: '1:00 PM', value: '13:00' }, ... ]

However, if you must have the seconds in the time value, then you can simply find the time the user selected from the inputTranscript value and do your validation of it from there.

var userInput = event.inputTranscript;

EDIT:

Another option is to ignore Lex's suggested resolutions and get the slot-details original-value. Like this:

var timeValue = event.currentIntent.slotDetails.AppointmentTime.originalValue;

And then set the AppointmentTime slot yourself. Like this:

event.currentIntent.slots.AppointmentTime = timeValue;