I'm building a custom Alexa Skill with Node.js (which I'm new to). I have the skill set up, ONE custom intent created, and ONE custom slot with some test values. My goal is for my user to open the skill, and ask a question such as "how far away is the {slotname}", where slotname contains the two values "Sun" and "Moon", and based on what the user asks my skill would return some appropriate answer. Example:
User: "How far away is the Sun" Alexa: "The sun is almost ninety three million miles from Earth" User: "How far away is the Moon" Alexa: "The moon is just down the street"
My problem: While the concept makes sense, I don't know how to actually apply this to my code. My apologies, I'm new.
I have spent the past few nights trying to find similar posts by people who had a similar issue with Node.js. I tried searching for coding examples that could help guide me, watched videos, etc. Nothing has worked so far, which has led to this--my first post on Stack Overflow. So I'm hoping you lovely folks can help, and I've included the current state of my meek attempts below.
P.S. I am completely new to posting on S.O. If I have done something wrong, please let me know! I just didn't know where else to go for help at this point.
const MyIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'MyIntent';
},
handle(handlerInput) {
//var bigObect = this.event.request.intent.slots.slotName.value;
var bigObject = handlerInput.requestEnvelope.request.intent.slots.slotName.value;
var speakOutput;
if(bigObect === 'Sun') {
speakOutput = 'The sun is almost ninety three million miles away from Earth.';
} else if(bigObject === 'Moon') {
speakOutput = 'The moon is across the street.';
}
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
1.Replace the slotName
with the actual name of your slot (you can check that in your request body).
var bigObject = handlerInput.requestEnvelope.request.intent.slots.slotName.value;
2.There is a typo in if
condition it should be bigObject === 'Sun'
.
3.If this is the only intentHandler
in your skill , then you need to add handle the request.type === 'LaunchRequest'
condition also.
4.Make sure you are exporting the Intenthandler
i.e the intentHandler
is not just defined in the file but can be used when a request is made.
5.Make 100% sure that the request is coming from the skill you intend to i.e your lambda function(backend) and Alexa skill(frontend) are completely connected ( with ARN and Skill-ID ). This is the most common mistake :)