Node.js Lambda handler crashing on Genesys Cloud Conversation.Analytics.AgentSummary webhook payload

I’ve been trying to set up a simple Lambda function in Node.js to catch the conversation.analytics.agentsummary webhooks from Genesys Cloud. The idea is just to log the agent’s wrap-up code into a DynamoDB table for later reporting. I’ve got the webhook configured in Genesys to hit the Lambda URL, and I can see the events firing in the Genesys console, but the Lambda keeps timing out or throwing a Runtime.UnknownError.

Here’s the handler code I’m using right now:

exports.handler = async (event) => {
 try {
 console.log("Received event:", JSON.stringify(event));
 
 // Trying to extract the relevant data
 const body = event.body;
 console.log("Body type:", typeof body);
 
 // This is where it seems to fail
 const payload = JSON.parse(body);
 const agent = payload.data.agent;
 
 // Logic to write to DB would go here
 return {
 statusCode: 200,
 body: JSON.stringify({ message: 'Processed' })
 };
 } catch (error) {
 console.error("Error processing webhook:", error);
 throw error;
 }
};

The weird thing is that when I test it locally with a sample JSON payload, it works fine. But in production, event.body is coming in as a string that looks like a double-encoded JSON or something similar. I’m seeing errors like SyntaxError: Unexpected token o in JSON at position 1 in the CloudWatch logs.

I’ve tried adding JSON.parse(event.body) but that just makes it worse sometimes. Is Genesys sending the payload in a specific format that requires special handling in the Lambda trigger config? I’ve checked the webhook settings and it’s set to application/json.

Any ideas on how to properly parse the incoming event structure for this specific webhook type? I’m stuck on why the local test works but the live event fails.