Changelog #38

·

Wait for Request

Eric Allam

Eric Allam

CTO, Trigger.dev

Image forWait for Request

When we released our Replicate integration last month, we added support for tasks that could be completed via a one-time webhook request to support Replicate Prediction webhooks. Replicate webhooks work by providing a URL for a "callback" request when creating a prediction:


_10
await replicate.predictions.create({
_10
version: "d55b9f2d...",
_10
input: { prompt: "call me later maybe" },
_10
webhook: "https://example.com/replicate-webhook",
_10
webhook_events_filter: ["completed"], // optional
_10
});

This allowed us to create an integration task that uses these webhooks to provide a seemless experience when creating a prediction:


_10
const prediction = await io.replicate.predictions.createAndAwait(
_10
"create-prediction",
_10
{
_10
version: "d55b9f2d...",
_10
input: {
_10
prompt: "call me later maybe",
_10
},
_10
}
_10
);

We've now nicely exposed the same functionality so anyone can take advantage of similar APIs with our new io.waitForRequest() built-in task. This task allows you to create a task that will wait for a request to be made to a specific URL, and then return the request body as the task result. This is useful for any API that requires a webhook to be set up, or for any API that requires a callback URL to be provided.

For example, you could use it to interface with ScreenshotOne.com to take a screenshot of a website and resume execution once the screenshot is ready:


_24
const result = await io.waitForRequest(
_24
"screenshot-one",
_24
async (url) => {
_24
await fetch(`https://api.screenshotone.com/take`, {
_24
method: "POST",
_24
headers: {
_24
"Content-Type": "application/json",
_24
},
_24
body: JSON.stringify({
_24
access_key: process.env.SCREENSHOT_ONE_API_KEY,
_24
url: "https://trigger.dev",
_24
store: "true",
_24
storage_path: "my-screeshots",
_24
response_type: "json",
_24
async: "true",
_24
webhook_url: url, // this is the URL that will be called when the screenshot is ready
_24
storage_return_location: "true",
_24
}),
_24
});
_24
},
_24
{
_24
timeoutInSeconds: 300, // wait up to 5 minutes for the screenshot to be ready
_24
}
_24
);

How to update

The trigger.dev/* packages are now at v2.2.6. You can update using the following command:


_10
npx @trigger.dev/cli@latest update

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now
,