function callSendAPI(messageData) {
  request({
    uri: 'https://graph.facebook.com/v2.6/me/messages',
    qs: { access_token: PAGE_ACCESS_TOKEN },
    method: 'POST',
    json: messageData
  }, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      let recipientId = body.recipient_id
      let messageId = body.message_id

      console.log("Successfully sent generic message to recipient %s", recipientId)
    } else {
      console.error("Unable to send message.")
      // console.error(response)
      console.error(error)
    }
  })
}
/**
 * Using NodeJS request package to send a POST message with data to Messenger Platform.
 * @param {object} messageData Message object to send to Messenger Platform
 * Note: Send API ref: https://developers.facebook.com/docs/messenger-platform/reference/send-api
 */
Using NodeJS request package to send a POST message with data to Messenger Platform.
Using NodeJS request package to send a POST message with data to Messenger Platform .
function callSendAPI(messageData) {
  request({
    uri: 'https://graph.facebook.com/v2.6/me/messages',
    qs: { access_token: PAGE_ACCESS_TOKEN },
    method: 'POST',
    json: messageData
  }, function (error, response, body) {
    if (!error && response.statusCode == 200) {
      let recipientId = body.recipient_id
      let messageId = body.message_id
      console.log("Successfully sent generic message to recipient %s", recipientId)
    } else {
      console.error("Unable to send message.")
      console.error(error)
    }
  })
}
function callSendAPI ( messageData ) { request ( { uri : 'https://graph.facebook.com/v2.6/me/messages' , qs : { access_token : PAGE_ACCESS_TOKEN } , method : 'POST' , json : messageData } , function ( error , response , body ) { if ( ! error && response . statusCode == 200 ) { let recipientId = body . recipient_id let messageId = body . message_id console . log ( "Successfully sent generic message to recipient %s" , recipientId ) } else { console . error ( "Unable to send message." ) console . error ( error ) } } ) }
Using NodeJS request package to send a POST message with data to Messenger Platform.
Using NodeJS request package to send a POST message with data to Messenger Platform .
// console.error(response)