utils/api.js
// Accept de resquest info and make HTTP POST request
Accept de resquest info and make HTTP POST request
Accept de resquest info and make HTTP POST request
function call(path, payload, done) {
  const access_token = process.env.PAGE_ACCESS_TOKEN,
        graph_url = "https://graph.facebook.com/v2.6/me";
  if(!path) {
    console.error('No endpoint specified on Messenger send!');
    return;
  } else if(!access_token || !graph_url) {
    console.error('No Page access token or graph API url configured!');
    return;
  }
  request({
    "uri": graph_url + path,
    "qs": {'access_token': access_token},
    "method": 'POST',
    "json": payload
  }, (err, res, body) => {
    if(!err && res.statusCode === 200) {
    } else {
      console.error('Error: ' + err);
      console.log(body);
    }
    done();
  });
}
function call ( path , payload , done ) { const access_token = process . env . PAGE_ACCESS_TOKEN , graph_url = "https://graph.facebook.com/v2.6/me" ; if ( ! path ) { console . error ( 'No endpoint specified on Messenger send!' ) ; return ; } else if ( ! access_token || ! graph_url ) { console . error ( 'No Page access token or graph API url configured!' ) ; return ; } request ( { "uri" : graph_url + path , "qs" : { 'access_token' : access_token } , "method" : 'POST' , "json" : payload } , ( err , res , body ) => { if ( ! err && res . statusCode === 200 ) { } else { console . error ( 'Error: ' + err ) ; console . log ( body ) ; } done ( ) ; } ) ; }
Accept de resquest info and make HTTP POST request
Accept de resquest info and make HTTP POST request
//console.log('Message sent');