-
-
Notifications
You must be signed in to change notification settings - Fork 730
Alert Webhook improvements #1703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
528759d
WIP with webhook SDK function and types
matt-aitken 109f014
JSDocs added to the schema
matt-aitken 66d6854
Merge remote-tracking branch 'origin/main' into webhook-improvements
matt-aitken 8b71817
Webhooks are working
matt-aitken b09d875
Expanded the alert docs
matt-aitken 07f0268
Remove duplicate export of waitUntil.js
matt-aitken 035245e
Use uncrypto
matt-aitken 4f2109f
Don’t rate limit webhooks
matt-aitken d033444
Create slow-olives-fix.md
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
"@trigger.dev/sdk": patch | ||
--- | ||
|
||
You can add Alerts in the dashboard. One of these is a webhook, which this change greatly improves. | ||
|
||
The main change is that there's now an SDK function to verify and parse them (similar to Stripe SDK). | ||
|
||
```ts | ||
const event = await webhooks.constructEvent(request, process.env.ALERT_WEBHOOK_SECRET!); | ||
``` | ||
|
||
If the signature you provide matches the one from the dashboard when you create the webhook, you will get a nicely typed object back for these three types: | ||
- "alert.run.failed" | ||
- "alert.deployment.success" | ||
- "alert.deployment.failed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ActionFunctionArgs, json } from "@remix-run/server-runtime"; | ||
import { webhooks } from "@trigger.dev/sdk/v3"; | ||
import { WebhookError } from "@trigger.dev/sdk/v3"; | ||
import { logger } from "~/services/logger.server"; | ||
|
||
/* | ||
This route is for testing our webhooks | ||
*/ | ||
export async function action({ request }: ActionFunctionArgs) { | ||
// Make sure this is a POST request | ||
if (request.method !== "POST") { | ||
return json({ error: "[Webhook Internal Test] Method not allowed" }, { status: 405 }); | ||
} | ||
|
||
const clonedRequest = request.clone(); | ||
const rawBody = await clonedRequest.text(); | ||
logger.log("[Webhook Internal Test] Raw body:", { rawBody }); | ||
|
||
try { | ||
// Construct and verify the webhook event | ||
const event = await webhooks.constructEvent(request, process.env.INTERNAL_TEST_WEBHOOK_SECRET!); | ||
|
||
// Handle the webhook event | ||
logger.log("[Webhook Internal Test] Received verified webhook:", event); | ||
|
||
// Process the event based on its type | ||
switch (event.type) { | ||
default: | ||
logger.log(`[Webhook Internal Test] Unhandled event type: ${event.type}`); | ||
} | ||
ericallam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Return a success response | ||
return json({ received: true }, { status: 200 }); | ||
} catch (err) { | ||
// Handle webhook errors | ||
if (err instanceof WebhookError) { | ||
logger.error("[Webhook Internal Test] Webhook error:", { message: err.message }); | ||
return json({ error: err.message }, { status: 400 }); | ||
} | ||
|
||
if (err instanceof Error) { | ||
logger.error("[Webhook Internal Test] Error processing webhook:", { message: err.message }); | ||
return json({ error: err.message }, { status: 400 }); | ||
} | ||
|
||
// Handle other errors | ||
logger.error("[Webhook Internal Test] Error processing webhook:", { err }); | ||
return json({ error: "Internal server error" }, { status: 500 }); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.