Alexa Skill Learning: TypeError: Cannot read property 'value' of undefined












0














I keep getting an error when I try to test my basic skill (I'm trying to learn how to create them).
Here is the error from the log:




2018-11-21T16:10:55.759Z 06a36441-eda8-11e8-a421-f996bf66c592
Unexpected exception 'TypeError: Cannot read property 'value' of
undefined':



TypeError: Cannot read property 'value' of undefined at
Object.getSuggestion (/var/task/index.js:31:54) at emitNone
(events.js:86:13) at AlexaRequestEmitter.emit (events.js:185:7) at
AlexaRequestEmitter.EmitEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:216:10) at
AlexaRequestEmitter.ValidateRequest
(/var/task/node_modules/alexa-sdk/lib/alexa.js:181:23) at
AlexaRequestEmitter.HandleLambdaEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:126:25) at
AlexaRequestEmitter.value
(/var/task/node_modules/alexa-sdk/lib/alexa.js:100:31)



at exports.handler (/var/task/index.js:52:9)




How can I figure this out?



Here is my code:



var Alexa = require('alexa-sdk');


const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';


const skillData = [
{
city: "Austin",
suggestion: "Austin has some of the most outstanding people."
},
{
city: "San Antonio",
suggestion: "San Antonio has some of the most outstanding people."
},
{
city: "Dallas",
suggestion: "The Dallas metroplex is one of the hottest places."
}
];


var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {


this.emit(':ask', 'Tell me the name of the major city you are closest to'
},
'Unhandled': function () {
this.emit(':ask', 'Try saying a city name like Austin, San Antonio, or Dallas');
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.City.value;


this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};
number = number+1;
}


exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};


function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {
if (arr[i][propName] == cityName) {
return arr[i];
}
}
}


Update



I've made some changes that were suggested below, however, I am still getting an error after the initial response.




"errorMessage": "Cannot read property 'city' of undefined"




Please look at my new code and help me figure this out:



var Alexa = require('alexa-sdk');

const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';

const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', 'Tell me the name of the major city you are closest to!', 'Which major city are you closest to?');
},
'Unhandled': function () {
this.emit(':ask', "Try saying a city name like Austin, San Antonio, or Dallas");
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.city.value;

this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};

number = number+1;
}
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


UPDATE #2



After a lot of trying different things, I've gotten the skill to run with the help of bal simpson!



However, the skill still errors out when the user utters a city name. There must be an error in my Interaction Model, which is below:



   {
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": ,
"samples": [
"san antonio",
"dallas",
"austin"
]
}
],
"types":
}
}
}


Getting close!!



As a last-ditch effort:



Here is my index.js housed in Lambda. Would anyone mind looking at this?






const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





And here is my Interaction Model from the Developer Portal:






{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}












share|improve this question
























  • post your response of getSuggestion Intent
    – Shreya Prajapati
    Nov 22 '18 at 6:05












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 '18 at 12:52










  • When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
    – halfer
    Nov 27 '18 at 20:03










  • You are correct! It was totally my bad. Thanks for cleaning it up!
    – Michael Coleman
    Nov 27 '18 at 20:15
















0














I keep getting an error when I try to test my basic skill (I'm trying to learn how to create them).
Here is the error from the log:




2018-11-21T16:10:55.759Z 06a36441-eda8-11e8-a421-f996bf66c592
Unexpected exception 'TypeError: Cannot read property 'value' of
undefined':



TypeError: Cannot read property 'value' of undefined at
Object.getSuggestion (/var/task/index.js:31:54) at emitNone
(events.js:86:13) at AlexaRequestEmitter.emit (events.js:185:7) at
AlexaRequestEmitter.EmitEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:216:10) at
AlexaRequestEmitter.ValidateRequest
(/var/task/node_modules/alexa-sdk/lib/alexa.js:181:23) at
AlexaRequestEmitter.HandleLambdaEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:126:25) at
AlexaRequestEmitter.value
(/var/task/node_modules/alexa-sdk/lib/alexa.js:100:31)



at exports.handler (/var/task/index.js:52:9)




How can I figure this out?



Here is my code:



var Alexa = require('alexa-sdk');


const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';


const skillData = [
{
city: "Austin",
suggestion: "Austin has some of the most outstanding people."
},
{
city: "San Antonio",
suggestion: "San Antonio has some of the most outstanding people."
},
{
city: "Dallas",
suggestion: "The Dallas metroplex is one of the hottest places."
}
];


var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {


this.emit(':ask', 'Tell me the name of the major city you are closest to'
},
'Unhandled': function () {
this.emit(':ask', 'Try saying a city name like Austin, San Antonio, or Dallas');
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.City.value;


this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};
number = number+1;
}


exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};


function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {
if (arr[i][propName] == cityName) {
return arr[i];
}
}
}


Update



I've made some changes that were suggested below, however, I am still getting an error after the initial response.




"errorMessage": "Cannot read property 'city' of undefined"




Please look at my new code and help me figure this out:



var Alexa = require('alexa-sdk');

const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';

const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', 'Tell me the name of the major city you are closest to!', 'Which major city are you closest to?');
},
'Unhandled': function () {
this.emit(':ask', "Try saying a city name like Austin, San Antonio, or Dallas");
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.city.value;

this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};

number = number+1;
}
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


UPDATE #2



After a lot of trying different things, I've gotten the skill to run with the help of bal simpson!



However, the skill still errors out when the user utters a city name. There must be an error in my Interaction Model, which is below:



   {
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": ,
"samples": [
"san antonio",
"dallas",
"austin"
]
}
],
"types":
}
}
}


Getting close!!



As a last-ditch effort:



Here is my index.js housed in Lambda. Would anyone mind looking at this?






const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





And here is my Interaction Model from the Developer Portal:






{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}












share|improve this question
























  • post your response of getSuggestion Intent
    – Shreya Prajapati
    Nov 22 '18 at 6:05












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 '18 at 12:52










  • When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
    – halfer
    Nov 27 '18 at 20:03










  • You are correct! It was totally my bad. Thanks for cleaning it up!
    – Michael Coleman
    Nov 27 '18 at 20:15














0












0








0







I keep getting an error when I try to test my basic skill (I'm trying to learn how to create them).
Here is the error from the log:




2018-11-21T16:10:55.759Z 06a36441-eda8-11e8-a421-f996bf66c592
Unexpected exception 'TypeError: Cannot read property 'value' of
undefined':



TypeError: Cannot read property 'value' of undefined at
Object.getSuggestion (/var/task/index.js:31:54) at emitNone
(events.js:86:13) at AlexaRequestEmitter.emit (events.js:185:7) at
AlexaRequestEmitter.EmitEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:216:10) at
AlexaRequestEmitter.ValidateRequest
(/var/task/node_modules/alexa-sdk/lib/alexa.js:181:23) at
AlexaRequestEmitter.HandleLambdaEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:126:25) at
AlexaRequestEmitter.value
(/var/task/node_modules/alexa-sdk/lib/alexa.js:100:31)



at exports.handler (/var/task/index.js:52:9)




How can I figure this out?



Here is my code:



var Alexa = require('alexa-sdk');


const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';


const skillData = [
{
city: "Austin",
suggestion: "Austin has some of the most outstanding people."
},
{
city: "San Antonio",
suggestion: "San Antonio has some of the most outstanding people."
},
{
city: "Dallas",
suggestion: "The Dallas metroplex is one of the hottest places."
}
];


var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {


this.emit(':ask', 'Tell me the name of the major city you are closest to'
},
'Unhandled': function () {
this.emit(':ask', 'Try saying a city name like Austin, San Antonio, or Dallas');
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.City.value;


this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};
number = number+1;
}


exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};


function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {
if (arr[i][propName] == cityName) {
return arr[i];
}
}
}


Update



I've made some changes that were suggested below, however, I am still getting an error after the initial response.




"errorMessage": "Cannot read property 'city' of undefined"




Please look at my new code and help me figure this out:



var Alexa = require('alexa-sdk');

const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';

const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', 'Tell me the name of the major city you are closest to!', 'Which major city are you closest to?');
},
'Unhandled': function () {
this.emit(':ask', "Try saying a city name like Austin, San Antonio, or Dallas");
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.city.value;

this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};

number = number+1;
}
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


UPDATE #2



After a lot of trying different things, I've gotten the skill to run with the help of bal simpson!



However, the skill still errors out when the user utters a city name. There must be an error in my Interaction Model, which is below:



   {
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": ,
"samples": [
"san antonio",
"dallas",
"austin"
]
}
],
"types":
}
}
}


Getting close!!



As a last-ditch effort:



Here is my index.js housed in Lambda. Would anyone mind looking at this?






const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





And here is my Interaction Model from the Developer Portal:






{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}












share|improve this question















I keep getting an error when I try to test my basic skill (I'm trying to learn how to create them).
Here is the error from the log:




2018-11-21T16:10:55.759Z 06a36441-eda8-11e8-a421-f996bf66c592
Unexpected exception 'TypeError: Cannot read property 'value' of
undefined':



TypeError: Cannot read property 'value' of undefined at
Object.getSuggestion (/var/task/index.js:31:54) at emitNone
(events.js:86:13) at AlexaRequestEmitter.emit (events.js:185:7) at
AlexaRequestEmitter.EmitEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:216:10) at
AlexaRequestEmitter.ValidateRequest
(/var/task/node_modules/alexa-sdk/lib/alexa.js:181:23) at
AlexaRequestEmitter.HandleLambdaEvent
(/var/task/node_modules/alexa-sdk/lib/alexa.js:126:25) at
AlexaRequestEmitter.value
(/var/task/node_modules/alexa-sdk/lib/alexa.js:100:31)



at exports.handler (/var/task/index.js:52:9)




How can I figure this out?



Here is my code:



var Alexa = require('alexa-sdk');


const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';


const skillData = [
{
city: "Austin",
suggestion: "Austin has some of the most outstanding people."
},
{
city: "San Antonio",
suggestion: "San Antonio has some of the most outstanding people."
},
{
city: "Dallas",
suggestion: "The Dallas metroplex is one of the hottest places."
}
];


var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {


this.emit(':ask', 'Tell me the name of the major city you are closest to'
},
'Unhandled': function () {
this.emit(':ask', 'Try saying a city name like Austin, San Antonio, or Dallas');
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.City.value;


this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};
number = number+1;
}


exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};


function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {
if (arr[i][propName] == cityName) {
return arr[i];
}
}
}


Update



I've made some changes that were suggested below, however, I am still getting an error after the initial response.




"errorMessage": "Cannot read property 'city' of undefined"




Please look at my new code and help me figure this out:



var Alexa = require('alexa-sdk');

const APP_ID = 'amzn1.ask.skill.ab07421a-0a92-4c2b-b3bd-998e14286xxx';

const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

var number = 0;
while(number<3){
var handlers = {
'LaunchRequest': function () {
this.emit(':ask', 'Tell me the name of the major city you are closest to!', 'Which major city are you closest to?');
},
'Unhandled': function () {
this.emit(':ask', "Try saying a city name like Austin, San Antonio, or Dallas");
},
'getSuggestion': function() {
var city = this.event.request.intent.slots.city.value;

this.emit(':ask', getSuggestion(skillData,'city', city.toUpperCase()).suggestion + '. Give me another city and I'll hook you up with the best peeps.');
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', "What can I help you with?", "How can I help?");
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', "Okay!");
},
'AMAZON.StopIntent': function () {
this.emit(':tell', "Goodbye!");
},
};

number = number+1;
}
exports.handler = function(event, context, callback){
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


UPDATE #2



After a lot of trying different things, I've gotten the skill to run with the help of bal simpson!



However, the skill still errors out when the user utters a city name. There must be an error in my Interaction Model, which is below:



   {
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": ,
"samples": [
"san antonio",
"dallas",
"austin"
]
}
],
"types":
}
}
}


Getting close!!



As a last-ditch effort:



Here is my index.js housed in Lambda. Would anyone mind looking at this?






const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





And here is my Interaction Model from the Developer Portal:






{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}








const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Lets get you into your new home. Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slot.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Seeya later!`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}





{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}





{
"interactionModel": {
"languageModel": {
"invocationName": "city picker",
"intents": [
{
"name": "AMAZON.FallbackIntent",
"samples":
},
{
"name": "AMAZON.CancelIntent",
"samples":
},
{
"name": "AMAZON.HelpIntent",
"samples":
},
{
"name": "AMAZON.StopIntent",
"samples": [
"stop"
]
},
{
"name": "AMAZON.NavigateHomeIntent",
"samples":
},
{
"name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"{city}"
]
}
],
"types": [
{
"name": "CITY_NAMES",
"values": [
{
"name": {
"value": "dallas"
}
},
{
"name": {
"value": "san antonio"
}
},
{
"name": {
"value": "austin"
}
}
]
}
]
}
}
}






node.js aws-lambda alexa alexa-skills-kit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 4 '18 at 15:22







Michael Coleman

















asked Nov 21 '18 at 18:14









Michael ColemanMichael Coleman

35




35












  • post your response of getSuggestion Intent
    – Shreya Prajapati
    Nov 22 '18 at 6:05












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 '18 at 12:52










  • When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
    – halfer
    Nov 27 '18 at 20:03










  • You are correct! It was totally my bad. Thanks for cleaning it up!
    – Michael Coleman
    Nov 27 '18 at 20:15


















  • post your response of getSuggestion Intent
    – Shreya Prajapati
    Nov 22 '18 at 6:05












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 '18 at 12:52










  • When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
    – halfer
    Nov 27 '18 at 20:03










  • You are correct! It was totally my bad. Thanks for cleaning it up!
    – Michael Coleman
    Nov 27 '18 at 20:15
















post your response of getSuggestion Intent
– Shreya Prajapati
Nov 22 '18 at 6:05






post your response of getSuggestion Intent
– Shreya Prajapati
Nov 22 '18 at 6:05














Please post request to or response of your getSuggestion Intent.
– Ussama Zubair
Nov 22 '18 at 12:52




Please post request to or response of your getSuggestion Intent.
– Ussama Zubair
Nov 22 '18 at 12:52












When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
– halfer
Nov 27 '18 at 20:03




When making a change to a question that already has answers, it is worth getting into the habit of asking yourself whether the change would invalidate those answer(s). In this case the change was substantial, so it is better to add an update, so that new readers of the question do not start off with reading an "update" at the very start. (Some changes are so drastic that they are better as a new question, for much the same reasons). The golden rule is ensuring answers are still relevant for the questions above them.
– halfer
Nov 27 '18 at 20:03












You are correct! It was totally my bad. Thanks for cleaning it up!
– Michael Coleman
Nov 27 '18 at 20:15




You are correct! It was totally my bad. Thanks for cleaning it up!
– Michael Coleman
Nov 27 '18 at 20:15












1 Answer
1






active

oldest

votes


















0














ok. alexa-sdk has been deprecated link. To get the new SDK, do this.



1 - Create a new function in Lambda.



2 - Choose AWS Serverless Application Repository.
alexa-skills-kit-nodejs-factskill



3 - Choose alexa-skills-kit-nodejs-factskill.



4 - Click on deploy. Once deployed, click on functions and you should see the new function you just created with a name like aws-serverless-repository-alexaskillskitnodejsfact-NR8HPILH8WNI.
enter image description here



5 - Delete the code and replace the code with this.
enter image description here



const Alexa = require('ask-sdk');    
const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slots.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Goodbye`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


6 - Go to developer.amazon.com and change your Alexa Skill endpoint to the new lambda ARN.
enter image description here



To add a slot type:



enter image description here



Specify slot in your sample phrases like this:



enter image description here



Change your slot name to city:



enter image description here



So instead of musicStations it will be city. Make sure you have entered the three values in your slot values like this:



Add your custom slot values to CITY_NAMES:
Add slot values



If you have done it right, your interaction model should be something like this:



                "name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"city name is {city}",
"{city}"
]


Testing Lambda code



In the drop down menu, choose 'configure test events'.
enter image description here



Create new test event with JSON from your developer test portal which should look like this.



{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.XXXXXX",
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
},
"device": {
"deviceId": "amzn1.ask.device.XXXXXX",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "ACCESS_TOKEN"
},
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.XXXX",
"timestamp": "2018-12-03T20:28:29Z",
"locale": "en-IN",
"intent": {
"name": "PlayRadioIntent",
"confirmationStatus": "NONE",
"slots": {
"musicStation": {
"name": "musicStation",
"value": "classic rock",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.XXXX.RadioStations",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Classic Rock",
"id": "b8a5bd97a8a02691f9f81dcfb12184dd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}


Click on test button



Check Logs



Does the test result look like this? To see the logs, click on logs. It might have additional error details.



enter image description here






share|improve this answer























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Dec 4 '18 at 22:43











Your Answer






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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418242%2falexa-skill-learning-typeerror-cannot-read-property-value-of-undefined%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









0














ok. alexa-sdk has been deprecated link. To get the new SDK, do this.



1 - Create a new function in Lambda.



2 - Choose AWS Serverless Application Repository.
alexa-skills-kit-nodejs-factskill



3 - Choose alexa-skills-kit-nodejs-factskill.



4 - Click on deploy. Once deployed, click on functions and you should see the new function you just created with a name like aws-serverless-repository-alexaskillskitnodejsfact-NR8HPILH8WNI.
enter image description here



5 - Delete the code and replace the code with this.
enter image description here



const Alexa = require('ask-sdk');    
const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slots.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Goodbye`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


6 - Go to developer.amazon.com and change your Alexa Skill endpoint to the new lambda ARN.
enter image description here



To add a slot type:



enter image description here



Specify slot in your sample phrases like this:



enter image description here



Change your slot name to city:



enter image description here



So instead of musicStations it will be city. Make sure you have entered the three values in your slot values like this:



Add your custom slot values to CITY_NAMES:
Add slot values



If you have done it right, your interaction model should be something like this:



                "name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"city name is {city}",
"{city}"
]


Testing Lambda code



In the drop down menu, choose 'configure test events'.
enter image description here



Create new test event with JSON from your developer test portal which should look like this.



{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.XXXXXX",
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
},
"device": {
"deviceId": "amzn1.ask.device.XXXXXX",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "ACCESS_TOKEN"
},
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.XXXX",
"timestamp": "2018-12-03T20:28:29Z",
"locale": "en-IN",
"intent": {
"name": "PlayRadioIntent",
"confirmationStatus": "NONE",
"slots": {
"musicStation": {
"name": "musicStation",
"value": "classic rock",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.XXXX.RadioStations",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Classic Rock",
"id": "b8a5bd97a8a02691f9f81dcfb12184dd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}


Click on test button



Check Logs



Does the test result look like this? To see the logs, click on logs. It might have additional error details.



enter image description here






share|improve this answer























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Dec 4 '18 at 22:43
















0














ok. alexa-sdk has been deprecated link. To get the new SDK, do this.



1 - Create a new function in Lambda.



2 - Choose AWS Serverless Application Repository.
alexa-skills-kit-nodejs-factskill



3 - Choose alexa-skills-kit-nodejs-factskill.



4 - Click on deploy. Once deployed, click on functions and you should see the new function you just created with a name like aws-serverless-repository-alexaskillskitnodejsfact-NR8HPILH8WNI.
enter image description here



5 - Delete the code and replace the code with this.
enter image description here



const Alexa = require('ask-sdk');    
const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slots.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Goodbye`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


6 - Go to developer.amazon.com and change your Alexa Skill endpoint to the new lambda ARN.
enter image description here



To add a slot type:



enter image description here



Specify slot in your sample phrases like this:



enter image description here



Change your slot name to city:



enter image description here



So instead of musicStations it will be city. Make sure you have entered the three values in your slot values like this:



Add your custom slot values to CITY_NAMES:
Add slot values



If you have done it right, your interaction model should be something like this:



                "name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"city name is {city}",
"{city}"
]


Testing Lambda code



In the drop down menu, choose 'configure test events'.
enter image description here



Create new test event with JSON from your developer test portal which should look like this.



{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.XXXXXX",
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
},
"device": {
"deviceId": "amzn1.ask.device.XXXXXX",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "ACCESS_TOKEN"
},
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.XXXX",
"timestamp": "2018-12-03T20:28:29Z",
"locale": "en-IN",
"intent": {
"name": "PlayRadioIntent",
"confirmationStatus": "NONE",
"slots": {
"musicStation": {
"name": "musicStation",
"value": "classic rock",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.XXXX.RadioStations",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Classic Rock",
"id": "b8a5bd97a8a02691f9f81dcfb12184dd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}


Click on test button



Check Logs



Does the test result look like this? To see the logs, click on logs. It might have additional error details.



enter image description here






share|improve this answer























  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Dec 4 '18 at 22:43














0












0








0






ok. alexa-sdk has been deprecated link. To get the new SDK, do this.



1 - Create a new function in Lambda.



2 - Choose AWS Serverless Application Repository.
alexa-skills-kit-nodejs-factskill



3 - Choose alexa-skills-kit-nodejs-factskill.



4 - Click on deploy. Once deployed, click on functions and you should see the new function you just created with a name like aws-serverless-repository-alexaskillskitnodejsfact-NR8HPILH8WNI.
enter image description here



5 - Delete the code and replace the code with this.
enter image description here



const Alexa = require('ask-sdk');    
const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slots.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Goodbye`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


6 - Go to developer.amazon.com and change your Alexa Skill endpoint to the new lambda ARN.
enter image description here



To add a slot type:



enter image description here



Specify slot in your sample phrases like this:



enter image description here



Change your slot name to city:



enter image description here



So instead of musicStations it will be city. Make sure you have entered the three values in your slot values like this:



Add your custom slot values to CITY_NAMES:
Add slot values



If you have done it right, your interaction model should be something like this:



                "name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"city name is {city}",
"{city}"
]


Testing Lambda code



In the drop down menu, choose 'configure test events'.
enter image description here



Create new test event with JSON from your developer test portal which should look like this.



{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.XXXXXX",
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
},
"device": {
"deviceId": "amzn1.ask.device.XXXXXX",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "ACCESS_TOKEN"
},
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.XXXX",
"timestamp": "2018-12-03T20:28:29Z",
"locale": "en-IN",
"intent": {
"name": "PlayRadioIntent",
"confirmationStatus": "NONE",
"slots": {
"musicStation": {
"name": "musicStation",
"value": "classic rock",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.XXXX.RadioStations",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Classic Rock",
"id": "b8a5bd97a8a02691f9f81dcfb12184dd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}


Click on test button



Check Logs



Does the test result look like this? To see the logs, click on logs. It might have additional error details.



enter image description here






share|improve this answer














ok. alexa-sdk has been deprecated link. To get the new SDK, do this.



1 - Create a new function in Lambda.



2 - Choose AWS Serverless Application Repository.
alexa-skills-kit-nodejs-factskill



3 - Choose alexa-skills-kit-nodejs-factskill.



4 - Click on deploy. Once deployed, click on functions and you should see the new function you just created with a name like aws-serverless-repository-alexaskillskitnodejsfact-NR8HPILH8WNI.
enter image description here



5 - Delete the code and replace the code with this.
enter image description here



const Alexa = require('ask-sdk');    
const skillData = [
{
city: 'Austin',
suggestion: "Austin is blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'San Antonio',
suggestion: "San Antonio has blahblahblahblahlshflashdfasldfha blah."
},
{
city: 'Dallas',
suggestion: "The Dallas metroplex is one of the hottest blahblahblahbla blahblahblahblahblahblah."
}
];

const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "LaunchRequest";
},
handle(handlerInput) {

console.log("LaunchRequestHandler");
let speechText = 'Tell me the name of the major city you are closest to!';
let prompt = 'Which major city are you closest to?';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(prompt)
.getResponse();
}
};

const GetSuggestionIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "getSuggestion"
);
},
handle(handlerInput) {
let intent = handlerInput.requestEnvelope.request.intent;
let city = intent.slots.city.value;

let suggestion = getSuggestion(skillData,'city', city.toUpperCase()).suggestion;

return handlerInput.responseBuilder
.speak(suggestion)
.reprompt('prompt')
.getResponse();
}
};

const HelpIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "AMAZON.HelpIntent"
);
},
handle(handlerInput) {
const speechText = "Try saying a city name like Austin, San Antonio, or Dallas";
const promptText = "How can I help?";

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(promptText)
// .withSimpleCard("City Details", speechText)
.getResponse();
}
};

const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type === "IntentRequest" &&
(handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.CancelIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.StopIntent" ||
handlerInput.requestEnvelope.request.intent.name ===
"AMAZON.PauseIntent")
);
},
handle(handlerInput) {

const speechText = `Goodbye`;

return (
handlerInput.responseBuilder
.speak(speechText)
.withShouldEndSession(true)
.getResponse()
);
}
};

const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.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) {
console.log(`Error handled: ${error.message}`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Try saying a city name like Austin, San Antonio, or Dallas')
.reprompt('Try saying a city name like Austin, San Antonio, or Dallas')
.getResponse();
},
};

const SystemExceptionHandler = {
canHandle(handlerInput) {
return (
handlerInput.requestEnvelope.request.type ===
"System.ExceptionEncountered"
);
},
handle(handlerInput) {
console.log(
`System exception encountered: ${
handlerInput.requestEnvelope.request.reason
}`
);
}
};

const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
GetSuggestionIntentHandler,
CancelAndStopIntentHandler,
HelpIntentHandler,
SystemExceptionHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.lambda();

function getSuggestion(arr, propName, cityName) {
for (var i=0; i < arr.length; i++) {

var prop = arr[i][propName];
prop = prop.toUpperCase();

if (prop == cityName) {
return arr[i];
}
}
}


6 - Go to developer.amazon.com and change your Alexa Skill endpoint to the new lambda ARN.
enter image description here



To add a slot type:



enter image description here



Specify slot in your sample phrases like this:



enter image description here



Change your slot name to city:



enter image description here



So instead of musicStations it will be city. Make sure you have entered the three values in your slot values like this:



Add your custom slot values to CITY_NAMES:
Add slot values



If you have done it right, your interaction model should be something like this:



                "name": "getSuggestion",
"slots": [
{
"name": "city",
"type": "CITY_NAMES"
}
],
"samples": [
"city name is {city}",
"{city}"
]


Testing Lambda code



In the drop down menu, choose 'configure test events'.
enter image description here



Create new test event with JSON from your developer test portal which should look like this.



{
"version": "1.0",
"session": {
"new": true,
"sessionId": "amzn1.echo-api.session.XXXXXX",
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
}
},
"context": {
"AudioPlayer": {
"playerActivity": "IDLE"
},
"System": {
"application": {
"applicationId": "amzn1.ask.skill.XXXXXX"
},
"user": {
"userId": "amzn1.ask.account.XXXXXX"
},
"device": {
"deviceId": "amzn1.ask.device.XXXXXX",
"supportedInterfaces": {
"AudioPlayer": {}
}
},
"apiEndpoint": "https://api.eu.amazonalexa.com",
"apiAccessToken": "ACCESS_TOKEN"
},
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.XXXX",
"timestamp": "2018-12-03T20:28:29Z",
"locale": "en-IN",
"intent": {
"name": "PlayRadioIntent",
"confirmationStatus": "NONE",
"slots": {
"musicStation": {
"name": "musicStation",
"value": "classic rock",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.XXXX.RadioStations",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "Classic Rock",
"id": "b8a5bd97a8a02691f9f81dcfb12184dd"
}
}
]
}
]
},
"confirmationStatus": "NONE",
"source": "USER"
}
}
}
}


Click on test button



Check Logs



Does the test result look like this? To see the logs, click on logs. It might have additional error details.



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 4 '18 at 19:43

























answered Nov 25 '18 at 8:13









bal simpsonbal simpson

916




916












  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Dec 4 '18 at 22:43


















  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Samuel Liew
    Dec 4 '18 at 22:43
















Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew
Dec 4 '18 at 22:43




Comments are not for extended discussion; this conversation has been moved to chat.
– Samuel Liew
Dec 4 '18 at 22:43


















draft saved

draft discarded




















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418242%2falexa-skill-learning-typeerror-cannot-read-property-value-of-undefined%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python