// Adds support for GET requests to our webhook 
app.get('/webhook', (req, res) => { 
// Your verify token: should be a random string. let VERIFY_TOKEN = "<YOUR_VERIFY_TOKEN>" 
// Parse the query params let mode = req.query['hub.mode']; let token = req.query['hub.verify_token']; let challenge = req.query['hub.challenge']; 
// Checks if a token and mode were in the query string of the request 
if (mode && token) { 
// Checks if the mode and token sent are correct if (mode === 'subscribe' && token === VERIFY_TOKEN) { 
// Responds with the challenge token from the request res.status(200).send(challenge); 
} else { 
// Responds with '403 Forbidden' if tokens do not match res.sendStatus(403); } } }); 

// Creates the endpoint for our webhook 
app.post('/webhook', (req, res) => { 
let body = req.body; 
// Checks if this is an event from a page subscription if (body.object === 'page') { 
// Iterates over each entry - there may be multiple if batched body.entry.forEach(function(entry) { 
// Gets the message: entry.messaging is an array, but // will only ever contain one message, so we get index 0 let webhook_event = entry.messaging[0]; 
// Get the sender PSID let sender_psid = webhook_event.sender.id; 
// Check if the event is a message or postback and // pass the event to the appropriate handler function if (webhook_event.message) { 
handleMessage(sender_psid, webhook_event.message); } else if (webhook_event.postback) { 
handlePostback(sender_psid, webhook_event.postback); } }); 
// Returns a '200 OK' response to all requests res.status(200).send('EVENT_RECEIVED'); } else { // Returns a '404 Not Found' if event is not from a page subscription 
res.sendStatus(404); } }); 

// Handles messages events function handleMessage(sender_psid, received_message) { 
let response = {}; //... callSendAPI(sender_psid, response); }// Handles messaging_postbacks events function handlePostback(sender_psid, received_postback) { 
let response = {}; //... callSendAPI(sender_psid, response); }// Sends response messages via the Send API function callSendAPI(sender_psid, response) { // Construct the message body let request_body = { 
"recipient": { 
"id": sender_psid }, "message": response }// Send the HTTP request to the Messenger Platform request({ 
"uri": "https://graph.facebook.com/v2.6/me/messages", "qs": { "access_token": PAGE_ACCESS_TOKEN }, //do not forget to specify the Page Access Token 
"method": "POST", "json": request_body }, (err, res, body) => { 
if (!err) { 
console.log('message sent!') } else { 
console.error("Unable to send message:" + err); } }); } 

response = { "text": `Hi! I'm Zenbot and I can help you improve your skills on Stack Overflow.` } ou bien un message riche composé d'un titre, d'une image et de boutons : 
response = { 
"attachment": { 
"type": "template", "payload": { 
"template_type": "generic", "elements": [{ 
"title": "How to send request on click React Hooks way ?", 
"subtitle": "https://stackoverflow.com/questions/ 55647287/how-to-send-request-on-click-react-hooks-way", 
"image_url": attachment_url, "buttons": [ 
{ 
"type": "postback", "title": "It helped!", "payload": "useful", }, { 
"type": "postback", "title": "Not very useful.", "payload": "useless", } ], }] } } }