I am very new to coding and trying to learn, so please bear with me.
I am attempting to create a very basic Alexa Skill that:
- Asks a few questions
- Then sends an email with a little information gathered from the Alexa Skill via AWS-Lambda using AWS-SES.
My main issue is finding a lack of information and guidance on how to integrate the two to make what I'm attempting work.
Is it possible to mix the two and achieve what I'm aiming for? Any help is appreciated.
This Lambda function, by itself, works and will send emails, accepting the following Request Body as input:
{
"SubCategory": "General",
"MainCategory": "Problem",
"Email": "email@email.com"
}
This is the Lambda function:
var aws = require('aws-sdk');
var ses = new aws.SES({region: 'us-east-1'});
var toEmail = "email@email.com";
exports.handler = function(event, context) {
console.log("Incoming: ", event);
var eParams = {
Destination: {
ToAddresses: [toEmail]
},
Message: {
Body: {
Text: {
Data: event.SubCategory
}
},
Subject: {
Data: event.MainCategory
}
},
Source: event.Email
};
console.log('===SENDING EMAIL===');
var email = ses.sendEmail(eParams, function(err, data){
if(err) console.log(err);
else {
console.log("===EMAIL SENT===");
console.log(data);
console.log("EMAIL CODE END");
console.log('EMAIL: ', email);
context.succeed(event);
}
});
};
And this is the Alexa Lambda Function:
const Alexa = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Hi there, looks like you need some technical support. Lets get started. Are you having a problem or do you have a question?';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const ProblemIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'ProblemIntent';
},
handle(handlerInput) {
const speechText = 'Which of these categories does your problem fall into? General, Network, or Security?';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const QuestionIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'QuestionIntent';
},
handle(handlerInput) {
const speechText = 'Which of these categories does your question fall into? Software Development, Business Consulting, or virtual C.I.O. engagement? ';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const GeneralIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'GeneralIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a General Problem then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const NetworkIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'NetworkIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a Network Problem then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const SecurityIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SecurityIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a Security Problem then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const VirtualCioIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'VirtualCioIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a Virtual C.I.O. question then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const BusinessConsultingIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'BusinessConsultingIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a Business Consulting question then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const SoftwareDevelopmentIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'SoftwareDevelopmentIntent';
},
handle(handlerInput) {
const speechText = 'Looks like you have a Software Development question then, lets go ahead and notify the helpdesk. They should reach out to you soon.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'Please say either Problem or Question.';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(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');
},
handle(handlerInput) {
const speechText = 'Goodbye!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
// Any cleanup logic goes here.
return handlerInput.responseBuilder.getResponse();
}
};
const IntentReflectorHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest';
},
handle(handlerInput) {
const intentName = handlerInput.requestEnvelope.request.intent.name;
const speechText = `You just triggered ${intentName}`;
return handlerInput.responseBuilder
.speak(speechText)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`~~~~ Error handled: ${error.message}`);
const speechText = `Sorry, I couldn't understand what you said. Please try again.`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
ProblemIntentHandler,
QuestionIntentHandler,
GeneralIntentHandler,
NetworkIntentHandler,
SecurityIntentHandler,
VirtualCioIntentHandler,
BusinessConsultingIntentHandler,
SoftwareDevelopmentIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler)
.addErrorHandlers(
ErrorHandler)
.lambda();