I've been trying to write this custom Alexa skill for a day now but am stuck at something very small. I am unable to put retrieve values from an array when using variables. The code places[theplace].pincode
returns UNDEFINED.
Any pointers? Here is the entire code I am using.
// 1. Text strings
var languageStrings = {
'en': {
'translation': {
'WELCOME' : "Welcome to Pincode search!",
'HELP' : "Hi! you can ask me the pin code for any place you want. For example say Tell me the pin code for mumbai",
'ABOUT' : "This is an Alexa Skill.",
'STOP' : "Bye!"
}
}
};
var places = {
"mumbai": {
"pincode": "400001",
},
"delhi": {
"pincode": "110001",
},
};
// 2. Skill Code
var Alexa = require('alexa-sdk');
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
// alexa.appId = 'amzn1.echo-sdk-ams.app.1234';
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
this.emit(':tell', this.t('WELCOME') + ' ' + this.t('HELP'));
},
'getPlaceIntent': function () {
var theplace = this.event.request.intent.slots.place.value;
var thepincode = places[theplace]['pincode'];
this.emit(':tell', 'The pin code for '+ theplace + ' is ' + thepincode);
},
'AMAZON.HelpIntent': function () {
this.emit(':ask', this.t('HELP'));
},
'AMAZON.NoIntent': function () {
this.emit('AMAZON.StopIntent');
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', this.t('STOP'));
},
'AMAZON.StopIntent': function () {
this.emit(':tell', this.t('STOP'));
}
};