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











up vote
0
down vote

favorite












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









share|improve this question
























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












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 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 at 20:03










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















up vote
0
down vote

favorite












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









share|improve this question
























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












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 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 at 20:03










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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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









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






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 Nov 27 at 20:01









halfer

14.2k757106




14.2k757106










asked Nov 21 at 18:14









Michael Coleman

12




12












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












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 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 at 20:03










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


















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












  • Please post request to or response of your getSuggestion Intent.
    – Ussama Zubair
    Nov 22 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 at 20:03










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
















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






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














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




Please post request to or response of your getSuggestion Intent.
– Ussama Zubair
Nov 22 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 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 at 20:03












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




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












1 Answer
1






active

oldest

votes

















up vote
0
down vote













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



Hope this helps.






share|improve this answer























  • Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
    – Michael Coleman
    Nov 26 at 15:05












  • GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
    – Michael Coleman
    Nov 26 at 21:06












  • Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
    – Michael Coleman
    2 days ago










  • that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
    – bal simpson
    yesterday










  • It's got to be something REALLY stupid that I'm missing, then. Sigh
    – Michael Coleman
    yesterday











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',
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








up vote
0
down vote













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



Hope this helps.






share|improve this answer























  • Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
    – Michael Coleman
    Nov 26 at 15:05












  • GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
    – Michael Coleman
    Nov 26 at 21:06












  • Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
    – Michael Coleman
    2 days ago










  • that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
    – bal simpson
    yesterday










  • It's got to be something REALLY stupid that I'm missing, then. Sigh
    – Michael Coleman
    yesterday















up vote
0
down vote













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



Hope this helps.






share|improve this answer























  • Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
    – Michael Coleman
    Nov 26 at 15:05












  • GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
    – Michael Coleman
    Nov 26 at 21:06












  • Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
    – Michael Coleman
    2 days ago










  • that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
    – bal simpson
    yesterday










  • It's got to be something REALLY stupid that I'm missing, then. Sigh
    – Michael Coleman
    yesterday













up vote
0
down vote










up vote
0
down vote









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



Hope this helps.






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



Hope this helps.







share|improve this answer














share|improve this answer



share|improve this answer








edited 17 hours ago

























answered Nov 25 at 8:13









bal simpson

764




764












  • Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
    – Michael Coleman
    Nov 26 at 15:05












  • GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
    – Michael Coleman
    Nov 26 at 21:06












  • Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
    – Michael Coleman
    2 days ago










  • that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
    – bal simpson
    yesterday










  • It's got to be something REALLY stupid that I'm missing, then. Sigh
    – Michael Coleman
    yesterday


















  • Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
    – Michael Coleman
    Nov 26 at 15:05












  • GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
    – Michael Coleman
    Nov 26 at 21:06












  • Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
    – Michael Coleman
    2 days ago










  • that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
    – bal simpson
    yesterday










  • It's got to be something REALLY stupid that I'm missing, then. Sigh
    – Michael Coleman
    yesterday
















Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
– Michael Coleman
Nov 26 at 15:05






Thank you SO much for your help. I'm really at a loss and am just kind of guessing on how to fix it at this point and I'm sure it's something simple. I added your suggested default fix and the CloudWatch logs still show the same error: TypeError: Cannot read property 'City' of undefined.
– Michael Coleman
Nov 26 at 15:05














GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
– Michael Coleman
Nov 26 at 21:06






GREAT suggestion and I hadn't considered case being the issue, but it makes really good sense. However, I'm still getting the same error. I've edited my original post to reflect my code as it stands after making your suggested changes. THANK YOU for your help and anything else you can have me try is very very very appreciated!
– Michael Coleman
Nov 26 at 21:06














Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
– Michael Coleman
2 days ago




Hey there! I inserted your handlers portion without the while loop, and it still throws the same error. I have NO idea where to go from here as I feel I have tried just about everything :(
– Michael Coleman
2 days ago












that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
– bal simpson
yesterday




that's strange. the new code with const Alexa = require('ask-sdk-core'); works fine as a skill. I tested it.
– bal simpson
yesterday












It's got to be something REALLY stupid that I'm missing, then. Sigh
– Michael Coleman
yesterday




It's got to be something REALLY stupid that I'm missing, then. Sigh
– Michael Coleman
yesterday


















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

Lallio

Unable to find Lightning Node

Futebolista