Skip to main content

What are Webhooks?

Webhooks are the trigger mechanism that awakens your AI agent. Instead of your agent constantly checking for new emails, webhooks notify it instantly when something happens—a new email arrives, a message bounces, or a delivery fails.
https://mintcdn.com/jasni/lHmS9NbBwozpErCB/icons-svg/refresh.svg?fit=max&auto=format&n=lHmS9NbBwozpErCB&q=85&s=345301f8459448873d2550e8c7c63743

Instant Awareness

Your agent knows the moment an email arrives
https://mintcdn.com/jasni/lHmS9NbBwozpErCB/icons-svg/check.svg?fit=max&auto=format&n=lHmS9NbBwozpErCB&q=85&s=df478a200c9054dd3a57ec54c30b8fa8

Resource Efficient

No wasted cycles polling—agents only wake when needed
https://mintcdn.com/jasni/lHmS9NbBwozpErCB/icons-svg/keys.svg?fit=max&auto=format&n=lHmS9NbBwozpErCB&q=85&s=d1457e1d1f41d82f34eba1085c86c7e7

Secure

Signed payloads ensure events are authentic
https://mintcdn.com/jasni/HyBGBd8FKHwaOJ6d/icons-svg/webhook.svg?fit=max&auto=format&n=HyBGBd8FKHwaOJ6d&q=85&s=f0553984c133e7a1715f7c76ccb52b75

Reliable

Automatic retries guarantee delivery

Quick Start

1. Create a Webhook Endpoint

Create an HTTP endpoint that will wake your agent when events occur:
// Express.js example
app.post('/webhooks/jasni', express.json(), async (req, res) => {
  const { event, data } = req.body;
  
  console.log(`Agent notified of ${event}`);
  
  // Trigger your AI agent
  switch (event) {
    case 'email.received':
      await agent.processIncomingEmail(data);
      break;
    case 'email.sent':
      await agent.confirmDelivery(data);
      break;
  }
  
  // Always respond with 200
  res.status(200).send('OK');
});

2. Register the Webhook

Use the API to register your endpoint:
curl -X POST https://api.jasni.ai/api/v1/webhooks \
  -H "Authorization: Bearer jsk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-server.com/webhooks/jasni",
    "events": ["email.received", "email.sent"]
  }'

3. Save the Secret

The response includes a secret - save it securely:
{
  "success": true,
  "data": {
    "webhook": {
      "id": "webhook-id",
      "secret": "whsec_abc123..."
    }
  }
}

4. Verify Signatures

Always verify that webhooks are from Jasni:
const crypto = require('crypto');

function verifySignature(payload, signature, secret) {
  const expected = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');
  
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected)
  );
}

app.post('/webhooks/jasni', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-webhook-signature'];
  const payload = req.body.toString();
  
  if (!verifySignature(payload, signature, process.env.WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }
  
  // Process verified webhook
  const data = JSON.parse(payload);
  // ...
});

Available Events

EventTrigger
email.receivedNew email arrives in mailbox
email.sentEmail sent successfully
email.bouncedEmail delivery failed
email.spamEmail marked as spam
email.deletedEmail was deleted
https://mintcdn.com/jasni/lHmS9NbBwozpErCB/icons-svg/info.svg?fit=max&auto=format&n=lHmS9NbBwozpErCB&q=85&s=c94668b0be6eb16006e8624605a36478

Event Reference

See detailed payload schemas for each event

Webhook Payload

Every webhook includes all the context your agent needs to act:
{
  "event": "email.received",
  "timestamp": "2024-01-15T10:30:00.000Z",
  "data": {
    "id": "12345",
    "messageId": "<[email protected]>",
    "from": "[email protected]",
    "to": ["[email protected]"],
    "subject": "Need help with my order",
    "account": "[email protected]",
    "folder": "INBOX",
    "text": "Hi, I have a question about my recent order...",
    "html": "<p>Hi, I have a question about my recent order...</p>"
  }
}

Headers

Each webhook request includes:
HeaderDescription
Content-Typeapplication/json
X-Webhook-SignatureHMAC-SHA256 signature
X-Webhook-TimestampUnix timestamp
X-Webhook-EventEvent type
User-AgentJasniAI-Webhooks/1.0

Retry Policy

If your endpoint fails (non-2xx response or timeout), Jasni retries:
AttemptDelay
1stImmediate
2nd10 seconds
3rd60 seconds
4th5 minutes
After 3 failed retries, the delivery is marked as failed.

Best Practices

Return a 200 response immediately, then queue the event for your agent to process. Webhooks timeout after 30 seconds.
The same event might be delivered multiple times. Your agent should handle duplicates gracefully.
Verify the X-Webhook-Signature header to ensure events are genuinely from Jasni—not spoofed.
Always use HTTPS endpoints in production to protect email content in transit.

Next Steps