The v2.analytics.conversation.aggregate webhook payload keeps interval metrics buried inside a nested data object instead of flattening it. Our json.loads() routine hits payload['data']['metrics']['handleTime']['value'] but it’s throwing a KeyError when the same SQS queue mixes in conversation.media.created events. The JSON structure shifts between aggregate and detail schemas without a reliable eventType discriminator field. Running jq '.data.metrics' on the raw webhook.body just spits out null.
You need to guard against schema drift. The aggregate payload lives under data.metrics, but detail events don’t. Check the event type first.
if payload.get("event") == "v2.analytics.conversation.aggregate":
val = payload["data"]["metrics"]["handleTime"]["value"]
Missing the check causes the KeyError.