Problem
We’re routing conversation.started events from our Pacific region org to an internal queue dashboard. The admin UI confirms the webhook endpoint is active and the test ping succeeds. Actual production events just vanish in the Lambda execution logs. The timeout keeps hitting the 3-second mark before the handler finishes parsing. Pretty frustrating since the test button works fine.
Code
exports.handler = async (event) => {
const payload = JSON.parse(event.body);
const queueId = payload.from.queue_id;
const agentId = payload.to.agent_id;
await db.insert({ queueId, agentId, timestamp: payload.timestamp });
return { statusCode: 200, body: 'Processed' };
};
Error
CloudWatch throws SyntaxError: Unexpected token u in JSON at position 0 roughly half the time. The other half, the function times out. We’ve verified the signature validation middleware isn’t blocking anything. The payload structure looks standard enough when we trigger it manually through the UI. Logs are messy and the error traces don’t show the full header chain.
Question
How should we handle the gzip compression flag that Genesys Cloud sometimes attaches to these webhook deliveries? The event.headers object shows content-encoding: gzip on the failing requests, but we’re just running JSON.parse(event.body) directly. Should we pipe it through zlib first, or is there a simpler way to normalize the incoming stream before hitting the database? The documentation mentions async processing but doesn’t specify the exact Lambda signature adjustments needed for compressed bodies. We configured the webhook against /api/v2/webhooks with the conversation.started event type. The raw body sometimes arrives as a buffer instead of a string. The zlib pipe keeps throwing a stream error.