‘use strict’;
const { WebhookVerified: Webhook, ExpressJS } = require(‘jovo-framework’);
const { app } = require(’./app.js’);
//ExpressJS (Jovo Webhook)
if (process.argv.indexOf(’–webhook’) > -1) {
const port = process.env.JOVO_PORT || 3000;
Webhook.jovoApp = app;
Webhook.listen(port, () => {
console.info(Local server listening on port ${port}.
);
});
Webhook.post([’/webhook’,’/webhook_alexa’], async (req, res) => {
await app.handle(new ExpressJS(req, res));
});
}
//default security from Alexa
const Alexa = require(‘ask-sdk-core’);
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Hello there! My name is Elizabeth'; //this works, can change stuff here
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
//app.followUpState('IntroState').ask(speech, reprompt);
}
};
//testing intent handlers, this works after, we would need to add states and everything over to here
/*
const GoodIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’ && Alexa.getIntentName(handlerInput.requestEnvelope) === ‘GoodIntent’;
},
handle(handlerInput) {
const speakOutput = 'I\'m happy to hear that. Before we get started, could I get your first name?';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt('I\'m so pleased to hear that. Could I get your first name please?')
.getResponse();
}
};
*/
// Dont think we need this intent handler regardless
/*
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’
&& Alexa.getIntentName(handlerInput.requestEnvelope) === ‘HelloWorldIntent’;
},
handle(handlerInput) {
const speakOutput = ‘Hello World!’;
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt(‘add a reprompt if you want to keep the session open for the user to respond’)
.getResponse();
}
};
*/
const HelpIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’
&& Alexa.getIntentName(handlerInput.requestEnvelope) === ‘AMAZON.HelpIntent’;
},
handle(handlerInput) {
const speakOutput = ‘You can say hello to me! How can I help?’;
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’
&& (Alexa.getIntentName(handlerInput.requestEnvelope) === ‘AMAZON.CancelIntent’
|| Alexa.getIntentName(handlerInput.requestEnvelope) === ‘AMAZON.StopIntent’);
},
handle(handlerInput) {
const speakOutput = ‘Goodbye!’;
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘SessionEndedRequest’;
},
handle(handlerInput) {
// Any cleanup logic goes here.
return handlerInput.responseBuilder.getResponse();
}
};
// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === ‘IntentRequest’;
},
handle(handlerInput) {
const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
const speakOutput = You just triggered ${intentName}
;
return handlerInput.responseBuilder
.speak(speakOutput)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(~~~~ Error handled: ${error.stack}
);
const speakOutput = Sorry, I had trouble doing what you asked. Please try again.
;
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you’ve
// defined are included below. The order matters - they’re processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
//HelloWorldIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
//GoodIntentHandler,
IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn’t override your custom intent handlers
)
.addErrorHandlers(
ErrorHandler,
)
.lambda();
//end security by Alexa
/*
//AWS Lambda
exports.handler = async (event, context, callback) => {
// context.callbackWaitsForEmptyEventLoop = false;
await app.handle(new Lambda(event, context, callback));
};
*/
Thank you!