Hey folks,
I’m trying to set up a simple webhook consumer to track some basic adherence metrics. The plan is to subscribe to the v2.analytics.conversation.aggregate event so we can log conversation stats without hitting the Analytics API constantly. I’ve got the webhook registered in Genesys Cloud and it’s firing correctly when agents wrap up calls.
The issue is parsing the payload. The JSON structure is deeper than I expected, and I’m struggling to extract the actual metric values like wrap-up time or talk time from the nested metrics object. I’ve been using Python to test this locally, but I keep getting KeyError or NoneType errors when trying to access the data.
Here’s a sanitized snippet of the payload I’m receiving:
{
"event": "v2.analytics.conversation.aggregate",
"data": {
"id": "abc-123-def",
"type": "voice",
"metrics": {
"wrap-up": {
"value": 45000
},
"talk": {
"value": 120000
},
"hold": {
"value": 0
}
}
}
}
And here’s the Python code I’m using to parse it:
import json
def handle_webhook(payload):
data = json.loads(payload)
# This works fine
conversation_id = data['data']['id']
print(f"Processing conversation: {conversation_id}")
# This is where it breaks
try:
wrap_up_time = data['data']['metrics']['wrap-up']['value']
talk_time = data['data']['metrics']['talk']['value']
print(f"Wrap-up: {wrap_up_time}, Talk: {talk_time}")
except KeyError as e:
print(f"Missing key: {e}")
print(f"Available keys in metrics: {data['data']['metrics'].keys() if 'metrics' in data['data'] else 'N/A'}")
The error message I get is Missing key: 'wrap-up' even though I can see it in the JSON above. Sometimes the webhook seems to send a slightly different structure where metrics is a list instead of a dict, which throws everything off.
Is there a standard way to handle these aggregate events? I feel like I’m missing something obvious about how the metrics are structured. I’ve checked the API documentation for GET /api/v2/analytics/conversations/queues/summary, but that endpoint returns a different format than the real-time webhook event.
Any help would be appreciated. I just need to get the talk and wrap-up times into a database for our WFM reports.
Thanks.