Consuming the Genesys Cloud EventBridge events in an Azure Function. Specifically looking at v2.analytics.conversation.aggregate. The JSON structure is deeply nested and the property names use dots, which makes standard C# JsonSerializer deserialization a pain.
Here is a snippet of the payload coming through:
{
"data": {
"event_id": "a1b2c3d4-...",
"event_type": "v2.analytics.conversation.aggregate",
"payload": {
"conversationId": "98765432-...",
"conversationType": "voice",
"segments": [
{
"segmentId": "seg-123",
"startTime": "2023-10-27T14:30:00Z",
"endTime": "2023-10-27T14:35:00Z",
"metrics": {
"talkTime": 120.5,
"holdTime": 30.0
}
}
]
}
}
}
Trying to map this to a C# class hierarchy. The docs mention:
“Events are delivered as JSON objects with a standardized envelope.”
But they don’t give a C# example for the aggregate event. When I try to deserialize payload.segments[0].metrics.talkTime, I’m getting nulls because I’m not sure how to handle the dynamic nesting or if there’s a specific SDK helper I’m missing.
Currently using System.Text.Json. Should I be using JsonElement to navigate the tree manually, or is there a clean POCO approach that handles the payload wrapper correctly? The payload object seems to vary based on event type, so hardcoding classes feels wrong, but JObject from Newtonsoft is slow in the function execution model.
Any pointers on the best pattern for this in .NET 8?