naystack - v1.5.10
    Preparing search index...
    • Sets up GET (verification) and POST (event handling) route handlers for the Instagram webhook.

      • GET: Responds to Meta's webhook verification challenge (checks hub.verify_token against secret).
      • POST: Parses incoming webhook events and calls your callback for each event in the payload.

      Parameters

      • options: {
            callback: (type: string, value: any, id: string) => Promise<void>;
            secret: string;
        }

        Configuration object.

        • callback: (type: string, value: any, id: string) => Promise<void>

          Called for each webhook event: (type, value, pageId) => Promise<void>.

          • type — Event type (e.g. "messaging", "changes").
          • value — Event payload.
          • id — The page/account id from the entry.
        • secret: string

          The verify token you configured in the Meta Developer Portal.

      Returns {
          GET: (req: NextRequest) => NextResponse<unknown> | undefined;
          POST: (req: NextRequest) => Promise<Response>;
      }

      Object with GET and POST — export as your route's handlers.

      // app/api/webhooks/instagram/route.ts
      import { setupInstagramWebhook } from "naystack/socials";

      export const { GET, POST } = setupInstagramWebhook({
      secret: process.env.WEBHOOK_SECRET!,
      callback: async (type, value, id) => {
      if (type === "messaging") {
      console.log("New message from page", id, value);
      }
      },
      });