Reputation: 395
Hi i've created a lambda function that can recall items from my dynamodb table using the primary key.
here is the code i have
'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;
it works fine but now what i want to do is set it up to work with alexa so i can ask alexa to query my table
can anyone help me on how to do this? ive created a skill and had it all linked but not sure how to do my interaction model
thanks
here is my intent schema
{
"intents": [
{
"intent": "date"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "Cinema"
},
{
"intent": "MyIntent"
}
]
}
Upvotes: 1
Views: 692
Reputation: 8541
Please follow below steps,
Please copy below code as such to your Lambda function and just say 'Open 'YOUR SKILL NAME'' the Alexa should respond '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;
}
Please find one sample in my GitHub (not using Alexa SDK),
https://github.com/vnathv/alexa-myfortune/blob/master/MyFortune/Index.js
Upvotes: 2