我对编码和尝试学习非常陌生,所以请多多包涵。
我正在尝试创建一个非常基本的Alexa技能:
我的主要问题是发现缺乏信息和指南,无法将两者结合起来以使我正在尝试的工作变为现实。
是否可以将两者混合并实现我的目标?任何帮助表示赞赏。
此Lambda函数本身可以工作,并且将发送电子邮件,接受以下请求正文作为输入:
{
"SubCategory": "General",
"MainCategory": "Problem",
"Email": "email@email.com"
}
这是Lambda函数:
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);
}
});
};
这是Alexa Lambda函数:
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();