您好我已经创建了一个lambda函数,可以使用主键从我的dynamodb表中调用项目。
这是我的代码
'use strict';
var AWS = require('aws-sdk');
var dclient = new AWS.DynamoDB.DocumentClient();
var getItems = (event, context, callback)=>{
dclient.get(event.params,(error,data)=>{
if(error){
callback(null,"error occurerd");
}
else{
callback(null,data);
}
});
};
exports.getItems = getItems;
//exportshandelrhandlergetItems = getItems;
它工作正常,但现在我想做的是设置它与alexa一起工作所以我可以让alexa查询我的表
任何人都可以帮我解决这个问题吗?香港专业教育学院创建了一项技能并将其全部链接但不确定如何进行我的交互模型
谢谢
这是我的意图架构
{
"intents": [
{
"intent": "date"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "Cinema"
},
{
"intent": "MyIntent"
}
]
}
答案 0 :(得分:2)
请按照以下步骤进行操作
请将以下代码复制到您的Lambda函数中,然后说“打开您的技能名称”,Alexa应回复'欢迎来到Alexa的世界'
exports.handler = (event, context, callback) => {
try {
var request = event.request;
if (request.type === "LaunchRequest") {
context.succeed(buildResponse({
speechText: "Welcome to the world of Alexa",
repromptText: "I repeat, Welcome to the world of Alexa",
endSession: false
}));
}
else if (request.type === "SessionEndedRequest") {
options.endSession = true;
context.succeed();
}
else {
context.fail("Unknown Intent type")
}
} catch (e) {
}
};
function buildResponse(options) {
var response = {
version: "1.0",
response: {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.speechText}</prosody></speak>`
},
shouldEndSession: options.endSession
}
};
if (options.repromptText) {
response.response.reprompt = {
outputSpeech: {
"type": "SSML",
"ssml": `<speak><prosody rate="slow">${options.repromptText}</prosody></speak>`
}
};
}
return response;
}
请在我的GitHub中找到一个样本(不使用Alexa SDK),
https://github.com/vnathv/alexa-myfortune/blob/master/MyFortune/Index.js