I have created one skill and code is as below with my test case.
(1) I am facing issue for the Invalid input after 3-4 times input given by user for both intents.
(2) If user call CustomerWiseProductPriceIntent it working fine but if user enter "No" or "go back" it should prompt for the LaunchRequest and start everything again but it prompts for "please, provide customer name or account number".
Currently this is happening:
When the user enters CustomerWiseProductPriceIntent
it prompts for Account no.
and product name
and after that it elicits slot: confirmation
(YES/NO/GO BACK)
If the user enters YES:
It is working fine and again asks for account no.
and product name
.
If user enters NO:
Then it enters inside No
and console logs "Inside No ....." but the next line: this.emit('AMAZON.StopIntent');
does not execute.
It then again asks for account no.
and product name
.
If user enters GO BACK:
Then it enters inside go back
but but the next line: this.emit('LaunchRequest');
does not execute.
It then again asks for account no.
and product name
.
Here is my code :
Lambda function :
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = undefined;
const SKILL_NAME = 'CustomerSupportVA';
const HELP_MESSAGE = 'You can say Item name to get On hand quantity or stop to exit';
const HELP_REPROMPT = 'What can I help you with?';
const STOP_MESSAGE = 'Thank for using EBS, Goodbye!';
const WELCOME_MESSAGE = "Welcome to EBS Speech Assistance, what do you like to know about <break time=\"1s\"/> On hand stock , past due or customer wise product price";
const handlers = {
'LaunchRequest': function() {
this.response.speak(WELCOME_MESSAGE).listen("Please provide input");
this.response.shouldEndSession(false);
this.emit(':responseReady');
},
'OnHandQuantityIntent': function() {
var intentObj = this.event.request.intent;
var self = this;
var slotToElicit = "";
console.log("this.event.request : "+JSON.stringify(this.event.request))
var promptForProductName = "please, provide Product name";
var confirmationStr = "<break time=\"1s\"/> " + " Would you like to know for other product on hand quantity?";
console.log("Request Object : "+JSON.stringify( this.event.request));
if (this.event.request.dialogState == "STARTED") {
slotToElicit = "productName";
this.emit(':elicitSlot', slotToElicit, promptForProductName, promptForProductName, intentObj);
}else if (this.event.request.dialogState == "IN_PROGRESS") {
console.log("=============>>>>>>>>>>>>0000000 "+intentObj.slots.productName.value)
if (intentObj.slots.productName.value) {
var productName = intentObj.slots.productName.value;
productName = productName.replace(' ', '');
getOnHandQuatitySrv(productName, function(result) {
intentObj.slots.productName.value = undefined;
slotToElicit = "confirmation";
self.response.shouldEndSession(false);
self.emit(':elicitSlot', slotToElicit, result + confirmationStr, confirmationStr, intentObj);
});
}else if ("yes" == intentObj.slots.confirmation.value) {
console.log("Inside Yes .....");
intentObj = this.event.request.intent;
slotToElicit = "productName";
this.emit(':elicitSlot', slotToElicit, promptForProductName, promptForProductName, intentObj);
intentObj.slots.confirmation.value = undefined;
}else if ("no" == intentObj.slots.confirmation.value) {
console.log("Inside No .....");
this.emit('AMAZON.StopIntent');
}else if ("go back" == intentObj.slots.confirmation.value) {
this.emit('LaunchRequest');
}
}
},
'CustomerWiseProductPriceIntent': function() {
var intentObj = this.event.request.intent;
var self = this;
var promptForCustomerName = "please, provide customer name or account number";
var promptForProductName = "please, provide product name";
var confirmationStr = "<break time=\"1s\"/> " + "Would you like to know for product price for other customer?";
var slotToElicit = "custAccountNameNo";
var slotToElicitProd = "productName";
if (this.event.request.dialogState == "STARTED") {
console.log("Inside STARTED .....");
if (!intentObj.slots.custAccountNameNo.value) {
this.emit(':elicitSlot', slotToElicit, promptForCustomerName, promptForCustomerName, intentObj);
}
}else if (this.event.request.dialogState == "IN_PROGRESS") {
console.log("Inside IN PROGRESS .....");
if(""==intentObj.slots.custAccountNameNo.value || intentObj.slots.custAccountNameNo.value==undefined){
this.emit(':elicitSlot', slotToElicit, promptForCustomerName, promptForCustomerName, intentObj);
}else if (""==intentObj.slots.productName.value || intentObj.slots.productName.value==undefined) {
this.emit(':elicitSlot', slotToElicitProd, promptForProductName, promptForProductName, intentObj);
}
if (intentObj.slots.custAccountNameNo.value!="" && intentObj.slots.productName.value!="") {
var custAccountNameNo = intentObj.slots.custAccountNameNo.value;
var productName = intentObj.slots.productName.value;
var speechOut="";
getCustomerWiseProductPriceSrv(custAccountNameNo, productName, function(itemPrice) {
if (itemPrice == undefined) {
itemPrice = 0;
}
else {
if (itemPrice == -333) {
speechOut = "Please provide valid Product Name";
slotToElicit="productName";
}
else if (itemPrice == -666) {
speechOut = "Please provide valid Account Number";
slotToElicit="custAccountNameNo";
}
else {
speechOut = "Price of " + productName + " is " + itemPrice + " for " + custAccountNameNo + " customer " + confirmationStr;
console.log("resultStr : " + speechOut);
slotToElicit = "confirmation";
intentObj.slots.productName.value = "";
intentObj.slots.custAccountNameNo.value = "";
}
}
slotToElicit = "confirmation";
intentObj.slots.productName.value = "";
intentObj.slots.custAccountNameNo.value="";
self.response.shouldEndSession(false);
intentObj = self.event.request.intent;
self.emit(':elicitSlot', slotToElicit, speechOut, speechOut, intentObj);
});
}else if ("yes" == intentObj.slots.confirmation.value) {
console.log("Inside Yes .....");
slotToElicit = "custAccountNameNo";
slotToElicitProd = "productName";
intentObj.slots.confirmation.value = "";
intentObj = this.event.request.intent;
this.response.shouldEndSession(false);
}
else if ("no" == intentObj.slots.confirmation.value) {
console.log("Inside No .....");
this.response.shouldEndSession(false);
this.emit('AMAZON.StopIntent');
}
else if ("go back" == intentObj.slots.confirmation.value) {
this.emit('LaunchRequest');
}
}
},
'AMAZON.HelpIntent': function() {
const speechOutput = HELP_MESSAGE;
const reprompt = HELP_REPROMPT;
this.response.speak(speechOutput).listen(reprompt);
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function() {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'AMAZON.StopIntent': function() {
this.response.speak(STOP_MESSAGE);
this.emit(':responseReady');
},
'Unhandled': function() {
this.response.speak("Invalid Input");
console.log("this.event.request : "+JSON.stringify(this.event.request))
this.emit(':responseReady');
},
};
exports.handler = function(event, context, callback) {
const alexa = Alexa.handler(event, context, callback);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var getOnHandQuatitySrv = function(productName, callback) {
var totalOnHandQuanity = Math.floor(Math.random() * Math.floor(999))
//web service call
var resultStr = "Total " + totalOnHandQuanity + " available for Product " + productName + "<break time=\"1s\"/> " + resultStr;
callback(resultStr);
}
var getCustomerWiseProductPriceSrv = function(customerAccountNameNo, ProductName, callback) {
var custWiseItemPrice = Math.floor(Math.random() * Math.floor(999));
//web service call
callback(custWiseItemPrice);
}
Here is my Model JSON :
{
"interactionModel": {
"languageModel": {
"invocationName": "product details",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples": []
},
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "OnHandQuantityIntent",
"slots": [
{
"name": "productName",
"type": "ProductName",
"samples": [
"on hand stock for {productName}",
"{productName}"
]
},
{
"name": "confirmation",
"type": "AMAZON.Genre",
"samples": [
"go back",
"No",
"yes"
]
}
],
"samples": [
"provide me on hand stock ",
"on hand quantity ",
"on hand stock "
]
},
{
"name": "CustomerWiseProductPriceIntent",
"slots": [
{
"name": "custAccountNameNo",
"type": "CustomerAccountNameNo",
"samples": [
"{custAccountNameNo}"
]
},
{
"name": "productName",
"type": "ProductName",
"samples": [
"{productName}"
]
},
{
"name": "confirmation",
"type": "AMAZON.Genre",
"samples": [
"go back",
"No",
"Yes"
]
}
],
"samples": [
"customer wise product price "
]
}
],
"types": [
{
"name": "ProductName",
"values": [
{
"id": "CM080901",
"name": {
"value": "CM080901",
"synonyms": [
"CM o eight o nine o one",
"CM zero eight zero nine zero one",
"CM080901"
]
}
},
{
"id": "f30000",
"name": {
"value": "f30000",
"synonyms": [
"F three O O O O",
"F thirty thousand",
"F three zero zero zero zero"
]
}
},
{
"id": "AT23808",
"name": {
"value": "AT23808",
"synonyms": [
"A T two three eight zero eight",
"AT twentythree thousand and eight hundred and eight",
"AT two three eight zero eight"
]
}
}
]
},
{
"name": "CustomerAccountNameNo",
"values": [
{
"id": "1004",
"name": {
"value": "1004",
"synonyms": [
"one o o four",
"one zero zero four",
"One thousand four"
]
}
},
{
"name": {
"value": "AT&T Universal Card",
"synonyms": [
"A T and T Universal Card",
"atandt Universal Card",
"AT&T Universal Card",
"AT and T Universal Card"
]
}
},
{
"name": {
"value": "hilman and associates",
"synonyms": [
"hilman and associates",
"hilman associates"
]
}
},
{
"name": {
"value": "American Telephone & Telegraph - GOLD",
"synonyms": [
"american telephone and telegraph dash gold",
"american telephone and telegraph gold",
"american telephone and telegraph - gold"
]
}
},
{
"name": {
"value": "A. C. NETWORKS",
"synonyms": [
"A CNetworks",
"ACNETWORKS",
"A C Networks"
]
}
},
{
"name": {
"value": "1001",
"synonyms": [
"one zero zero one",
"one o o one",
"one thousand one",
"1001"
]
}
}
]
}
]
},
"dialog": {
"intents": [
{
"name": "OnHandQuantityIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "productName",
"type": "ProductName",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.979240528726.539427738586"
}
},
{
"name": "confirmation",
"type": "AMAZON.Genre",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.979240528726.1367676676111"
}
}
]
},
{
"name": "CustomerWiseProductPriceIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "custAccountNameNo",
"type": "CustomerAccountNameNo",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.160438293908.60972362882"
}
},
{
"name": "productName",
"type": "ProductName",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.160438293908.513106626751"
}
},
{
"name": "confirmation",
"type": "AMAZON.Genre",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.160438293908.1422666600589"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Slot.979240528726.539427738586",
"variations": [
{
"type": "PlainText",
"value": "Please provide product name"
}
]
},
{
"id": "Elicit.Slot.979240528726.1367676676111",
"variations": [
{
"type": "PlainText",
"value": "would you like to know for other product on hand quantity?"
}
]
},
{
"id": "Elicit.Slot.160438293908.1422666600589",
"variations": [
{
"type": "PlainText",
"value": "DO you like to continue?"
}
]
},
{
"id": "Elicit.Slot.160438293908.60972362882",
"variations": [
{
"type": "PlainText",
"value": "provide customer account name or number"
}
]
},
{
"id": "Elicit.Slot.160438293908.513106626751",
"variations": [
{
"type": "PlainText",
"value": "provide product name"
}
]
}
]
}
}
Sometimes For both intent if user do multi turn conversation than dialogue states changes to "Started" and gives response "Invalid Input". For CustomerWiseProductPriceIntent if user enter "NO" it must message for stop and if user enter "go back" it prompt message like Launch Request.