How to get a specific item from DynamoDB table using NodeJs for alexa skill developmentIs there a way to get version from package.json in nodejs code?developing and testing alexa skill (with authorization)Alexa-Skill Monetization possibilities for developersStarting Alexa Skill in a specific stateAlexa Node.js skill not getting into intentRead from DynamoDB with Lambda nodejs for Alexa SkillScanning DynamoDB table not showing results from the column specified in ProjectionExpressionadding alexa skill session attributes from nodejsalexa skill local could not write to dynamodb

What are some bad ways to subvert tropes?

Can one block with a protection from color creature?

Will Jimmy fall off his platform?

How do ballistic trajectories work in a ring world?

Can a USB hub be used to access a drive from two devices?

Computer name naming convention for security

How do I talk to my wife about unrealistic expectations?

What's the big deal about the Nazgûl losing their horses?

Who goes first? Person disembarking bus or the bicycle?

Why no parachutes in the Orion AA2 abort test?

Taking my Ph.D. advisor out for dinner after graduation

Wouldn't putting an electronic key inside a small Faraday cage render it completely useless?

My professor has told me he will be the corresponding author. Will it hurt my future career?

How does the cloaker's Phantasms action work?

What exactly is a "murder hobo"?

Can you create a free-floating MASYU puzzle?

Which is a better conductor, a very thick rubber wire or a very thin copper wire?

How can I review my manager, who is fine?

How can I use my cell phone's light as a reading light?

Chilling juice in copper vessel

How to say "is going" in Russian in "this game is going to perish"

How to have a filled pattern

Is conquering your neighbors to fight a greater enemy a valid strategy?

Why do people prefer metropolitan areas, considering monsters and villains?



How to get a specific item from DynamoDB table using NodeJs for alexa skill development


Is there a way to get version from package.json in nodejs code?developing and testing alexa skill (with authorization)Alexa-Skill Monetization possibilities for developersStarting Alexa Skill in a specific stateAlexa Node.js skill not getting into intentRead from DynamoDB with Lambda nodejs for Alexa SkillScanning DynamoDB table not showing results from the column specified in ProjectionExpressionadding alexa skill session attributes from nodejsalexa skill local could not write to dynamodb






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I've been trying to develop a skill in Alexa that can store data in amazon DynamoDB Table. For now i'm able to add data (i.e. an item name) along with an attribute (i.e. item location) into the DynamoDB table using voice commands, i'm also able to remove a specific item from the table. But now I want alexa to get a specific item along with its attribute (location) from the Table whenever i say Alexa get itemName.



I have created two separate files index.js to handle with the intent requests and DbHelper.js to pass the parameters to the table. I've included the code in both the files below.
i am using AWS Lambda function to host my skill's endpoint and using NodeJs to code the lambda function.



I've tried using different query options included in aws-sdk like docClient.get, docClient.scan and docClient.query, but since i'm new to this all i was able to do is to get all the items from the table not a specific item.



I expect to get a specific item from the table but i get all the items that are present in the table.






/* ```````````````Index.js```````````````*/

const Alexa = require('ask-sdk');
const dbHelper = require('./helpers/dbHelper');
const GENERAL_REPROMPT = "What would you like to do?";
const dynamoDBTableName = "FORGETABLE_THINGS";
const LaunchRequestHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
,
handle(handlerInput)
const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
const repromptText = 'What would you like to do? You can say HELP to get available options';

return handlerInput.responseBuilder
.speak(speechText)
.reprompt(repromptText)
.getResponse();
,
;

const InProgressAddItemIntentHandler =
canHandle(handlerInput)
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'AddItemIntent' &&
request.dialogState !== 'COMPLETED';
,
handle(handlerInput)
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();



const AddItemIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
,
async handle(handlerInput)
const responseBuilder = handlerInput;
const userID = handlerInput.requestEnvelope.context.System.user.userId;
const slots = handlerInput.requestEnvelope.request.intent.slots;
const itemValue = slots.itemValue.value;
const location = slots.location.value;
return dbHelper.addItem(itemValue, location, userID)
.then((data) =>
const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
)
.catch((err) =>
console.log("Error occured while saving it", err);
const speechText = "we cannot save your item right now. Try again!"
return responseBuilder
.speak(speechText)
.getResponse();
)
,
;

const GetItemIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
,
async handle(handlerInput)
const responseBuilder = handlerInput;
//const userID = handlerInput.requestEnvelope.context.System.user.userId;
const itemName= slots.itemValue.value;
return dbHelper.getItem(itemName)
.then((data) =>
var speechText = "Your items are "
if (data.length == 0)
speechText = "You do not have any favourite item yet, add item by saying add itemname "
else
const datas = data.map(e => e.itemName + " " + e.Location);
speechText += datas.join(" ,")

return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
)
.catch((err) =>
const speechText = "we cannot get your item right now. Try again!"
return responseBuilder
.speak(speechText)
.getResponse();
)



const InProgressRemoveItemIntentHandler =
canHandle(handlerInput)
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' &&
request.intent.name === 'RemoveItemIntent' &&
request.dialogState !== 'COMPLETED';
,
handle(handlerInput)
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();



const RemoveItemIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
,
handle(handlerInput)
const responseBuilder = handlerInput;
const userID = handlerInput.requestEnvelope.context.System.user.userId;
const slots = handlerInput.requestEnvelope.request.intent.slots;
const itemValue = slots.itemValue.value;
return dbHelper.removeItem(itemValue, userID)
.then((data) =>
const speechText = `You have removed item with name $itemValue you can add another one by saying add`
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
)
.catch((err) =>
const speechText = `You do not have item with name $itemValue, you can add it by saying add`
return responseBuilder
.speak(speechText)
.reprompt(GENERAL_REPROMPT)
.getResponse();
)



const HelpIntentHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
,
handle(handlerInput)
const speechText = 'You can introduce yourself by telling me your name';

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'
,
handle(handlerInput)
const speechText = 'Goodbye!';

return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
,
;

const SessionEndedRequestHandler =
canHandle(handlerInput)
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
,
handle(handlerInput)
console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

return handlerInput.responseBuilder.getResponse();
,
;

const ErrorHandler =
canHandle()
return true;
,
handle(handlerInput, error)
console.log(`Error handled: $error.message`);

return handlerInput.responseBuilder
.speak('Sorry, I can't understand the command. Please say again.')
.reprompt('Sorry, I can't understand the command. Please say again.')
.getResponse();
,
;

const skillBuilder = Alexa.SkillBuilders.standard();

exports.handler = skillBuilder
.addRequestHandlers(
LaunchRequestHandler,
InProgressAddItemIntentHandler,
AddItemIntentHandler,
GetItemIntentHandler,
InProgressRemoveItemIntentHandler,
RemoveItemIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.withTableName(dynamoDBTableName)
.withAutoCreateTable(true)
.lambda();








/*```````````dbHelper.js`````````````*/
var AWS = require("aws-sdk");
AWS.config.update(
region: "us-east-1"
);
const tableName = "FORGETABLE_THINGS";

var dbHelper = function() ;
var docClient = new AWS.DynamoDB.DocumentClient();

dbHelper.prototype.addItem = (item, location, userID) =>
return new Promise((resolve, reject) =>
const params =
TableName: tableName,
Item:
'itemName': item,
'Location': location,
'userId': userID,


;
docClient.put(params, (err, data) =>
if (err)
console.log("Unable to insert =>", JSON.stringify(err))
return reject("Unable to insert");

console.log("Saved Data, ", JSON.stringify(data));
resolve(data);
);
);


dbHelper.prototype.getItem = (userID) =>
return new Promise((resolve, reject) =>
const params =
TableName: tableName,
KeyConditionExpression: "#userID = :user_id",
ExpressionAttributeNames:
"#userID": "userId"
"itemName": "itemName"
,
ExpressionAttributeValues:
":user_id": userID



docClient.query(params, (err, data) =>
if (err)
console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
return reject(JSON.stringify(err, null, 2))

console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
resolve(data.Items)

)
);


dbHelper.prototype.removeItem = (item, userID) =>
return new Promise((resolve, reject) =>
const params =
TableName: tableName,
Key:
"userId": userID,
"itemName": item
,
ConditionExpression: "attribute_exists(itemName)"

docClient.delete(params, function(err, data)
if (err)
console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
return reject(JSON.stringify(err, null, 2));

console.log(JSON.stringify(err));
console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
resolve();
)
);
;

module.exports = new dbHelper();












share|improve this question




























    0















    I've been trying to develop a skill in Alexa that can store data in amazon DynamoDB Table. For now i'm able to add data (i.e. an item name) along with an attribute (i.e. item location) into the DynamoDB table using voice commands, i'm also able to remove a specific item from the table. But now I want alexa to get a specific item along with its attribute (location) from the Table whenever i say Alexa get itemName.



    I have created two separate files index.js to handle with the intent requests and DbHelper.js to pass the parameters to the table. I've included the code in both the files below.
    i am using AWS Lambda function to host my skill's endpoint and using NodeJs to code the lambda function.



    I've tried using different query options included in aws-sdk like docClient.get, docClient.scan and docClient.query, but since i'm new to this all i was able to do is to get all the items from the table not a specific item.



    I expect to get a specific item from the table but i get all the items that are present in the table.






    /* ```````````````Index.js```````````````*/

    const Alexa = require('ask-sdk');
    const dbHelper = require('./helpers/dbHelper');
    const GENERAL_REPROMPT = "What would you like to do?";
    const dynamoDBTableName = "FORGETABLE_THINGS";
    const LaunchRequestHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
    ,
    handle(handlerInput)
    const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
    const repromptText = 'What would you like to do? You can say HELP to get available options';

    return handlerInput.responseBuilder
    .speak(speechText)
    .reprompt(repromptText)
    .getResponse();
    ,
    ;

    const InProgressAddItemIntentHandler =
    canHandle(handlerInput)
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest' &&
    request.intent.name === 'AddItemIntent' &&
    request.dialogState !== 'COMPLETED';
    ,
    handle(handlerInput)
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    return handlerInput.responseBuilder
    .addDelegateDirective(currentIntent)
    .getResponse();



    const AddItemIntentHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
    && handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
    ,
    async handle(handlerInput)
    const responseBuilder = handlerInput;
    const userID = handlerInput.requestEnvelope.context.System.user.userId;
    const slots = handlerInput.requestEnvelope.request.intent.slots;
    const itemValue = slots.itemValue.value;
    const location = slots.location.value;
    return dbHelper.addItem(itemValue, location, userID)
    .then((data) =>
    const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
    return responseBuilder
    .speak(speechText)
    .reprompt(GENERAL_REPROMPT)
    .getResponse();
    )
    .catch((err) =>
    console.log("Error occured while saving it", err);
    const speechText = "we cannot save your item right now. Try again!"
    return responseBuilder
    .speak(speechText)
    .getResponse();
    )
    ,
    ;

    const GetItemIntentHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
    && handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
    ,
    async handle(handlerInput)
    const responseBuilder = handlerInput;
    //const userID = handlerInput.requestEnvelope.context.System.user.userId;
    const itemName= slots.itemValue.value;
    return dbHelper.getItem(itemName)
    .then((data) =>
    var speechText = "Your items are "
    if (data.length == 0)
    speechText = "You do not have any favourite item yet, add item by saying add itemname "
    else
    const datas = data.map(e => e.itemName + " " + e.Location);
    speechText += datas.join(" ,")

    return responseBuilder
    .speak(speechText)
    .reprompt(GENERAL_REPROMPT)
    .getResponse();
    )
    .catch((err) =>
    const speechText = "we cannot get your item right now. Try again!"
    return responseBuilder
    .speak(speechText)
    .getResponse();
    )



    const InProgressRemoveItemIntentHandler =
    canHandle(handlerInput)
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest' &&
    request.intent.name === 'RemoveItemIntent' &&
    request.dialogState !== 'COMPLETED';
    ,
    handle(handlerInput)
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    return handlerInput.responseBuilder
    .addDelegateDirective(currentIntent)
    .getResponse();



    const RemoveItemIntentHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
    && handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
    ,
    handle(handlerInput)
    const responseBuilder = handlerInput;
    const userID = handlerInput.requestEnvelope.context.System.user.userId;
    const slots = handlerInput.requestEnvelope.request.intent.slots;
    const itemValue = slots.itemValue.value;
    return dbHelper.removeItem(itemValue, userID)
    .then((data) =>
    const speechText = `You have removed item with name $itemValue you can add another one by saying add`
    return responseBuilder
    .speak(speechText)
    .reprompt(GENERAL_REPROMPT)
    .getResponse();
    )
    .catch((err) =>
    const speechText = `You do not have item with name $itemValue, you can add it by saying add`
    return responseBuilder
    .speak(speechText)
    .reprompt(GENERAL_REPROMPT)
    .getResponse();
    )



    const HelpIntentHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
    && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
    ,
    handle(handlerInput)
    const speechText = 'You can introduce yourself by telling me your name';

    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'
    ,
    handle(handlerInput)
    const speechText = 'Goodbye!';

    return handlerInput.responseBuilder
    .speak(speechText)
    .getResponse();
    ,
    ;

    const SessionEndedRequestHandler =
    canHandle(handlerInput)
    return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
    ,
    handle(handlerInput)
    console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

    return handlerInput.responseBuilder.getResponse();
    ,
    ;

    const ErrorHandler =
    canHandle()
    return true;
    ,
    handle(handlerInput, error)
    console.log(`Error handled: $error.message`);

    return handlerInput.responseBuilder
    .speak('Sorry, I can't understand the command. Please say again.')
    .reprompt('Sorry, I can't understand the command. Please say again.')
    .getResponse();
    ,
    ;

    const skillBuilder = Alexa.SkillBuilders.standard();

    exports.handler = skillBuilder
    .addRequestHandlers(
    LaunchRequestHandler,
    InProgressAddItemIntentHandler,
    AddItemIntentHandler,
    GetItemIntentHandler,
    InProgressRemoveItemIntentHandler,
    RemoveItemIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
    )
    .addErrorHandlers(ErrorHandler)
    .withTableName(dynamoDBTableName)
    .withAutoCreateTable(true)
    .lambda();








    /*```````````dbHelper.js`````````````*/
    var AWS = require("aws-sdk");
    AWS.config.update(
    region: "us-east-1"
    );
    const tableName = "FORGETABLE_THINGS";

    var dbHelper = function() ;
    var docClient = new AWS.DynamoDB.DocumentClient();

    dbHelper.prototype.addItem = (item, location, userID) =>
    return new Promise((resolve, reject) =>
    const params =
    TableName: tableName,
    Item:
    'itemName': item,
    'Location': location,
    'userId': userID,


    ;
    docClient.put(params, (err, data) =>
    if (err)
    console.log("Unable to insert =>", JSON.stringify(err))
    return reject("Unable to insert");

    console.log("Saved Data, ", JSON.stringify(data));
    resolve(data);
    );
    );


    dbHelper.prototype.getItem = (userID) =>
    return new Promise((resolve, reject) =>
    const params =
    TableName: tableName,
    KeyConditionExpression: "#userID = :user_id",
    ExpressionAttributeNames:
    "#userID": "userId"
    "itemName": "itemName"
    ,
    ExpressionAttributeValues:
    ":user_id": userID



    docClient.query(params, (err, data) =>
    if (err)
    console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
    return reject(JSON.stringify(err, null, 2))

    console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    resolve(data.Items)

    )
    );


    dbHelper.prototype.removeItem = (item, userID) =>
    return new Promise((resolve, reject) =>
    const params =
    TableName: tableName,
    Key:
    "userId": userID,
    "itemName": item
    ,
    ConditionExpression: "attribute_exists(itemName)"

    docClient.delete(params, function(err, data)
    if (err)
    console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
    return reject(JSON.stringify(err, null, 2));

    console.log(JSON.stringify(err));
    console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
    resolve();
    )
    );
    ;

    module.exports = new dbHelper();












    share|improve this question
























      0












      0








      0


      2






      I've been trying to develop a skill in Alexa that can store data in amazon DynamoDB Table. For now i'm able to add data (i.e. an item name) along with an attribute (i.e. item location) into the DynamoDB table using voice commands, i'm also able to remove a specific item from the table. But now I want alexa to get a specific item along with its attribute (location) from the Table whenever i say Alexa get itemName.



      I have created two separate files index.js to handle with the intent requests and DbHelper.js to pass the parameters to the table. I've included the code in both the files below.
      i am using AWS Lambda function to host my skill's endpoint and using NodeJs to code the lambda function.



      I've tried using different query options included in aws-sdk like docClient.get, docClient.scan and docClient.query, but since i'm new to this all i was able to do is to get all the items from the table not a specific item.



      I expect to get a specific item from the table but i get all the items that are present in the table.






      /* ```````````````Index.js```````````````*/

      const Alexa = require('ask-sdk');
      const dbHelper = require('./helpers/dbHelper');
      const GENERAL_REPROMPT = "What would you like to do?";
      const dynamoDBTableName = "FORGETABLE_THINGS";
      const LaunchRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
      ,
      handle(handlerInput)
      const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
      const repromptText = 'What would you like to do? You can say HELP to get available options';

      return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .getResponse();
      ,
      ;

      const InProgressAddItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'AddItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const AddItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      const location = slots.location.value;
      return dbHelper.addItem(itemValue, location, userID)
      .then((data) =>
      const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      console.log("Error occured while saving it", err);
      const speechText = "we cannot save your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )
      ,
      ;

      const GetItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      //const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const itemName= slots.itemValue.value;
      return dbHelper.getItem(itemName)
      .then((data) =>
      var speechText = "Your items are "
      if (data.length == 0)
      speechText = "You do not have any favourite item yet, add item by saying add itemname "
      else
      const datas = data.map(e => e.itemName + " " + e.Location);
      speechText += datas.join(" ,")

      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = "we cannot get your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )



      const InProgressRemoveItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'RemoveItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const RemoveItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
      ,
      handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      return dbHelper.removeItem(itemValue, userID)
      .then((data) =>
      const speechText = `You have removed item with name $itemValue you can add another one by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = `You do not have item with name $itemValue, you can add it by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )



      const HelpIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
      ,
      handle(handlerInput)
      const speechText = 'You can introduce yourself by telling me your name';

      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'
      ,
      handle(handlerInput)
      const speechText = 'Goodbye!';

      return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
      ,
      ;

      const SessionEndedRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
      ,
      handle(handlerInput)
      console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

      return handlerInput.responseBuilder.getResponse();
      ,
      ;

      const ErrorHandler =
      canHandle()
      return true;
      ,
      handle(handlerInput, error)
      console.log(`Error handled: $error.message`);

      return handlerInput.responseBuilder
      .speak('Sorry, I can't understand the command. Please say again.')
      .reprompt('Sorry, I can't understand the command. Please say again.')
      .getResponse();
      ,
      ;

      const skillBuilder = Alexa.SkillBuilders.standard();

      exports.handler = skillBuilder
      .addRequestHandlers(
      LaunchRequestHandler,
      InProgressAddItemIntentHandler,
      AddItemIntentHandler,
      GetItemIntentHandler,
      InProgressRemoveItemIntentHandler,
      RemoveItemIntentHandler,
      HelpIntentHandler,
      CancelAndStopIntentHandler,
      SessionEndedRequestHandler
      )
      .addErrorHandlers(ErrorHandler)
      .withTableName(dynamoDBTableName)
      .withAutoCreateTable(true)
      .lambda();








      /*```````````dbHelper.js`````````````*/
      var AWS = require("aws-sdk");
      AWS.config.update(
      region: "us-east-1"
      );
      const tableName = "FORGETABLE_THINGS";

      var dbHelper = function() ;
      var docClient = new AWS.DynamoDB.DocumentClient();

      dbHelper.prototype.addItem = (item, location, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Item:
      'itemName': item,
      'Location': location,
      'userId': userID,


      ;
      docClient.put(params, (err, data) =>
      if (err)
      console.log("Unable to insert =>", JSON.stringify(err))
      return reject("Unable to insert");

      console.log("Saved Data, ", JSON.stringify(data));
      resolve(data);
      );
      );


      dbHelper.prototype.getItem = (userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      KeyConditionExpression: "#userID = :user_id",
      ExpressionAttributeNames:
      "#userID": "userId"
      "itemName": "itemName"
      ,
      ExpressionAttributeValues:
      ":user_id": userID



      docClient.query(params, (err, data) =>
      if (err)
      console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2))

      console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
      resolve(data.Items)

      )
      );


      dbHelper.prototype.removeItem = (item, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Key:
      "userId": userID,
      "itemName": item
      ,
      ConditionExpression: "attribute_exists(itemName)"

      docClient.delete(params, function(err, data)
      if (err)
      console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2));

      console.log(JSON.stringify(err));
      console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
      resolve();
      )
      );
      ;

      module.exports = new dbHelper();












      share|improve this question














      I've been trying to develop a skill in Alexa that can store data in amazon DynamoDB Table. For now i'm able to add data (i.e. an item name) along with an attribute (i.e. item location) into the DynamoDB table using voice commands, i'm also able to remove a specific item from the table. But now I want alexa to get a specific item along with its attribute (location) from the Table whenever i say Alexa get itemName.



      I have created two separate files index.js to handle with the intent requests and DbHelper.js to pass the parameters to the table. I've included the code in both the files below.
      i am using AWS Lambda function to host my skill's endpoint and using NodeJs to code the lambda function.



      I've tried using different query options included in aws-sdk like docClient.get, docClient.scan and docClient.query, but since i'm new to this all i was able to do is to get all the items from the table not a specific item.



      I expect to get a specific item from the table but i get all the items that are present in the table.






      /* ```````````````Index.js```````````````*/

      const Alexa = require('ask-sdk');
      const dbHelper = require('./helpers/dbHelper');
      const GENERAL_REPROMPT = "What would you like to do?";
      const dynamoDBTableName = "FORGETABLE_THINGS";
      const LaunchRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
      ,
      handle(handlerInput)
      const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
      const repromptText = 'What would you like to do? You can say HELP to get available options';

      return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .getResponse();
      ,
      ;

      const InProgressAddItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'AddItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const AddItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      const location = slots.location.value;
      return dbHelper.addItem(itemValue, location, userID)
      .then((data) =>
      const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      console.log("Error occured while saving it", err);
      const speechText = "we cannot save your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )
      ,
      ;

      const GetItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      //const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const itemName= slots.itemValue.value;
      return dbHelper.getItem(itemName)
      .then((data) =>
      var speechText = "Your items are "
      if (data.length == 0)
      speechText = "You do not have any favourite item yet, add item by saying add itemname "
      else
      const datas = data.map(e => e.itemName + " " + e.Location);
      speechText += datas.join(" ,")

      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = "we cannot get your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )



      const InProgressRemoveItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'RemoveItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const RemoveItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
      ,
      handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      return dbHelper.removeItem(itemValue, userID)
      .then((data) =>
      const speechText = `You have removed item with name $itemValue you can add another one by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = `You do not have item with name $itemValue, you can add it by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )



      const HelpIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
      ,
      handle(handlerInput)
      const speechText = 'You can introduce yourself by telling me your name';

      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'
      ,
      handle(handlerInput)
      const speechText = 'Goodbye!';

      return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
      ,
      ;

      const SessionEndedRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
      ,
      handle(handlerInput)
      console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

      return handlerInput.responseBuilder.getResponse();
      ,
      ;

      const ErrorHandler =
      canHandle()
      return true;
      ,
      handle(handlerInput, error)
      console.log(`Error handled: $error.message`);

      return handlerInput.responseBuilder
      .speak('Sorry, I can't understand the command. Please say again.')
      .reprompt('Sorry, I can't understand the command. Please say again.')
      .getResponse();
      ,
      ;

      const skillBuilder = Alexa.SkillBuilders.standard();

      exports.handler = skillBuilder
      .addRequestHandlers(
      LaunchRequestHandler,
      InProgressAddItemIntentHandler,
      AddItemIntentHandler,
      GetItemIntentHandler,
      InProgressRemoveItemIntentHandler,
      RemoveItemIntentHandler,
      HelpIntentHandler,
      CancelAndStopIntentHandler,
      SessionEndedRequestHandler
      )
      .addErrorHandlers(ErrorHandler)
      .withTableName(dynamoDBTableName)
      .withAutoCreateTable(true)
      .lambda();








      /*```````````dbHelper.js`````````````*/
      var AWS = require("aws-sdk");
      AWS.config.update(
      region: "us-east-1"
      );
      const tableName = "FORGETABLE_THINGS";

      var dbHelper = function() ;
      var docClient = new AWS.DynamoDB.DocumentClient();

      dbHelper.prototype.addItem = (item, location, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Item:
      'itemName': item,
      'Location': location,
      'userId': userID,


      ;
      docClient.put(params, (err, data) =>
      if (err)
      console.log("Unable to insert =>", JSON.stringify(err))
      return reject("Unable to insert");

      console.log("Saved Data, ", JSON.stringify(data));
      resolve(data);
      );
      );


      dbHelper.prototype.getItem = (userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      KeyConditionExpression: "#userID = :user_id",
      ExpressionAttributeNames:
      "#userID": "userId"
      "itemName": "itemName"
      ,
      ExpressionAttributeValues:
      ":user_id": userID



      docClient.query(params, (err, data) =>
      if (err)
      console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2))

      console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
      resolve(data.Items)

      )
      );


      dbHelper.prototype.removeItem = (item, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Key:
      "userId": userID,
      "itemName": item
      ,
      ConditionExpression: "attribute_exists(itemName)"

      docClient.delete(params, function(err, data)
      if (err)
      console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2));

      console.log(JSON.stringify(err));
      console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
      resolve();
      )
      );
      ;

      module.exports = new dbHelper();








      /* ```````````````Index.js```````````````*/

      const Alexa = require('ask-sdk');
      const dbHelper = require('./helpers/dbHelper');
      const GENERAL_REPROMPT = "What would you like to do?";
      const dynamoDBTableName = "FORGETABLE_THINGS";
      const LaunchRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
      ,
      handle(handlerInput)
      const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
      const repromptText = 'What would you like to do? You can say HELP to get available options';

      return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .getResponse();
      ,
      ;

      const InProgressAddItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'AddItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const AddItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      const location = slots.location.value;
      return dbHelper.addItem(itemValue, location, userID)
      .then((data) =>
      const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      console.log("Error occured while saving it", err);
      const speechText = "we cannot save your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )
      ,
      ;

      const GetItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      //const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const itemName= slots.itemValue.value;
      return dbHelper.getItem(itemName)
      .then((data) =>
      var speechText = "Your items are "
      if (data.length == 0)
      speechText = "You do not have any favourite item yet, add item by saying add itemname "
      else
      const datas = data.map(e => e.itemName + " " + e.Location);
      speechText += datas.join(" ,")

      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = "we cannot get your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )



      const InProgressRemoveItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'RemoveItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const RemoveItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
      ,
      handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      return dbHelper.removeItem(itemValue, userID)
      .then((data) =>
      const speechText = `You have removed item with name $itemValue you can add another one by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = `You do not have item with name $itemValue, you can add it by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )



      const HelpIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
      ,
      handle(handlerInput)
      const speechText = 'You can introduce yourself by telling me your name';

      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'
      ,
      handle(handlerInput)
      const speechText = 'Goodbye!';

      return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
      ,
      ;

      const SessionEndedRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
      ,
      handle(handlerInput)
      console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

      return handlerInput.responseBuilder.getResponse();
      ,
      ;

      const ErrorHandler =
      canHandle()
      return true;
      ,
      handle(handlerInput, error)
      console.log(`Error handled: $error.message`);

      return handlerInput.responseBuilder
      .speak('Sorry, I can't understand the command. Please say again.')
      .reprompt('Sorry, I can't understand the command. Please say again.')
      .getResponse();
      ,
      ;

      const skillBuilder = Alexa.SkillBuilders.standard();

      exports.handler = skillBuilder
      .addRequestHandlers(
      LaunchRequestHandler,
      InProgressAddItemIntentHandler,
      AddItemIntentHandler,
      GetItemIntentHandler,
      InProgressRemoveItemIntentHandler,
      RemoveItemIntentHandler,
      HelpIntentHandler,
      CancelAndStopIntentHandler,
      SessionEndedRequestHandler
      )
      .addErrorHandlers(ErrorHandler)
      .withTableName(dynamoDBTableName)
      .withAutoCreateTable(true)
      .lambda();





      /* ```````````````Index.js```````````````*/

      const Alexa = require('ask-sdk');
      const dbHelper = require('./helpers/dbHelper');
      const GENERAL_REPROMPT = "What would you like to do?";
      const dynamoDBTableName = "FORGETABLE_THINGS";
      const LaunchRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
      ,
      handle(handlerInput)
      const speechText = 'Hello there. What is your favourite thing? You can say add itemname to add your item or say get to get your items.';
      const repromptText = 'What would you like to do? You can say HELP to get available options';

      return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .getResponse();
      ,
      ;

      const InProgressAddItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'AddItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const AddItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AddItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      const location = slots.location.value;
      return dbHelper.addItem(itemValue, location, userID)
      .then((data) =>
      const speechText = `You have added $itemValue, placed at $location. You can say add to add another one or remove to remove item`;
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      console.log("Error occured while saving it", err);
      const speechText = "we cannot save your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )
      ,
      ;

      const GetItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetItemIntent';
      ,
      async handle(handlerInput)
      const responseBuilder = handlerInput;
      //const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const itemName= slots.itemValue.value;
      return dbHelper.getItem(itemName)
      .then((data) =>
      var speechText = "Your items are "
      if (data.length == 0)
      speechText = "You do not have any favourite item yet, add item by saying add itemname "
      else
      const datas = data.map(e => e.itemName + " " + e.Location);
      speechText += datas.join(" ,")

      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = "we cannot get your item right now. Try again!"
      return responseBuilder
      .speak(speechText)
      .getResponse();
      )



      const InProgressRemoveItemIntentHandler =
      canHandle(handlerInput)
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest' &&
      request.intent.name === 'RemoveItemIntent' &&
      request.dialogState !== 'COMPLETED';
      ,
      handle(handlerInput)
      const currentIntent = handlerInput.requestEnvelope.request.intent;
      return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();



      const RemoveItemIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'RemoveItemIntent';
      ,
      handle(handlerInput)
      const responseBuilder = handlerInput;
      const userID = handlerInput.requestEnvelope.context.System.user.userId;
      const slots = handlerInput.requestEnvelope.request.intent.slots;
      const itemValue = slots.itemValue.value;
      return dbHelper.removeItem(itemValue, userID)
      .then((data) =>
      const speechText = `You have removed item with name $itemValue you can add another one by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )
      .catch((err) =>
      const speechText = `You do not have item with name $itemValue, you can add it by saying add`
      return responseBuilder
      .speak(speechText)
      .reprompt(GENERAL_REPROMPT)
      .getResponse();
      )



      const HelpIntentHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
      ,
      handle(handlerInput)
      const speechText = 'You can introduce yourself by telling me your name';

      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'
      ,
      handle(handlerInput)
      const speechText = 'Goodbye!';

      return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
      ,
      ;

      const SessionEndedRequestHandler =
      canHandle(handlerInput)
      return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
      ,
      handle(handlerInput)
      console.log(`Session ended with reason: $handlerInput.requestEnvelope.request.reason`);

      return handlerInput.responseBuilder.getResponse();
      ,
      ;

      const ErrorHandler =
      canHandle()
      return true;
      ,
      handle(handlerInput, error)
      console.log(`Error handled: $error.message`);

      return handlerInput.responseBuilder
      .speak('Sorry, I can't understand the command. Please say again.')
      .reprompt('Sorry, I can't understand the command. Please say again.')
      .getResponse();
      ,
      ;

      const skillBuilder = Alexa.SkillBuilders.standard();

      exports.handler = skillBuilder
      .addRequestHandlers(
      LaunchRequestHandler,
      InProgressAddItemIntentHandler,
      AddItemIntentHandler,
      GetItemIntentHandler,
      InProgressRemoveItemIntentHandler,
      RemoveItemIntentHandler,
      HelpIntentHandler,
      CancelAndStopIntentHandler,
      SessionEndedRequestHandler
      )
      .addErrorHandlers(ErrorHandler)
      .withTableName(dynamoDBTableName)
      .withAutoCreateTable(true)
      .lambda();





      /*```````````dbHelper.js`````````````*/
      var AWS = require("aws-sdk");
      AWS.config.update(
      region: "us-east-1"
      );
      const tableName = "FORGETABLE_THINGS";

      var dbHelper = function() ;
      var docClient = new AWS.DynamoDB.DocumentClient();

      dbHelper.prototype.addItem = (item, location, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Item:
      'itemName': item,
      'Location': location,
      'userId': userID,


      ;
      docClient.put(params, (err, data) =>
      if (err)
      console.log("Unable to insert =>", JSON.stringify(err))
      return reject("Unable to insert");

      console.log("Saved Data, ", JSON.stringify(data));
      resolve(data);
      );
      );


      dbHelper.prototype.getItem = (userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      KeyConditionExpression: "#userID = :user_id",
      ExpressionAttributeNames:
      "#userID": "userId"
      "itemName": "itemName"
      ,
      ExpressionAttributeValues:
      ":user_id": userID



      docClient.query(params, (err, data) =>
      if (err)
      console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2))

      console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
      resolve(data.Items)

      )
      );


      dbHelper.prototype.removeItem = (item, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Key:
      "userId": userID,
      "itemName": item
      ,
      ConditionExpression: "attribute_exists(itemName)"

      docClient.delete(params, function(err, data)
      if (err)
      console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2));

      console.log(JSON.stringify(err));
      console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
      resolve();
      )
      );
      ;

      module.exports = new dbHelper();





      /*```````````dbHelper.js`````````````*/
      var AWS = require("aws-sdk");
      AWS.config.update(
      region: "us-east-1"
      );
      const tableName = "FORGETABLE_THINGS";

      var dbHelper = function() ;
      var docClient = new AWS.DynamoDB.DocumentClient();

      dbHelper.prototype.addItem = (item, location, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Item:
      'itemName': item,
      'Location': location,
      'userId': userID,


      ;
      docClient.put(params, (err, data) =>
      if (err)
      console.log("Unable to insert =>", JSON.stringify(err))
      return reject("Unable to insert");

      console.log("Saved Data, ", JSON.stringify(data));
      resolve(data);
      );
      );


      dbHelper.prototype.getItem = (userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      KeyConditionExpression: "#userID = :user_id",
      ExpressionAttributeNames:
      "#userID": "userId"
      "itemName": "itemName"
      ,
      ExpressionAttributeValues:
      ":user_id": userID



      docClient.query(params, (err, data) =>
      if (err)
      console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2))

      console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
      resolve(data.Items)

      )
      );


      dbHelper.prototype.removeItem = (item, userID) =>
      return new Promise((resolve, reject) =>
      const params =
      TableName: tableName,
      Key:
      "userId": userID,
      "itemName": item
      ,
      ConditionExpression: "attribute_exists(itemName)"

      docClient.delete(params, function(err, data)
      if (err)
      console.error("Unable to delete item. Error JSON:", JSON.stringify(err, null, 2));
      return reject(JSON.stringify(err, null, 2));

      console.log(JSON.stringify(err));
      console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
      resolve();
      )
      );
      ;

      module.exports = new dbHelper();






      node.js amazon-web-services amazon-dynamodb alexa-skills-kit alexa-skill






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 25 at 21:07









      Ady YousfAdy Yousf

      33 bronze badges




      33 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346426%2fhow-to-get-a-specific-item-from-dynamodb-table-using-nodejs-for-alexa-skill-deve%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346426%2fhow-to-get-a-specific-item-from-dynamodb-table-using-nodejs-for-alexa-skill-deve%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript