We are trying to set up a webhook that triggers when a queue’s SLA is breached, specifically when the wait time exceeds our threshold. The goal is to send a formatted message to a Slack channel using their Block Kit API. I have the webhook endpoint configured in Genesys Cloud to call our internal relay service, which then forwards to Slack. The issue is mapping the Genesys Cloud webhook payload to the Slack JSON structure correctly within our .NET relay service.
The webhook from Genesys Cloud sends a payload like this:
{
"event": "queue_stats",
"data": {
"queueId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"metric": "percent_offers_answered",
"value": 0.85,
"slaThreshold": 0.90
}
}
In our .NET code, I’m using HttpClient to post to Slack. I need to construct the blocks array dynamically based on the metric and value. Here is the current relay logic:
var slackPayload = new {
channel = "#ops-alerts",
blocks = new[] {
new {
type = "section",
text = new {
type = "mrkdwn",
text = $"*SLA Breach Alert*\nQueue: {webhookData.queueId}\nMetric: {webhookData.metric}\nValue: {webhookData.value}"
}
}
}
};
var content = new StringContent(JsonSerializer.Serialize(slackPayload), Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("https://hooks.slack.com/services/T00/B00/XXX", content);
The problem is that Slack returns a 400 Bad Request if the block structure isn’t exactly right. I’m getting errors about invalid block types or missing text fields. The documentation for Slack’s Block Kit is dense, and I’m struggling to map the simple key-value pairs from the Genesys Cloud webhook to the nested Slack objects. Specifically, how do I handle the mrkdwn formatting for dynamic values? I’ve tried escaping characters but it seems like the issue is deeper in the JSON structure. Any examples of a clean mapping from Genesys Cloud queue stats to Slack blocks would be appreciated. The current implementation feels fragile and breaks often when the payload shape changes slightly.