@@ -3,6 +3,13 @@ title: "Alerts"
33description : " Get alerted when runs or deployments fail, or when deployments succeed."
44---
55
6+ We support receiving alerts for the following events:
7+ - Run fails
8+ - Deployment fails
9+ - Deployment succeeds
10+
11+ ## How to setup alerts
12+
613<Steps >
714
815<Step title = " Create a new alert" >
@@ -27,3 +34,63 @@ Click on the triple dot menu on the right side of the table row and select "Disa
2734</Step >
2835
2936</Steps >
37+
38+
39+ ## Alert webhooks
40+
41+ For the alert webhooks you can use the SDK to parse them. Here is an example of how to parse the webhook payload in Remix:
42+
43+ ``` ts
44+ import { ActionFunctionArgs , json } from " @remix-run/server-runtime" ;
45+ import { webhooks , WebhookError } from " @trigger.dev/sdk/v3" ;
46+
47+ export async function action({ request }: ActionFunctionArgs ) {
48+ // Make sure this is a POST request
49+ if (request .method !== " POST" ) {
50+ return json ({ error: " Method not allowed" }, { status: 405 });
51+ }
52+
53+ try {
54+ // Construct and verify the webhook event
55+ // This secret can be found on your Alerts page when you create a webhook alert
56+ const event = await webhooks .constructEvent (request , process .env .ALERT_WEBHOOK_SECRET ! );
57+
58+ // Process the event based on its type
59+ switch (event .type ) {
60+ case " alert.run.failed" : {
61+ console .log (" [Webhook Internal Test] Run failed alert webhook received" , { event });
62+ break ;
63+ }
64+ case " alert.deployment.success" : {
65+ console .log (" [Webhook Internal Test] Deployment success alert webhook received" , { event });
66+ break ;
67+ }
68+ case " alert.deployment.failed" : {
69+ console .log (" [Webhook Internal Test] Deployment failed alert webhook received" , { event });
70+ break ;
71+ }
72+ default : {
73+ console .log (" [Webhook Internal Test] Unhandled webhook type" , { event });
74+ }
75+ }
76+
77+ // Return a success response
78+ return json ({ received: true }, { status: 200 });
79+ } catch (err ) {
80+ // Handle webhook errors
81+ if (err instanceof WebhookError ) {
82+ console .error (" Webhook error:" , { message: err .message });
83+ return json ({ error: err .message }, { status: 400 });
84+ }
85+
86+ if (err instanceof Error ) {
87+ console .error (" Error processing webhook:" , { message: err .message });
88+ return json ({ error: err .message }, { status: 400 });
89+ }
90+
91+ // Handle other errors
92+ console .error (" Error processing webhook:" , { err });
93+ return json ({ error: " Internal server error" }, { status: 500 });
94+ }
95+ }
96+ ```
0 commit comments