Link alexa 技能包的 lambda 函数
Link lambda function to alexa skill kit
您好,我已经创建了一个 lambda 函数,它可以使用主键从我的 dynamodb table 中调用项目。
这是我的代码
'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 查询我的 table
谁能帮我解决这个问题?我创建了一项技能并将其全部链接起来但不确定如何建立我的交互模型
感谢
这是我的意图架构
{
"intents": [
{
"intent": "date"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "Cinema"
},
{
"intent": "MyIntent"
}
]
}
请按照以下步骤操作,
- 转到https://developer.amazon.com/
- 使用您的帐户登录
- 点击 Alexa
- 点击'Add new Skills'
- 填写 'Skill information' 和 'Interaction Model' 部分
- 在 'Configuration' 部分提到您的 Lambda ARN,如下所示,
请将下面的代码复制到您的 Lambda 函数中,只需说“打开 'YOUR SKILL NAME'”,Alexa 就会响应 'Welcome to the world of 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
您好,我已经创建了一个 lambda 函数,它可以使用主键从我的 dynamodb table 中调用项目。
这是我的代码
'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 查询我的 table
谁能帮我解决这个问题?我创建了一项技能并将其全部链接起来但不确定如何建立我的交互模型
感谢
这是我的意图架构
{
"intents": [
{
"intent": "date"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "Cinema"
},
{
"intent": "MyIntent"
}
]
}
请按照以下步骤操作,
- 转到https://developer.amazon.com/
- 使用您的帐户登录
- 点击 Alexa
- 点击'Add new Skills'
- 填写 'Skill information' 和 'Interaction Model' 部分
- 在 'Configuration' 部分提到您的 Lambda ARN,如下所示,
请将下面的代码复制到您的 Lambda 函数中,只需说“打开 'YOUR SKILL NAME'”,Alexa 就会响应 'Welcome to the world of 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