So I’m seeing a very odd bug with webhook ingestion.
- Context: Node.js Lambda consumer for Genesys Cloud
conversation:updated events.
- Issue: Payload arrives, but
event.detail.conversation is undefined.
- Code:
const conv = event.body.detail.conversation;
- Error:
TypeError: Cannot read properties of undefined (reading 'participants')
- Hypothesis: Is the Genesys webhook payload structure different in the Lambda
event object? Or is this a serialization issue with the API gateway integration?
- Request: Show me the correct path to extract participant data from the raw webhook body.
This looks like a string parsing issue. Lambda event.body is a string, not an object.
const body = JSON.parse(event.body);
const conv = body.detail.conversation;
I’d recommend looking at at the actual structure of the webhook payload because the conversation object is often nested deeper than expected depending on the specific event type and version. While the suggestion above correctly identifies that event.body needs parsing, you are likely hitting a case where body.detail exists but conversation is null or absent for certain update types like participant:added where the payload focuses on the participant change. I handle this in my Glue ETL jobs by validating the presence of keys before accessing them to prevent downstream Redshift COPY failures. You should implement a safe navigation check or a type guard in your Lambda handler. Here is a robust pattern using optional chaining to avoid the TypeError while ensuring you only process full conversation updates:
const payload = JSON.parse(event.body);
const conv = payload?.detail?.conversation;
if (!conv) {
console.warn('Missing conversation data in payload:', JSON.stringify(payload));
return { statusCode: 200, body: 'Ignored incomplete event' };
}
// Proceed with conv.participants
This prevents the crash and allows you to log the malformed events for debugging.
have you tried checking if the payload is actually a notification wrapper? sometimes the event type matters. try this in your lambda handler.
const body = JSON.parse(event.body);
const conv = body?.detail?.conversation || body?.conversation;
works for me with express middleware too.