Overview

Webhooks provide a real-time way to receive automation results without continuously polling the API. When you include a callbackUrl in your Remote Dispatch request, Narada will send a POST request to your specified URL when the task completes.

Remote Dispatch Request with Webhook
{
  "prompt": "/Operator search for software engineering jobs in Berkeley",
  "clearChat": true,
  "saveScreenshot": true,
  "callbackURL": "https://your-webhook-endpoint.com"
}

Implementing Webhook Endpoints

const express = require("express");
const app = express();

// Middleware to parse JSON bodies
app.use(express.json());

app.post("/api/narada-webhook", async (req, res) => {
  const { requestId, status, response } = req.body;

  console.log(`Task ${requestId} completed with status: ${status}`); // Task req_abc123def456 completed with status: success

  try {
    if (status === "success") {
      // Process successful response
      console.log("Response:", response.text); // Response: Successfully extracted customer data from table
      await processAutomationResult(requestId, response.text);
    } else if (status === "error") {
      // Handle error
      console.error("Automation failed:", response.text); // Automation failed: Element not found on page
      await handleAutomationError(requestId, response.text);
    }

    // Always respond with 200 to acknowledge receipt
    res.status(200).json({ received: true });
  } catch (error) {
    console.error("Webhook processing error:", error); // Webhook processing error: Database connection failed
    res.status(500).json({ error: "Internal server error" });
  }
});

async function processAutomationResult(requestId, responseText) {
  // Your business logic here
}

async function handleAutomationError(requestId, errorText) {
  // Your error handling logic here
}

app.listen(3000, () => {
  console.log("Webhook server listening on port 3000"); // Webhook server listening on port 3000
});

Next Steps