Webhook Handling

Handle webhook events from Limitry

Handle webhook events when quotas are exceeded.

import express from 'express';

const app = express();
app.use(express.json());

app.post('/webhooks/quota-alert', async (req, res) => {
  const { event, quota, customerId, usage } = req.body;

  if (event === 'quota.threshold_exceeded') {
    // Send notification to customer
    await notifyCustomer(customerId, {
      quota,
      usage,
      message: `You've used ${usage.percentage}% of your quota`,
    });
  }

  res.status(200).send('OK');
});
from flask import Flask, request

app = Flask(__name__)

@app.route('/webhooks/quota-alert', methods=['POST'])
async def handle_quota_alert():
    data = request.json
    event = data.get('event')
    quota = data.get('quota')
    customer_id = data.get('customerId')
    usage = data.get('usage')

    if event == 'quota.threshold_exceeded':
        # Send notification to customer
        await notify_customer(customer_id, {
            'quota': quota,
            'usage': usage,
            'message': f"You've used {usage['percentage']}% of your quota",
        })

    return {'status': 'OK'}, 200