Empty all slot values in intent
I have an Alexa Skill, where I have multiple intents. These intents are called using custom slot values that mostly take yes/ no answers. The thing is, the succeeding yes/ no slot values keep referring to the last intent and hence it never goes past the first intent. Is there a way in which the slot values can be reset?
Any help would be much appreciated.
{
"interactionModel": {
"languageModel": {
"invocationName": "tata nexon test drive",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples":
},
{
"name": "TATANexonmodelvariantfeatureIntent",
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"samples": [
"i'd like to know about the {modelTATANexon} model",
"{modelTATANexon}"
]
},
{
"name": "variantTATANexon",
"type": "varianttype",
"samples": [
"i'd like to know about the {variantTATANexon} variant",
"{variantTATANexon}"
]
}
],
"samples": [
"TATA Nexon Test Drive",
"start test drive",
"start TATA Nexon Test Drive",
"launch test drive",
"launch TATA Nexon Test Drive",
"load test drive",
"load TATA Nexon Test Drive",
"begin test drive",
"begin TATA Nexon Test Drive",
"enable test drive",
"enable TATA Nexon Test Drive"
]
},
{
"name": "TATANexonmodefeatureIntent",
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype"
}
],
"samples": [
"i am interested",
"sure",
"nah",
"yeah",
"I am not interested",
"nope",
"yup",
"no",
"yes"
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype"
}
],
"samples": [
"sure",
"nah",
"yeah",
"nope",
"yup",
"i am not interested",
"i am interested",
"no",
"yes"
]
}
],
"types": [
{
"name": "modeltype",
"values": [
{
"name": {
"value": "xza plus"
}
},
{
"name": {
"value": "xz plus"
}
}
]
},
{
"name": "varianttype",
"values": [
{
"name": {
"value": "diesel"
}
},
{
"name": {
"value": "petrol"
}
}
]
},
{
"name": "yesnomodeslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
},
{
"name": "yesnoinfotainmentslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "TATANexonmodelvariantfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon"
}
},
{
"name": "variantTATANexon",
"type": "varianttype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon"
}
}
]
},
{
"name": "TATANexonmodefeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot"
}
}
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon",
"variations": [
{
"type": "PlainText",
"value": " The model that you are currently driving, is it a XZ Plus or a XZA Plus?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon",
"variations": [
{
"type": "PlainText",
"value": "which variant do you seek information on, petrol or diesel?"
},
{
"type": "PlainText",
"value": "which variant are you interested in, petrol or diesel?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot",
"variations": [
{
"type": "PlainText",
"value": "Are you interested in the different modes offered by TATA Nexon?"
}
]
},
{
"id": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot",
"variations": [
{
"type": "PlainText",
"value": "Are you excited to know about TATA Nexon's feature rich infotainment system?"
}
]
}
]
}
}
const Alexa = require('ask-sdk-core');
// 1. Text strings ================================================================================
// Modify these strings and messages to change the behavior of your Lambda function
const welcomeOutput = "Hello! Starting a Test Drive? No worries, for I am here to help. Currently you are taking a Test Drive in a TATA Nexon. The Nexon range by TATA Motors is a stylish looking and powerful sub-compact SUV, which is feature loaded, following the IMPACT design philosophy, making ride and handling quite sorted.";
const welcomeReprompt = "Would you be interested to know about TATA Nexon Test Drive?";
const helpOutput = 'You can demonstrate the delegate directive by saying "TATA Nexon Test Drive".';
const helpReprompt = 'Try saying "TATA Nexon Test Drive".';
//CONSTANTS
const slotsToOptions2Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptions1Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptionsMap = {
'xz plus-petrol': 0,
'xz plus-diesel': 1,
'xza plus-petrol': 2,
'xza plus-diesel': 3,
};
const facts2 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
];
const facts1 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
];
const facts = [
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
];
// 1. Intent Handlers =============================================
const LaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(welcomeOutput)
.reprompt(welcomeReprompt)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodelvariantfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodelvariantfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodelvariantfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
//LOOK UP KEY-MAP RESOLUTION
const key = `${slotValues.modelTATANexon.resolved}-${slotValues.variantTATANexon.resolved}`;
const information = facts[slotsToOptionsMap[key]];
// compose speechOutput that simply reads all the collected slot values
//let speechOutput = "";
//NEW RESPONSE
const speechOutput = ` So you're interested in the ${slotValues.modelTATANexon.synonym} model, ${slotValues.variantTATANexon.synonym} variant . Good to know !` + ` ${information.model} ${information.variant} ` + ` Would you like to know about the different modes available ? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexoninfotainmentfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexoninfotainmentfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexoninfotainmentfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key2 = `${slotValues.yesnoinfotainmentslot.resolved}`;
const information2 = facts2[slotsToOptions2Map[key2]];
//NEW RESPONSE
const speechOutput = ` ${information2.text} `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnoinfotainmentslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodefeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodefeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodefeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key1 = `${slotValues.yesnomodeslot.resolved}`;
const information1 = facts1[slotsToOptions1Map[key1]];
//NEW RESPONSE
const speechOutput = ` ${information1.text} `;
//` Would you be interested in the level nex technology infotainment system? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnomodeslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(helpOutput)
.reprompt(helpReprompt)
.getResponse();
},
};
const CancelStopHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
(request.intent.name === 'AMAZON.CancelIntent' || request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
const speechOutput = 'Okay, talk to you later! ';
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(true)
.getResponse();
},
};
const SessionEndedHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
const request = handlerInput.requestEnvelope.request;
console.log(`Original Request was: ${JSON.stringify(request, null, 2)}`);
console.log(`Error handled: ${error}`);
return handlerInput.responseBuilder
.speak('Sorry, I can not understand the command. Please say again.')
.reprompt('Sorry, I can not understand the command. Please say again.')
.getResponse();
},
};
// 2. Helper Functions ============================================================================
function getSlotValues(filledSlots) {
const slotValues = {};
console.log(`The filled slots: ${JSON.stringify(filledSlots)}`);
Object.keys(filledSlots).forEach((item) => {
const name = filledSlots[item].name;
if (filledSlots[item] &&
filledSlots[item].resolutions &&
filledSlots[item].resolutions.resolutionsPerAuthority[0] &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
switch (filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
case 'ER_SUCCESS_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].resolutions.resolutionsPerAuthority[0].values[0].value.name,
isValidated: true,
};
break;
case 'ER_SUCCESS_NO_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
break;
default:
break;
}
} else {
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
}
}, this);
return slotValues;
}
/*function getRandomPhrase(array) {
// the argument is an array of words or phrases
const i = Math.floor(Math.random() * array.length);
return (array[i]);
}*/
// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressTATANexonmodelvariantfeatureHandler,
CompletedTATANexonmodelvariantfeatureHandler,
InProgressTATANexonmodefeatureHandler,
CompletedTATANexonmodefeatureHandler,
InProgressTATANexoninfotainmentfeatureHandler,
CompletedTATANexoninfotainmentfeatureHandler,
CancelStopHandler,
HelpHandler,
SessionEndedHandler,
)
.addErrorHandlers(ErrorHandler)
.lambda();
lambda alexa alexa-slot
add a comment |
I have an Alexa Skill, where I have multiple intents. These intents are called using custom slot values that mostly take yes/ no answers. The thing is, the succeeding yes/ no slot values keep referring to the last intent and hence it never goes past the first intent. Is there a way in which the slot values can be reset?
Any help would be much appreciated.
{
"interactionModel": {
"languageModel": {
"invocationName": "tata nexon test drive",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples":
},
{
"name": "TATANexonmodelvariantfeatureIntent",
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"samples": [
"i'd like to know about the {modelTATANexon} model",
"{modelTATANexon}"
]
},
{
"name": "variantTATANexon",
"type": "varianttype",
"samples": [
"i'd like to know about the {variantTATANexon} variant",
"{variantTATANexon}"
]
}
],
"samples": [
"TATA Nexon Test Drive",
"start test drive",
"start TATA Nexon Test Drive",
"launch test drive",
"launch TATA Nexon Test Drive",
"load test drive",
"load TATA Nexon Test Drive",
"begin test drive",
"begin TATA Nexon Test Drive",
"enable test drive",
"enable TATA Nexon Test Drive"
]
},
{
"name": "TATANexonmodefeatureIntent",
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype"
}
],
"samples": [
"i am interested",
"sure",
"nah",
"yeah",
"I am not interested",
"nope",
"yup",
"no",
"yes"
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype"
}
],
"samples": [
"sure",
"nah",
"yeah",
"nope",
"yup",
"i am not interested",
"i am interested",
"no",
"yes"
]
}
],
"types": [
{
"name": "modeltype",
"values": [
{
"name": {
"value": "xza plus"
}
},
{
"name": {
"value": "xz plus"
}
}
]
},
{
"name": "varianttype",
"values": [
{
"name": {
"value": "diesel"
}
},
{
"name": {
"value": "petrol"
}
}
]
},
{
"name": "yesnomodeslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
},
{
"name": "yesnoinfotainmentslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "TATANexonmodelvariantfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon"
}
},
{
"name": "variantTATANexon",
"type": "varianttype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon"
}
}
]
},
{
"name": "TATANexonmodefeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot"
}
}
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon",
"variations": [
{
"type": "PlainText",
"value": " The model that you are currently driving, is it a XZ Plus or a XZA Plus?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon",
"variations": [
{
"type": "PlainText",
"value": "which variant do you seek information on, petrol or diesel?"
},
{
"type": "PlainText",
"value": "which variant are you interested in, petrol or diesel?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot",
"variations": [
{
"type": "PlainText",
"value": "Are you interested in the different modes offered by TATA Nexon?"
}
]
},
{
"id": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot",
"variations": [
{
"type": "PlainText",
"value": "Are you excited to know about TATA Nexon's feature rich infotainment system?"
}
]
}
]
}
}
const Alexa = require('ask-sdk-core');
// 1. Text strings ================================================================================
// Modify these strings and messages to change the behavior of your Lambda function
const welcomeOutput = "Hello! Starting a Test Drive? No worries, for I am here to help. Currently you are taking a Test Drive in a TATA Nexon. The Nexon range by TATA Motors is a stylish looking and powerful sub-compact SUV, which is feature loaded, following the IMPACT design philosophy, making ride and handling quite sorted.";
const welcomeReprompt = "Would you be interested to know about TATA Nexon Test Drive?";
const helpOutput = 'You can demonstrate the delegate directive by saying "TATA Nexon Test Drive".';
const helpReprompt = 'Try saying "TATA Nexon Test Drive".';
//CONSTANTS
const slotsToOptions2Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptions1Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptionsMap = {
'xz plus-petrol': 0,
'xz plus-diesel': 1,
'xza plus-petrol': 2,
'xza plus-diesel': 3,
};
const facts2 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
];
const facts1 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
];
const facts = [
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
];
// 1. Intent Handlers =============================================
const LaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(welcomeOutput)
.reprompt(welcomeReprompt)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodelvariantfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodelvariantfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodelvariantfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
//LOOK UP KEY-MAP RESOLUTION
const key = `${slotValues.modelTATANexon.resolved}-${slotValues.variantTATANexon.resolved}`;
const information = facts[slotsToOptionsMap[key]];
// compose speechOutput that simply reads all the collected slot values
//let speechOutput = "";
//NEW RESPONSE
const speechOutput = ` So you're interested in the ${slotValues.modelTATANexon.synonym} model, ${slotValues.variantTATANexon.synonym} variant . Good to know !` + ` ${information.model} ${information.variant} ` + ` Would you like to know about the different modes available ? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexoninfotainmentfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexoninfotainmentfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexoninfotainmentfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key2 = `${slotValues.yesnoinfotainmentslot.resolved}`;
const information2 = facts2[slotsToOptions2Map[key2]];
//NEW RESPONSE
const speechOutput = ` ${information2.text} `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnoinfotainmentslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodefeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodefeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodefeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key1 = `${slotValues.yesnomodeslot.resolved}`;
const information1 = facts1[slotsToOptions1Map[key1]];
//NEW RESPONSE
const speechOutput = ` ${information1.text} `;
//` Would you be interested in the level nex technology infotainment system? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnomodeslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(helpOutput)
.reprompt(helpReprompt)
.getResponse();
},
};
const CancelStopHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
(request.intent.name === 'AMAZON.CancelIntent' || request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
const speechOutput = 'Okay, talk to you later! ';
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(true)
.getResponse();
},
};
const SessionEndedHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
const request = handlerInput.requestEnvelope.request;
console.log(`Original Request was: ${JSON.stringify(request, null, 2)}`);
console.log(`Error handled: ${error}`);
return handlerInput.responseBuilder
.speak('Sorry, I can not understand the command. Please say again.')
.reprompt('Sorry, I can not understand the command. Please say again.')
.getResponse();
},
};
// 2. Helper Functions ============================================================================
function getSlotValues(filledSlots) {
const slotValues = {};
console.log(`The filled slots: ${JSON.stringify(filledSlots)}`);
Object.keys(filledSlots).forEach((item) => {
const name = filledSlots[item].name;
if (filledSlots[item] &&
filledSlots[item].resolutions &&
filledSlots[item].resolutions.resolutionsPerAuthority[0] &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
switch (filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
case 'ER_SUCCESS_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].resolutions.resolutionsPerAuthority[0].values[0].value.name,
isValidated: true,
};
break;
case 'ER_SUCCESS_NO_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
break;
default:
break;
}
} else {
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
}
}, this);
return slotValues;
}
/*function getRandomPhrase(array) {
// the argument is an array of words or phrases
const i = Math.floor(Math.random() * array.length);
return (array[i]);
}*/
// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressTATANexonmodelvariantfeatureHandler,
CompletedTATANexonmodelvariantfeatureHandler,
InProgressTATANexonmodefeatureHandler,
CompletedTATANexonmodefeatureHandler,
InProgressTATANexoninfotainmentfeatureHandler,
CompletedTATANexoninfotainmentfeatureHandler,
CancelStopHandler,
HelpHandler,
SessionEndedHandler,
)
.addErrorHandlers(ErrorHandler)
.lambda();
lambda alexa alexa-slot
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13
add a comment |
I have an Alexa Skill, where I have multiple intents. These intents are called using custom slot values that mostly take yes/ no answers. The thing is, the succeeding yes/ no slot values keep referring to the last intent and hence it never goes past the first intent. Is there a way in which the slot values can be reset?
Any help would be much appreciated.
{
"interactionModel": {
"languageModel": {
"invocationName": "tata nexon test drive",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples":
},
{
"name": "TATANexonmodelvariantfeatureIntent",
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"samples": [
"i'd like to know about the {modelTATANexon} model",
"{modelTATANexon}"
]
},
{
"name": "variantTATANexon",
"type": "varianttype",
"samples": [
"i'd like to know about the {variantTATANexon} variant",
"{variantTATANexon}"
]
}
],
"samples": [
"TATA Nexon Test Drive",
"start test drive",
"start TATA Nexon Test Drive",
"launch test drive",
"launch TATA Nexon Test Drive",
"load test drive",
"load TATA Nexon Test Drive",
"begin test drive",
"begin TATA Nexon Test Drive",
"enable test drive",
"enable TATA Nexon Test Drive"
]
},
{
"name": "TATANexonmodefeatureIntent",
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype"
}
],
"samples": [
"i am interested",
"sure",
"nah",
"yeah",
"I am not interested",
"nope",
"yup",
"no",
"yes"
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype"
}
],
"samples": [
"sure",
"nah",
"yeah",
"nope",
"yup",
"i am not interested",
"i am interested",
"no",
"yes"
]
}
],
"types": [
{
"name": "modeltype",
"values": [
{
"name": {
"value": "xza plus"
}
},
{
"name": {
"value": "xz plus"
}
}
]
},
{
"name": "varianttype",
"values": [
{
"name": {
"value": "diesel"
}
},
{
"name": {
"value": "petrol"
}
}
]
},
{
"name": "yesnomodeslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
},
{
"name": "yesnoinfotainmentslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "TATANexonmodelvariantfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon"
}
},
{
"name": "variantTATANexon",
"type": "varianttype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon"
}
}
]
},
{
"name": "TATANexonmodefeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot"
}
}
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon",
"variations": [
{
"type": "PlainText",
"value": " The model that you are currently driving, is it a XZ Plus or a XZA Plus?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon",
"variations": [
{
"type": "PlainText",
"value": "which variant do you seek information on, petrol or diesel?"
},
{
"type": "PlainText",
"value": "which variant are you interested in, petrol or diesel?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot",
"variations": [
{
"type": "PlainText",
"value": "Are you interested in the different modes offered by TATA Nexon?"
}
]
},
{
"id": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot",
"variations": [
{
"type": "PlainText",
"value": "Are you excited to know about TATA Nexon's feature rich infotainment system?"
}
]
}
]
}
}
const Alexa = require('ask-sdk-core');
// 1. Text strings ================================================================================
// Modify these strings and messages to change the behavior of your Lambda function
const welcomeOutput = "Hello! Starting a Test Drive? No worries, for I am here to help. Currently you are taking a Test Drive in a TATA Nexon. The Nexon range by TATA Motors is a stylish looking and powerful sub-compact SUV, which is feature loaded, following the IMPACT design philosophy, making ride and handling quite sorted.";
const welcomeReprompt = "Would you be interested to know about TATA Nexon Test Drive?";
const helpOutput = 'You can demonstrate the delegate directive by saying "TATA Nexon Test Drive".';
const helpReprompt = 'Try saying "TATA Nexon Test Drive".';
//CONSTANTS
const slotsToOptions2Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptions1Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptionsMap = {
'xz plus-petrol': 0,
'xz plus-diesel': 1,
'xza plus-petrol': 2,
'xza plus-diesel': 3,
};
const facts2 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
];
const facts1 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
];
const facts = [
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
];
// 1. Intent Handlers =============================================
const LaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(welcomeOutput)
.reprompt(welcomeReprompt)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodelvariantfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodelvariantfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodelvariantfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
//LOOK UP KEY-MAP RESOLUTION
const key = `${slotValues.modelTATANexon.resolved}-${slotValues.variantTATANexon.resolved}`;
const information = facts[slotsToOptionsMap[key]];
// compose speechOutput that simply reads all the collected slot values
//let speechOutput = "";
//NEW RESPONSE
const speechOutput = ` So you're interested in the ${slotValues.modelTATANexon.synonym} model, ${slotValues.variantTATANexon.synonym} variant . Good to know !` + ` ${information.model} ${information.variant} ` + ` Would you like to know about the different modes available ? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexoninfotainmentfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexoninfotainmentfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexoninfotainmentfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key2 = `${slotValues.yesnoinfotainmentslot.resolved}`;
const information2 = facts2[slotsToOptions2Map[key2]];
//NEW RESPONSE
const speechOutput = ` ${information2.text} `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnoinfotainmentslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodefeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodefeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodefeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key1 = `${slotValues.yesnomodeslot.resolved}`;
const information1 = facts1[slotsToOptions1Map[key1]];
//NEW RESPONSE
const speechOutput = ` ${information1.text} `;
//` Would you be interested in the level nex technology infotainment system? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnomodeslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(helpOutput)
.reprompt(helpReprompt)
.getResponse();
},
};
const CancelStopHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
(request.intent.name === 'AMAZON.CancelIntent' || request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
const speechOutput = 'Okay, talk to you later! ';
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(true)
.getResponse();
},
};
const SessionEndedHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
const request = handlerInput.requestEnvelope.request;
console.log(`Original Request was: ${JSON.stringify(request, null, 2)}`);
console.log(`Error handled: ${error}`);
return handlerInput.responseBuilder
.speak('Sorry, I can not understand the command. Please say again.')
.reprompt('Sorry, I can not understand the command. Please say again.')
.getResponse();
},
};
// 2. Helper Functions ============================================================================
function getSlotValues(filledSlots) {
const slotValues = {};
console.log(`The filled slots: ${JSON.stringify(filledSlots)}`);
Object.keys(filledSlots).forEach((item) => {
const name = filledSlots[item].name;
if (filledSlots[item] &&
filledSlots[item].resolutions &&
filledSlots[item].resolutions.resolutionsPerAuthority[0] &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
switch (filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
case 'ER_SUCCESS_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].resolutions.resolutionsPerAuthority[0].values[0].value.name,
isValidated: true,
};
break;
case 'ER_SUCCESS_NO_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
break;
default:
break;
}
} else {
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
}
}, this);
return slotValues;
}
/*function getRandomPhrase(array) {
// the argument is an array of words or phrases
const i = Math.floor(Math.random() * array.length);
return (array[i]);
}*/
// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressTATANexonmodelvariantfeatureHandler,
CompletedTATANexonmodelvariantfeatureHandler,
InProgressTATANexonmodefeatureHandler,
CompletedTATANexonmodefeatureHandler,
InProgressTATANexoninfotainmentfeatureHandler,
CompletedTATANexoninfotainmentfeatureHandler,
CancelStopHandler,
HelpHandler,
SessionEndedHandler,
)
.addErrorHandlers(ErrorHandler)
.lambda();
lambda alexa alexa-slot
I have an Alexa Skill, where I have multiple intents. These intents are called using custom slot values that mostly take yes/ no answers. The thing is, the succeeding yes/ no slot values keep referring to the last intent and hence it never goes past the first intent. Is there a way in which the slot values can be reset?
Any help would be much appreciated.
{
"interactionModel": {
"languageModel": {
"invocationName": "tata nexon test drive",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples":
},
{
"name": "TATANexonmodelvariantfeatureIntent",
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"samples": [
"i'd like to know about the {modelTATANexon} model",
"{modelTATANexon}"
]
},
{
"name": "variantTATANexon",
"type": "varianttype",
"samples": [
"i'd like to know about the {variantTATANexon} variant",
"{variantTATANexon}"
]
}
],
"samples": [
"TATA Nexon Test Drive",
"start test drive",
"start TATA Nexon Test Drive",
"launch test drive",
"launch TATA Nexon Test Drive",
"load test drive",
"load TATA Nexon Test Drive",
"begin test drive",
"begin TATA Nexon Test Drive",
"enable test drive",
"enable TATA Nexon Test Drive"
]
},
{
"name": "TATANexonmodefeatureIntent",
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype"
}
],
"samples": [
"i am interested",
"sure",
"nah",
"yeah",
"I am not interested",
"nope",
"yup",
"no",
"yes"
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype"
}
],
"samples": [
"sure",
"nah",
"yeah",
"nope",
"yup",
"i am not interested",
"i am interested",
"no",
"yes"
]
}
],
"types": [
{
"name": "modeltype",
"values": [
{
"name": {
"value": "xza plus"
}
},
{
"name": {
"value": "xz plus"
}
}
]
},
{
"name": "varianttype",
"values": [
{
"name": {
"value": "diesel"
}
},
{
"name": {
"value": "petrol"
}
}
]
},
{
"name": "yesnomodeslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
},
{
"name": "yesnoinfotainmentslottype",
"values": [
{
"name": {
"value": "no, i am not interested"
}
},
{
"name": {
"value": "i am not interested"
}
},
{
"name": {
"value": "i am not"
}
},
{
"name": {
"value": "no"
}
},
{
"name": {
"value": "yes, i am interested"
}
},
{
"name": {
"value": "i am interested"
}
},
{
"name": {
"value": "i am"
}
},
{
"name": {
"value": "yes"
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "TATANexonmodelvariantfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "modelTATANexon",
"type": "modeltype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon"
}
},
{
"name": "variantTATANexon",
"type": "varianttype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon"
}
}
]
},
{
"name": "TATANexonmodefeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnomodeslot",
"type": "yesnomodeslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot"
}
}
]
},
{
"name": "TATANexoninfotainmentfeatureIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "yesnoinfotainmentslot",
"type": "yesnoinfotainmentslottype",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-modelTATANexon",
"variations": [
{
"type": "PlainText",
"value": " The model that you are currently driving, is it a XZ Plus or a XZA Plus?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodelvariantfeatureIntent.IntentSlot-variantTATANexon",
"variations": [
{
"type": "PlainText",
"value": "which variant do you seek information on, petrol or diesel?"
},
{
"type": "PlainText",
"value": "which variant are you interested in, petrol or diesel?"
}
]
},
{
"id": "Elicit.Intent-TATANexonmodefeatureIntent.IntentSlot-yesnomodeslot",
"variations": [
{
"type": "PlainText",
"value": "Are you interested in the different modes offered by TATA Nexon?"
}
]
},
{
"id": "Elicit.Intent-TATANexoninfotainmentfeatureIntent.IntentSlot-yesnoinfotainmentslot",
"variations": [
{
"type": "PlainText",
"value": "Are you excited to know about TATA Nexon's feature rich infotainment system?"
}
]
}
]
}
}
const Alexa = require('ask-sdk-core');
// 1. Text strings ================================================================================
// Modify these strings and messages to change the behavior of your Lambda function
const welcomeOutput = "Hello! Starting a Test Drive? No worries, for I am here to help. Currently you are taking a Test Drive in a TATA Nexon. The Nexon range by TATA Motors is a stylish looking and powerful sub-compact SUV, which is feature loaded, following the IMPACT design philosophy, making ride and handling quite sorted.";
const welcomeReprompt = "Would you be interested to know about TATA Nexon Test Drive?";
const helpOutput = 'You can demonstrate the delegate directive by saying "TATA Nexon Test Drive".';
const helpReprompt = 'Try saying "TATA Nexon Test Drive".';
//CONSTANTS
const slotsToOptions2Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptions1Map = {
'yes': 0,
'i am': 1,
'i am interested': 2,
'yes, i am interested': 3,
'no': 4,
'i am not': 5,
'i am not interested': 6,
'no, i am not interested': 7,
};
const slotsToOptionsMap = {
'xz plus-petrol': 0,
'xz plus-diesel': 1,
'xza plus-petrol': 2,
'xza plus-diesel': 3,
};
const facts2 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
{ text: ' TATA Nexon comes with a host of safety features. Would you be interested in it? '},
];
const facts1 = [
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' TEXT INFO '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
{ text: ' May I interest you in the features of the infotainment system present? '},
];
const facts = [
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
{ model: 'TEXT INFO', variant: 'TEXT INFO'},
];
// 1. Intent Handlers =============================================
const LaunchRequestHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'LaunchRequest';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(welcomeOutput)
.reprompt(welcomeReprompt)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodelvariantfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodelvariantfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodelvariantfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodelvariantfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
//LOOK UP KEY-MAP RESOLUTION
const key = `${slotValues.modelTATANexon.resolved}-${slotValues.variantTATANexon.resolved}`;
const information = facts[slotsToOptionsMap[key]];
// compose speechOutput that simply reads all the collected slot values
//let speechOutput = "";
//NEW RESPONSE
const speechOutput = ` So you're interested in the ${slotValues.modelTATANexon.synonym} model, ${slotValues.variantTATANexon.synonym} variant . Good to know !` + ` ${information.model} ${information.variant} ` + ` Would you like to know about the different modes available ? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexoninfotainmentfeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexoninfotainmentfeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexoninfotainmentfeatureIntent';
},
handle(handlerInput) {
console.log('TATANexoninfotainmentfeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key2 = `${slotValues.yesnoinfotainmentslot.resolved}`;
const information2 = facts2[slotsToOptions2Map[key2]];
//NEW RESPONSE
const speechOutput = ` ${information2.text} `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnoinfotainmentslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const InProgressTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'TATANexonmodefeatureIntent' &&
request.dialogState !== 'COMPLETED';
},
handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.withShouldEndSession(false)
.getResponse();
},
};
const CompletedTATANexonmodefeatureHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'TATANexonmodefeatureIntent';
},
handle(handlerInput) {
console.log('TATANexonmodefeatureIntent - handle');
const responseBuilder = handlerInput.responseBuilder;
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
const key1 = `${slotValues.yesnomodeslot.resolved}`;
const information1 = facts1[slotsToOptions1Map[key1]];
//NEW RESPONSE
const speechOutput = ` ${information1.text} `;
//` Would you be interested in the level nex technology infotainment system? `;
/*// activity is optional so we'll add it to the output
// only when we have a valid activity
if (slotValues.factMode) {
speechOutput += slotValues.factMode;
} else {
speechOutput += " So you're interested in the";
}
// Now let's recap the trip
speechOutput = `${speechOutput} ${slotValues.variantTATANexon.synonym} ${slotValues.modeTATANexon.synonym} mode and want to know about the ${slotValues.infotainmentTATANexon.synonym} infotainment system . Good to know !`;*/
//delete this.event.request.intent.slots.yesnomodeslot.resolutions;
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(false)
.getResponse();
},
};
const HelpHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
return responseBuilder
.speak(helpOutput)
.reprompt(helpReprompt)
.getResponse();
},
};
const CancelStopHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
(request.intent.name === 'AMAZON.CancelIntent' || request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const responseBuilder = handlerInput.responseBuilder;
const speechOutput = 'Okay, talk to you later! ';
return responseBuilder
.speak(speechOutput)
.withShouldEndSession(true)
.getResponse();
},
};
const SessionEndedHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
const request = handlerInput.requestEnvelope.request;
console.log(`Original Request was: ${JSON.stringify(request, null, 2)}`);
console.log(`Error handled: ${error}`);
return handlerInput.responseBuilder
.speak('Sorry, I can not understand the command. Please say again.')
.reprompt('Sorry, I can not understand the command. Please say again.')
.getResponse();
},
};
// 2. Helper Functions ============================================================================
function getSlotValues(filledSlots) {
const slotValues = {};
console.log(`The filled slots: ${JSON.stringify(filledSlots)}`);
Object.keys(filledSlots).forEach((item) => {
const name = filledSlots[item].name;
if (filledSlots[item] &&
filledSlots[item].resolutions &&
filledSlots[item].resolutions.resolutionsPerAuthority[0] &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status &&
filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
switch (filledSlots[item].resolutions.resolutionsPerAuthority[0].status.code) {
case 'ER_SUCCESS_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].resolutions.resolutionsPerAuthority[0].values[0].value.name,
isValidated: true,
};
break;
case 'ER_SUCCESS_NO_MATCH':
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
break;
default:
break;
}
} else {
slotValues[name] = {
synonym: filledSlots[item].value,
resolved: filledSlots[item].value,
isValidated: false,
};
}
}, this);
return slotValues;
}
/*function getRandomPhrase(array) {
// the argument is an array of words or phrases
const i = Math.floor(Math.random() * array.length);
return (array[i]);
}*/
// 4. Exports handler function and setup ===================================================
const skillBuilder = Alexa.SkillBuilders.custom();
exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressTATANexonmodelvariantfeatureHandler,
CompletedTATANexonmodelvariantfeatureHandler,
InProgressTATANexonmodefeatureHandler,
CompletedTATANexonmodefeatureHandler,
InProgressTATANexoninfotainmentfeatureHandler,
CompletedTATANexoninfotainmentfeatureHandler,
CancelStopHandler,
HelpHandler,
SessionEndedHandler,
)
.addErrorHandlers(ErrorHandler)
.lambda();
lambda alexa alexa-slot
lambda alexa alexa-slot
edited Nov 19 '18 at 6:29
monikr_on_east
asked Nov 16 '18 at 8:05
monikr_on_eastmonikr_on_east
115
115
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13
add a comment |
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13
add a comment |
1 Answer
1
active
oldest
votes
You need to work on your interaction model design. You should not use custom YesIntent
and NoIntent
, instead use predefined AMAZON.YesIntent
and AMAZON.NoIntent
.
If what I understood from your interaction model you only need two slots, model
and variant
.
Think about this way:
[TestDriveIntent]
start a test drive
I want a test drive
start a test drive on {model}
begin test drive on {model} {variant}
where {model}
and {variant}
are the two slots required to fulfill your intent. Once this dialog is started, you can delegate or elicit these slots to be filled. You can also use ConfirmSlot
and ConfirmIntent
directive to get confirmation from user before proceeding. The advantage here is that, you don't have to handle these "yes" and "no" inputs from user for these confirmations.
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 usevar attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can doattributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333732%2fempty-all-slot-values-in-intent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to work on your interaction model design. You should not use custom YesIntent
and NoIntent
, instead use predefined AMAZON.YesIntent
and AMAZON.NoIntent
.
If what I understood from your interaction model you only need two slots, model
and variant
.
Think about this way:
[TestDriveIntent]
start a test drive
I want a test drive
start a test drive on {model}
begin test drive on {model} {variant}
where {model}
and {variant}
are the two slots required to fulfill your intent. Once this dialog is started, you can delegate or elicit these slots to be filled. You can also use ConfirmSlot
and ConfirmIntent
directive to get confirmation from user before proceeding. The advantage here is that, you don't have to handle these "yes" and "no" inputs from user for these confirmations.
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 usevar attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can doattributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
add a comment |
You need to work on your interaction model design. You should not use custom YesIntent
and NoIntent
, instead use predefined AMAZON.YesIntent
and AMAZON.NoIntent
.
If what I understood from your interaction model you only need two slots, model
and variant
.
Think about this way:
[TestDriveIntent]
start a test drive
I want a test drive
start a test drive on {model}
begin test drive on {model} {variant}
where {model}
and {variant}
are the two slots required to fulfill your intent. Once this dialog is started, you can delegate or elicit these slots to be filled. You can also use ConfirmSlot
and ConfirmIntent
directive to get confirmation from user before proceeding. The advantage here is that, you don't have to handle these "yes" and "no" inputs from user for these confirmations.
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 usevar attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can doattributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
add a comment |
You need to work on your interaction model design. You should not use custom YesIntent
and NoIntent
, instead use predefined AMAZON.YesIntent
and AMAZON.NoIntent
.
If what I understood from your interaction model you only need two slots, model
and variant
.
Think about this way:
[TestDriveIntent]
start a test drive
I want a test drive
start a test drive on {model}
begin test drive on {model} {variant}
where {model}
and {variant}
are the two slots required to fulfill your intent. Once this dialog is started, you can delegate or elicit these slots to be filled. You can also use ConfirmSlot
and ConfirmIntent
directive to get confirmation from user before proceeding. The advantage here is that, you don't have to handle these "yes" and "no" inputs from user for these confirmations.
You need to work on your interaction model design. You should not use custom YesIntent
and NoIntent
, instead use predefined AMAZON.YesIntent
and AMAZON.NoIntent
.
If what I understood from your interaction model you only need two slots, model
and variant
.
Think about this way:
[TestDriveIntent]
start a test drive
I want a test drive
start a test drive on {model}
begin test drive on {model} {variant}
where {model}
and {variant}
are the two slots required to fulfill your intent. Once this dialog is started, you can delegate or elicit these slots to be filled. You can also use ConfirmSlot
and ConfirmIntent
directive to get confirmation from user before proceeding. The advantage here is that, you don't have to handle these "yes" and "no" inputs from user for these confirmations.
answered Nov 19 '18 at 14:18
Cicil ThomasCicil Thomas
3,40121633
3,40121633
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 usevar attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can doattributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
add a comment |
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 usevar attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can doattributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
I tried adding the AMAZON.YesIntent, AMAZON.NoIntent and use the sessionAttributes as instructed here stackoverflow.com/questions/52077201/amazon-alexa-skill, now I am unable to even get the first response
– monikr_on_east
Nov 20 '18 at 7:19
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
Did you correct your interaction model?
– Cicil Thomas
Nov 20 '18 at 16:29
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
I did. The thing is I am unable to figure out how to use sessionAttributes in my lambda function
– monikr_on_east
Nov 21 '18 at 5:14
The answer you mentioned use ask-sdk-v1. For v2 use
var attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can do attributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
The answer you mentioned use ask-sdk-v1. For v2 use
var attributes = handlerInput.attributesManager.getSessionAttributes()
to get the attributes and you can do attributes.yourSessionAttribute = "value"
and finally set it with'handlerInput.attributesManager.setSessionAttributes(attributes)
– Cicil Thomas
Nov 21 '18 at 7:59
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
I was able to get it done. Thanks a lot for your help!
– monikr_on_east
Nov 23 '18 at 7:49
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53333732%2fempty-all-slot-values-in-intent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Share little more information to look upon, like your interaction model, code snippet, request and response JSON.
– Cicil Thomas
Nov 16 '18 at 12:08
@CicilThomas, kindly find the requested.
– monikr_on_east
Nov 19 '18 at 6:13