On-Call Escalation with Manager Context
Draft
On-Call Escalation with Manager Context
Draft
Press a step to see its codeLook up the requestor and ticket, lines 24 to 29Find the escalation contact, lines 31 to 38Page the on-call responder, lines 40 to 60Record the escalation on the ticket, lines 62 to 66

Look up the requestor and ticket

ticket === null

Fail

No ticket is attached to this run — run this tool from a ticket.

Find the escalation contact

get_manager resolves null when the IdP profile has no manager set

Page the on-call responder

response.status_code !== 202

Fail

PagerDuty rejected the event (${response.status_code}) — check the routing key.

Record the escalation on the ticket

Return

return

true
false
true
false
1// Page the on-call responder about the ticket this run is attached to,
2// including the requestor's manager as the escalation contact, then record
3// what happened as an internal ticket comment.
4//
5// Before publishing: set the PAGERDUTY_ROUTING_KEY config value to an
6// Events API v2 integration key.
7
8export const input = z.object({
9 summary: z
10 .string()
11 .min(1)
12 .describe("One line describing the incident being escalated"),
13 severity: z
14 .enum(["critical", "error", "warning", "info"])
15 .default("error")
16 .describe("PagerDuty event severity"),
17});
18
19// http.post needs a "read_write" posture; publishing a script with one
20// forces the tool's approval requirement on.
21export const domains = { "events.pagerduty.com": "read_write" };
22
23export default async function run(params: z.infer<typeof input>) {
24 // **Look up the requestor and ticket**
25 const requestor = await risotto.requestor_context();
26 const ticket = await risotto.get_ticket();
27 if (ticket === null) {
28 fail("No ticket is attached to this run — run this tool from a ticket.");
29 }
30
31 // **Find the escalation contact**
32 // get_manager resolves null when the IdP profile has no manager set —
33 // branch on it instead of assuming every requestor has one.
34 const manager = await risotto.get_manager({ email: requestor.email });
35 const escalation =
36 manager === null
37 ? `No manager on file for ${requestor.email}.`
38 : `Escalation contact: ${manager}.`;
39
40 // **Page the on-call responder**
41 const response = await http.post("https://events.pagerduty.com/v2/enqueue", {
42 json: {
43 routing_key: env.PAGERDUTY_ROUTING_KEY,
44 event_action: "trigger",
45 payload: {
46 summary: `${params.summary} (ticket ${ticket.ticket_id})`,
47 source: "risotto",
48 severity: params.severity,
49 custom_details: {
50 reported_by: requestor.email,
51 escalation_contact: manager ?? "none on file",
52 },
53 },
54 },
55 });
56 if (response.status_code !== 202) {
57 fail(
58 `PagerDuty rejected the event (${response.status_code}) — check the routing key.`,
59 );
60 }
61
62 // **Record the escalation on the ticket**
63 await risotto.add_ticket_comment({
64 comment: `Paged on-call (severity: ${params.severity}) about "${params.summary}". ${escalation}`,
65 });
66 return `Paged on-call for ticket ${ticket.ticket_id} (${params.severity}). ${escalation}`;
67}
24 // **Look up the requestor and ticket**
25 const requestor = await risotto.requestor_context();
26 const ticket = await risotto.get_ticket();
27 if (ticket === null) {
28 fail("No ticket is attached to this run — run this tool from a ticket.");
29 }
31 // **Find the escalation contact**
32 // get_manager resolves null when the IdP profile has no manager set —
33 // branch on it instead of assuming every requestor has one.
34 const manager = await risotto.get_manager({ email: requestor.email });
35 const escalation =
36 manager === null
37 ? `No manager on file for ${requestor.email}.`
38 : `Escalation contact: ${manager}.`;
40 // **Page the on-call responder**
41 const response = await http.post("https://events.pagerduty.com/v2/enqueue", {
42 json: {
43 routing_key: env.PAGERDUTY_ROUTING_KEY,
44 event_action: "trigger",
45 payload: {
46 summary: `${params.summary} (ticket ${ticket.ticket_id})`,
47 source: "risotto",
48 severity: params.severity,
49 custom_details: {
50 reported_by: requestor.email,
51 escalation_contact: manager ?? "none on file",
52 },
53 },
54 },
55 });
56 if (response.status_code !== 202) {
57 fail(
58 `PagerDuty rejected the event (${response.status_code}) — check the routing key.`,
59 );
60 }
62 // **Record the escalation on the ticket**
63 await risotto.add_ticket_comment({
64 comment: `Paged on-call (severity: ${params.severity}) about "${params.summary}". ${escalation}`,
65 });
66 return `Paged on-call for ticket ${ticket.ticket_id} (${params.severity}). ${escalation}`;
Config you will fill in
These become encrypted config fields on the new tool:PAGERDUTY_ROUTING_KEY