Hey everyone,
I’m building a Node.js Lambda function to process Genesys Cloud interaction events. We need to track agent adherence strictly, so I’m listening for the interaction.routed event via a webhook.
The Lambda triggers fine, but I’m struggling to parse the payload correctly. The event comes in as a JSON string, and when I try to access the agent ID, I keep getting undefined. I’ve tried JSON.parse(event.body) and JSON.parse(event), but nothing seems to work.
Here’s my current code snippet:
exports.handler = async (event) => {
const payload = JSON.parse(event.body);
console.log("Payload:", payload);
// Trying to get the agent ID from the routed event
const agentId = payload.targetId;
console.log("Agent ID:", agentId);
return {
statusCode: 200,
body: JSON.stringify({ message: 'Event processed' })
};
};
The console log for payload shows the raw event data, but targetId is always undefined. I know the event structure has a routing object with to and from details. How do I drill down into that nested structure to get the actual agent ID? Also, is there a way to filter these events in Genesys before they hit the Lambda to reduce load?
Thanks for the help.