aws-lex-web-ui
aws-lex-web-ui copied to clipboard
Custom payload for checkbox form for user
Hey there
I am trying to send the user a form with checkboxes to enable the user to select a max of two values. In this instance I am trying to calculate from the user what their 2 most common transport modes are. Could you please advise how I could do this?
current code
if (slots.TransportMode === null) {
console.log('transport mode slot');
let slotToElicit = 'TransportMode';
let message = {
contentType: "CustomPayload",
content: "<div class='transport-mode'><p><strong>What are the 2 most common transport modes that you use?</strong></p><input class='single-checkbox' type='checkbox' name='Motorbike' value='Motorbike'>Motorbike<br><input class='single-checkbox' type='checkbox' name='Car' value='Car'>Car<br><input class='single-checkbox' type='checkbox' name='Bus' value='Bus'>Bus<br><input class='single-checkbox' type='checkbox' name='Train' value='Train'>Train<br></div>"
};
callback(lexResponses.ElicitSlot(intentRequest.sessionAttributes, intentRequest.currentIntent.name, slots, slotToElicit, message));
return;
}
elicit slot function
module.exports.ElicitSlot = function(sessionAttributes, intentName, slots, slotToElicit, message) {
return {
sessionAttributes,
dialogAction: {
type: 'ElicitSlot',
intentName,
slots,
slotToElicit,
message,
},
};
}
I can't say that I've seen any chat widgets using checkboxes.
Perhaps change the solution around a bit to fit into how Lex works. My suggestion would be to have two slots - e.g.: TransportModeOne and TransportModeTwo - and each of these slots would hold a value, being the users favourite transport mode.
You'd need to have some logic in a lambda to ensure that the user's chosen value for TransportModeOne is not repeated in the list of options when illicting a response for TransportModeTwo.
This should work and would be cleaner by my estimations.