EventBridge consumer failing to parse v2.analytics.conversation.aggregate payload

Step one: the downstream lambda needs to extract wrap-up durations from the v2.analytics.conversation.aggregate payload. Step two: we’re mapping the EventBridge rule to the endpoint, but the nested structure keeps breaking the parser. Here’s the failing line:

let aht = event.detail.data[0].metrics['avg_handle_time'].value;

The index shifts when multiple queues trigger. Does the aggregate event flatten the groupBy keys? The console output swaps metrics and attributes randomly.