βWebhook (LEGACY)
Last updated
npm install express body-parser crypto --saveconst express = require('express');
const crypto = require('crypto');
const bodyParser = require('body-parser');
const app = express();
const port = 4000;
app.use(bodyParser.json());
// Your webhook secret key from the dashboard
const secret = 'secretKey';
// Middleware to validate the webhook signature
function validateSignature(req, res, next) {
const sigHeader = req.headers["x-webhook-signature"];
const signature = crypto.createHmac('sha256', secret.replace('E_AI_K_', '')).update(req.body.result).digest('base64');
if (signature !== sigHeader) {
return res.status(401).send({ message: "Webhook is not properly signed" })
}
next()
}
// Webhook endpoint
app.post('/webhook', validateSignature, (req, res) => {
console.log('Webhook received:', req.body);
// Process the webhook payload as needed
// ...
res.send({ message: "Webhook received" })
})
app.listen(port, () => console.log(`Server listening on port ${port}!`))