facebook webhook verify token

Solutions on MaxInterview for facebook webhook verify token by the best coders in the world

showing results for - "facebook webhook verify token"
Oskar
29 Jul 2017
1// Adds support for GET requests to our webhook
2app.get('/webhook', (req, res) => {
3
4  // Your verify token. Should be a random string.
5  let VERIFY_TOKEN = "<YOUR_VERIFY_TOKEN>"
6    
7  // Parse the query params
8  let mode = req.query['hub.mode'];
9  let token = req.query['hub.verify_token'];
10  let challenge = req.query['hub.challenge'];
11    
12  // Checks if a token and mode is in the query string of the request
13  if (mode && token) {
14  
15    // Checks the mode and token sent is correct
16    if (mode === 'subscribe' && token === VERIFY_TOKEN) {
17      
18      // Responds with the challenge token from the request
19      console.log('WEBHOOK_VERIFIED');
20      res.status(200).send(challenge);
21    
22    } else {
23      // Responds with '403 Forbidden' if verify tokens do not match
24      res.sendStatus(403);      
25    }
26  }
27});