mirror of
https://github.com/tiennm99/claude-status-webhook.git
synced 2026-04-17 13:21:01 +00:00
fix: detect Statuspage event type by payload shape instead of meta.event_type
Statuspage webhooks don't include meta.event_type — the official API differentiates by root-level keys (incident vs component_update/component).
This commit is contained in:
@@ -68,42 +68,21 @@ export async function handleStatuspageWebhook(c) {
|
|||||||
return c.text("OK", 200);
|
return c.text("OK", 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventType = body?.meta?.event_type;
|
// Statuspage payloads have no event_type discriminator — detect by root-level keys
|
||||||
if (!eventType) {
|
|
||||||
const reason = "missing_event_type";
|
|
||||||
const details = { keys: Object.keys(body || {}), meta: body?.meta ?? null };
|
|
||||||
console.error(JSON.stringify({ level: "error", event: "webhook_error", reason, ...details }));
|
|
||||||
c.executionCtx.waitUntil(notifyAdmin(c.env, reason, details));
|
|
||||||
return c.text("OK", 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(JSON.stringify({ event: "webhook_received", eventType }));
|
|
||||||
|
|
||||||
// Determine category and format message
|
|
||||||
let category, html, componentName;
|
let category, html, componentName;
|
||||||
if (eventType.startsWith("incident.")) {
|
if (body.incident) {
|
||||||
if (!body.incident) {
|
|
||||||
const reason = "missing_incident_data";
|
|
||||||
console.error(JSON.stringify({ event: "webhook_error", reason, eventType }));
|
|
||||||
c.executionCtx.waitUntil(notifyAdmin(c.env, reason, { eventType }));
|
|
||||||
return c.text("OK", 200);
|
|
||||||
}
|
|
||||||
category = "incident";
|
category = "incident";
|
||||||
html = formatIncidentMessage(body.incident);
|
html = formatIncidentMessage(body.incident);
|
||||||
} else if (eventType.startsWith("component.")) {
|
console.log(JSON.stringify({ event: "webhook_received", category, incident: body.incident.name }));
|
||||||
if (!body.component) {
|
} else if (body.component_update || body.component) {
|
||||||
const reason = "missing_component_data";
|
|
||||||
console.error(JSON.stringify({ event: "webhook_error", reason, eventType }));
|
|
||||||
c.executionCtx.waitUntil(notifyAdmin(c.env, reason, { eventType }));
|
|
||||||
return c.text("OK", 200);
|
|
||||||
}
|
|
||||||
category = "component";
|
category = "component";
|
||||||
componentName = body.component.name || null;
|
const component = body.component;
|
||||||
html = formatComponentMessage(body.component, body.component_update);
|
componentName = component?.name || null;
|
||||||
|
html = formatComponentMessage(component, body.component_update);
|
||||||
|
console.log(JSON.stringify({ event: "webhook_received", category, component: componentName }));
|
||||||
} else {
|
} else {
|
||||||
const reason = "unknown_event_type";
|
// Unknown payload shape — log and accept
|
||||||
console.error(JSON.stringify({ event: "webhook_error", reason, eventType }));
|
console.log(JSON.stringify({ event: "webhook_unknown", keys: Object.keys(body) }));
|
||||||
c.executionCtx.waitUntil(notifyAdmin(c.env, reason, { eventType }));
|
|
||||||
return c.text("OK", 200);
|
return c.text("OK", 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user