'C# Lambda has different payload when called from Amazon Connect
I am new to C# and I have a lambda that works locally and when tested from the lambda console. My Lambda expects a payload that looks like this
{
"PhoneNum": "myphonenumber"
}
My class looks like this
public class PageParams
{
public string EmpId { get; set; }
public string PhoneNum { get; set; }
}
However, when my lambda is called from Amazon Connect my parameters are nested in an object that looks like this
{
"Details": {
"ContactData": {
"Attributes": {},
"Channel": "VOICE",
"ContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"CustomerEndpoint": {
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
},
"InitialContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"InitiationMethod": "INBOUND | OUTBOUND | TRANSFER | CALLBACK",
"InstanceARN": "arn:aws:connect:aws-region:1234567890:instance/c8c0e68d-2200-4265-82c0-XXXXXXXXXX",
"PreviousContactId": "4a573372-1f28-4e26-b97b-XXXXXXXXXXX",
"Queue": {
"ARN": "arn:aws:connect:eu-west-2:111111111111:instance/cccccccc-bbbb-dddd-eeee-ffffffffffff/queue/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"Name": "PasswordReset"
},
"SystemEndpoint": {
"Address": "+1234567890",
"Type": "TELEPHONE_NUMBER"
}
},
"Parameters": {
"PhoneNum": "myphonenumber"
}
},
"Name": "ContactFlowEvent"
}
I don't know how to handle having nested objects in my c# code. I am guessing I have to modify the class for PageParams to have a Details object with the Parameters object nested inside of it but I can't figure out how to write that and I can't find any example online of C# lambdas that are called from Connect.
How would I change my code to expect for the page parameters to be nested at PageParams.Details.Parameters?
Solution 1:[1]
I'm not familiar with AWS. Do they refer to this as lambda?
Anyway, the data you're getting back is JSON. You can create new classes in your code to represent it and then deserialize this response to create a new instance of that class. It'll actually be a couple of classes.
Easy way is to 'paste json as class' which is under 'paste special' in the Edit Menu.
Highly recommend using Newtonsoft.Json for this.
var result = JaonConvert.DeserializeObject<Details>(jsonString);
Solution 2:[2]
if you neeed just a phoneNum and an empId, you don't need any extra classes since you can get data this way
var jsonParced=JObject.Parse(json);
PageParams pageParams= jsonParsed["Parameters"].ToObject<PageParams>();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Acktually |
Solution 2 |