export const POST = async (req: Request) => {
const webhookSignature = req.headers.get('Agentset-Signature');
if (!webhookSignature) {
return new Response('No signature provided.', { status: 401 });
}
// Copy this from the webhook details page
const secret = process.env.AGENTSET_WEBHOOK_SECRET;
if (!secret) {
return new Response('No secret provided.', { status: 401 });
}
// Make sure to get the raw body from the request
const rawBody = await req.text();
const computedSignature = crypto
.createHmac('sha256', secret)
.update(rawBody)
.digest('hex');
if (webhookSignature !== computedSignature) {
return new Response('Invalid signature', { status: 400 });
}
// Handle the webhook event
// ...
};