service-cloud-voice / ServiceCloudVoiceLambdas

This application provides a set of Lambda functions, which are available within your Amazon Connect instance after provisioning the instance with your Service Cloud Voice contact center. You can use these Lambdas in Amazon Connect contact flows.
BSD 3-Clause "New" or "Revised" License
14 stars 18 forks source link

Support returning nested JSON instead of flattened data in REST API Lambda #68

Open alexhafner opened 4 months ago

alexhafner commented 4 months ago

The REST API Lambda would benefit from returning standard JSON. In the current release, the Flat library is used to return results that are potentially nested.

So for example, given a SOSL search query returning this result snippet

        "data": {
            "searchRecords": [
                {
                    "BillingCity": "Las Vegas",
                    "BillingCountryCode": "US",
                    "BillingPostalCode": "89119",
                    "BillingStateCode": "NV",
                    "Id": "001DC0000012345678",
                    "attributes": {
                        "type": "Account",
                        "url": "/services/data/v54.0/sobjects/Account/001DC0000012345678"
                    }
                },
                //...

currently requires the type to be accessed like this: ['attributes.type'] whereas you should be able to access it using normal dot notation when setting the Lambda Invocation Response Validation in the Contact flow to "JSON" instead of "STRING MAP" as described in the Amazon Connect Documentation and introduced in the March 2023 Release of Amazon Connect.

I assume the code in the Salesforce Service Cloud Voice REST API Lambda used flattening because this feature is relatively new and initially you had to work with STRING MAP validation; however JSON support has now been around over a year and is much more intuitive and powerful. I understand changing this is potentially a breaking change for some customers; however feature flags would easily be able to handle that. In addition, being able to handle arrays would be very useful - per the AWS docs this is currently only supported by forwarding the data to another Lambda; rather than direct use in the flow; but even that opens a number of important and powerful use cases.

Is support of JSON for Amazon Connect Lambda invocations for REST APIs already planned? If not please let me know how to best progress this - via this issue, an Idea, etc. Also happy to create a PR; however the version of the Service Cloud Voice Code in this repository is outdated as indicated in https://github.com/service-cloud-voice/ServiceCloudVoiceLambdas/issues/66

jinalkathiara commented 4 months ago

I agree with this feature and Salesforce team will evaluate and deliver this.