Creating Plot Twists
    Preparing search index...

    Class CallbacksAbstract

    Built-in tool for creating and managing persistent callback references.

    The Callbacks tool enables twists and tools to create callback links that persist across worker invocations and restarts. This is essential for webhook handlers, scheduled operations, and user interaction flows that need to survive runtime boundaries.

    Note: Callback methods are also available directly on Twist and Tool classes via this.callback(), this.deleteCallback(), this.deleteAllCallbacks(), and this.run(). This is the recommended approach for most use cases.

    When to use callbacks:

    • Webhook handlers that need persistent function references
    • Scheduled operations that run after worker timeouts
    • User interaction links (ActivityLinkType.callback)
    • Cross-tool communication that survives restarts

    Type Safety: Callbacks are fully type-safe - extraArgs are type-checked against the function signature.

    class MyTool extends Tool {
    async setupWebhook() {
    // Using built-in callback method (recommended)
    const callback = await this.callback(this.handleWebhook, "calendar");
    return `https://api.plot.day/webhook/${callback}`;
    }

    async handleWebhook(data: any, webhookType: string) {
    console.log("Webhook received:", data, webhookType);
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Methods

    • Creates a persistent callback to a method on the current class.

      Parameters

      • fn: Function

        The function to callback

      • ...extraArgs: any[]

        Additional arguments to pass to the function (must be serializable)

      Returns Promise<Callback>

      Promise resolving to a persistent callback token

    • Creates a persistent callback to a function from the parent twist/tool. Use this when the callback function is passed in from outside this class.

      Parameters

      • fn: Function

        The function to callback

      • ...extraArgs: any[]

        Additional arguments to pass to the function (must be serializable, validated at runtime)

      Returns Promise<Callback>

      Promise resolving to a persistent callback token

    • Deletes a specific callback by its token.

      Parameters

      • callback: Callback

        The callback token to delete

      Returns Promise<void>

      Promise that resolves when the callback is deleted

    • Deletes all callbacks for the tool's parent.

      Returns Promise<void>

      Promise that resolves when all callbacks are deleted

    • Executes a callback by its token.

      Type Parameters

      • T = unknown

      Parameters

      • callback: Callback

        The callback token returned by create()

      • ...args: any[]

        Optional arguments to pass to the callback function

      Returns Promise<T>

      Promise resolving to the callback result