2

I have this lambda below that gets items from DynamoDB and returns it to connect just fine... however, I cannot seem to get the inputTranscript over. Is there a way I could implement this in my current lambda so that Connect can access it? I am seriously stumped on this, as everything I have tried in the documentation has not worked for me.

const AWS = require("aws-sdk");
const dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context, callback) {
  console.log(`DEBUG:\t Event`, JSON.stringify(event, null, 4));

  var params = {
    Key: {
      "name": {
        "S": '"' + event.slots.list + '"'
      }
    },
    TableName: 'ServiceOfferings'
  };

  dynamodb.getItem(params, function(err, data) {
    if (err) { 
        console.log("ERROR:\t", err);
        callback(err);
    } else { 
        console.log(data);
        if (data.Item) {
          console.log('data returned from DynamoDB ', JSON.stringify(data));
          callback(null, {
            ServiceOffering: data.Item.name.S.slice(1, -1)
          });
        }
        else {
          console.log("no callback number found for intent");
          callback(new Error("no callback number found for intent"));
        }
    }
  });
};

The test instance I use to ensure the lambda works correctly is as follows:

{
  "dialog-state": "ReadyForFulfillment",
  "input-transcript": "my printer is not working",
  "slots": {
    "list": "Re-IP Project - Printers"
  },
  "intent-name": "getServiceOffering"
}

The response after Testing this comes out to:

{
  "ServiceOffering": "Re-IP Project - Printers"
}
JustinMc
  • 41
  • 3

1 Answers1

2

When you log the event, you should be able to see the inputTranscript being passed to your Lambda. So you simply need to take it out of the event and do with it what you want.

const AWS = require("aws-sdk");
const dynamodb = new AWS.DynamoDB();
exports.handler = function(event, context, callback) {
  console.log(`DEBUG:\t Event`, JSON.stringify(event, null, 4));
  var inputTranscript = event.inputTranscript

     ...

      callback(null, {
        ServiceOffering: data.Item.name.S.slice(1, -1),
        inputTranscript: inputTranscript   
      });

That includes the inputTranscript in your callback to Connect (I assume), and you can use the Set Attribute block to save and handle the input within Connect.

Jay A. Little
  • 3,239
  • 2
  • 11
  • 32