Hey everyone,
We’ve got a Node.js service listening to the v2.analytics.conversation.aggregate webhook endpoint. The goal is to calculate real-time wait times, but the payload structure is a bit maddening.
The intervals array inside the JSON is deeply nested. Here’s a snippet of what we’re seeing:
{
"id": "abc-123",
"intervals": [
{
"value": 45.2,
"startTime": "2023-10-27T10:00:00.000Z",
"endTime": "2023-10-27T10:05:00.000Z"
}
]
}
The problem is that value isn’t always what we expect. Sometimes it’s the count, sometimes it’s the wait time, depending on the metric field which seems to shift around in different aggregates. We’re trying to map these to a local DB, but the SDK doesn’t have a parser for this specific webhook shape.
Has anyone written a solid parser for this? Or is there a helper in the genesyscloud npm package I’m missing? We’re currently doing manual if checks on the metric type, but it feels brittle. The docs are pretty vague on the exact schema variations.
Any code examples for handling the metric discrimination would be great. We’re losing data because some intervals come back with null values when the metric switches.