I am trying to build an Alexa skill. I am still trying to get Alexa to say something when there is an intent request, but I get an error and I am not sure what to do with it. When I run the Sample Utterance through the Alexa service simulator I get the error:
The remote endpoint could not be called, or the response it returned was invalid.
If I run the same utterance through the lambda test event the error I get is:
"errorMessage": "Exception: ReferenceError: output is not defined"
My javascript code is
exports.handler = (event, context) => {
try {
//New Session
if(event.session.new) {
console.log("NEW SESSION")
}
switch (event.request.type) {
//Launch Request
case "LaunchRequest":
console.log(`LAUNCH REQUEST`)
context.succeed(
generateResponse(
buildSpeechletResponse("Welcome to an Alexa Skill, this is running on a lambda function", true),
{}
)
)
break;
//Intent Request
case "IntentRequest":
console.log(`INTENT REQUEST`)
switch(event.request.intent.name) {
case "FindFlight":
//Get data from user to send to Fare Portal
//Clean up data to send back to user
context.succeed(
generateResponse(
buildSpeechletResponse("Flight Search", "You asked to find a flight", true),
{}
)
)
break;
default:
throw "Invalid intent"
}
break;
//Session Ended Request
case "SessionEndedRequest":
console.log(`SESSION ENDED REQUEST`)
break;
default:
context.fail(`INVALID REQUEST TYPE: ${event.request.type}`)
}
} catch(error) {context.fail(`Exception: ${error}`)}
//Helpers
buildSpeechletResponse = (title, outputText, shouldEndSession) => {
return {
outputSpeech: {
type: "PlainText",
text: outputText
},
card: {
type: 'Simple',
title: `SessionSpeechlet - ${title}`,
content: `SessionSpeechlet - ${output}`,
},
shoudlEndSession: shouldEndSession
}
}
generateResponse = (sessionAttributes, speechletResponse) => {
return {
version: "1.0",
sessionAttributes: sessionAttributes,
response: speechletResponse
}
}
}
Any help would be greatly appreciated thanks!
outputis indeed not defined. So you need to use variables that are defined or you go ahead and defineoutput. - Sebastian Simon