Unable to access return value of AWS Lambda (Typescript) in Contact Flow

79 Views Asked by At

Hope you are all doing well. I am reaching out to you all because I am having a problem with capturing a value that is returned from a Lambda in AWS. For now, I am just looking to capture the value and then add it as a contract attribute.

The purpose of the Lambda is to check if the caller phone number is in a DynamoDB table. I've tried a number of things to access the value and attach it as a contact attribute. Here are some of the things I've tried.

  1. I've tried to change the response validation between both, "String Map" and "JSON". I understand that in connect, "String Map" is the better way to return a value, but personally I'm much more familiar with JSON so that's what I've been looking to use. Additionally, it seems that when I try to use the, "String Map" validation response the Lambda returns an error.

The lambda right now is essentially taking in the value phone number and running a search on the Lambda table. Then obviously a simple if statement is being used to respond to the search.

Below you will find some information/artifacts that I believe will help you answer the question. The first one is the body of code of the lambda itself [A]. The second one is a couple of screen shots that demonstrate how the call flow is configured. There are a couple of things I would like to note:

1.) The lambda is functioning (except in the scenario described above) as expected, and this is confirmed in the logs.

    try {
        await DynamoDBObject.getItem(parameters, function(error, data){
            const twelveDaysUnix = 1036800
            const minimumCall = Number(data.Item.LastCall.N) - twelveDaysUnix
            if(between(dateFunctionality.getTime(), minimumCall, dateFunctionality.getTime())){
                returnValue.betweenDates = true
                event.Details.Parameters.PhoneNumberLambdaReturn = returnValue
                console.log("Console log of complete event: ",event)
                console.log("Console log of entered data: ", event.Details.Parameters.PhoneNumberLambdaReturn)
                return event
            } else {
                returnValue.betweenDates = false;
                return returnValue
            }

        }).promise()
    } catch (error){
        console.log("Catch block of try/catch")
        console.log(error.message)
        return error.message
    }

B.) Invoke AWS Lambda Function Block Photo: enter image description here Photo showing the invokation of "Set contact attribute" block. enter image description here

1

There are 1 best solutions below

0
On

The lambda returns the complete ‘event’ object instead of ‘event.Details.Parameters’ object. When using STRING MAP you must return a simple object with string keys and string values.