-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.js
More file actions
34 lines (26 loc) · 776 Bytes
/
webhook.js
File metadata and controls
34 lines (26 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* Webhook Server
*
* @author Payant Support <[email protected]>
* @version 1.0.0
*/
const express = require('express');
const bodyParser = require('body-parser');
let app = express();
app.use(bodyParser.json());
app.get('/webhook', (req, res) => {
if(req.query.type === 'subscribe' && req.query.verify_token === 'VerifyToken') {
console.log("Token validation successful.");
res.status(200).send(req.query.challenge);
}else {
console.error("Token validation failed. Make sure the validation tokens match.");
res.sendStatus(403);
}
});
app.post('/webhook', (req, res) => {
var data = req.body;
console.log("Data received: ", data);
//Lastly send back a 200
res.sendStatus(200);
})
app.listen(process.env.PORT || 8005);