type ScreenshotResponse = {
  store: {
    location: string;
  }
}

client.defineJob({
  id: "screenshot-one-example",
  name: "Screenshot One Example",
  version: "1.0.0",
  trigger: invokeTrigger({
    schema: z.object({
      url: z.string().url().default("https://trigger.dev"),
    }),
  }),
  run: async (payload, io, ctx) => {
    const result = await io.waitForRequest<ScreenshotResponse>(
      "screenshot-one",
      async (url) => {
        await fetch(`https://api.screenshotone.com/take`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            access_key: process.env.SCREENSHOT_ONE_API_KEY,
            url: payload.url,
            store: "true",
            storage_path: "my-screeshots",
            response_type: "json",
            async: "true",
            webhook_url: url, // this is the URL that will be called when the screenshot is ready
            storage_return_location: "true",
          }),
        });
      },
      {
        timeoutInSeconds: 300,
      }
    );
  },
});

Parameters

cacheKey
string
required

Should be a stable and unique cache key inside the run(). See resumability for more information.

callback
function
required

A callback function that is called with a single url parameter. When the URL is POSTed to, the task will be completed and the POST request body will be returned.

options
object
timeoutInSeconds
number

The amount of time to wait for the request to be made before timing out. Defaults to 1 hour.

Returns

Returns a Promise that resolves to the request body when the request is made.