MCPcopy
hub / github.com/triggerdotdev/trigger.dev / waitForRequest

Method waitForRequest

packages/trigger-sdk/src/io.ts:458–496  ·  view source on GitHub ↗

`io.waitForRequest()` allows you to pause the execution of a run until the url provided in the callback is POSTed to. * This is useful for integrating with external services that require a callback URL to be provided, or if you want to be able to wait until an action is performed somewhere else

(
    cacheKey: string | any[],
    callback: (url: string) => Promise<unknown>,
    options?: { timeoutInSeconds?: number }
  )

Source from the content-addressed store, hash-verified

456 * ```
457 */
458 async waitForRequest<T extends Json<T> | unknown = unknown>(
459 cacheKey: string | any[],
460 callback: (url: string) => Promise<unknown>,
461 options?: { timeoutInSeconds?: number }
462 ): Promise<T> {
463 const timeoutInSeconds = options?.timeoutInSeconds ?? 60 * 60;
464
465 return (await this.runTask(
466 cacheKey,
467 async (task, io) => {
468 if (!task.callbackUrl) {
469 throw new Error("No callbackUrl found on task");
470 }
471
472 task.outputProperties = [
473 {
474 label: "Callback URL",
475 text: task.callbackUrl,
476 },
477 ];
478
479 return callback(task.callbackUrl) as Promise<{}>;
480 },
481 {
482 name: "Wait for Request",
483 icon: "clock",
484 callback: {
485 enabled: true,
486 timeoutInSeconds: options?.timeoutInSeconds,
487 },
488 properties: [
489 {
490 label: "Timeout",
491 text: `${timeoutInSeconds}s`,
492 },
493 ],
494 }
495 )) as T;
496 }
497
498 /** `io.createStatus()` allows you to set a status with associated data during the Run. Statuses can be used by your UI using the react package
499 * @param cacheKey Should be a stable and unique key inside the `run()`. See [resumability](https://trigger.dev/docs/documentation/concepts/resumability) for more information.

Callers 1

built-ins.tsFile · 0.80

Calls 1

runTaskMethod · 0.95

Tested by

no test coverage detected