function handleHttpPost(data, callback) {
  // Make sure this is a page subscription
  if (data.object === 'page') {
    // Inititalise the RiveScript
    RS.init().then(() => {
      // Iterate over each entry - there may be multiple if batched
      data.entry.forEach(function(entry) {
        let pageID = entry.id
        let timeOfEvent = entry.time

        // Iterate over each messaging event
        entry.messaging.forEach((msg) => {
          if (msg.message) {
            receivedMessage(msg)                
          } else if (msg.postback) {
            receivedPostback(msg)
          } else {
            console.log("Webhook received unknown event: ", event)
          }
        })
      })
    
      let response = {
        'body': 'ok',
        'statusCode': 200
      };
      callback(null, response);
    })
  } else {
    throw new Error('Unhandle object: ' + data.object);
  }
}
/**
 * This function handles webhook http POST event usually called from Messenger Platform when user input messages.
 * @param {object} data 
 * @param {function} callback 
 */
This function handles webhook http POST event usually called from Messenger Platform when user input messages.
@param {object} data
@param {function} callback
This function handles webhook http POST event usually called from Messenger Platform when user input messages . @param { object } data @param { function } callback
function handleHttpPost(data, callback) {
  if (data.object === 'page') {
    RS.init().then(() => {
      data.entry.forEach(function(entry) {
        let pageID = entry.id
        let timeOfEvent = entry.time
        entry.messaging.forEach((msg) => {
          if (msg.message) {
            receivedMessage(msg)                
          } else if (msg.postback) {
            receivedPostback(msg)
          } else {
            console.log("Webhook received unknown event: ", event)
          }
        })
      })
      let response = {
        'body': 'ok',
        'statusCode': 200
      };
      callback(null, response);
    })
  } else {
    throw new Error('Unhandle object: ' + data.object);
  }
}
function handleHttpPost ( data , callback ) { if ( data . object === 'page' ) { RS . init ( ) . then ( ( ) => { data . entry . forEach ( function ( entry ) { let pageID = entry . id let timeOfEvent = entry . time entry . messaging . forEach ( ( msg ) => { if ( msg . message ) { receivedMessage ( msg ) } else if ( msg . postback ) { receivedPostback ( msg ) } else { console . log ( "Webhook received unknown event: " , event ) } } ) } ) let response = { 'body' : 'ok' , 'statusCode' : 200 } ; callback ( null , response ) ; } ) } else { throw new Error ( 'Unhandle object: ' + data . object ) ; } }
This function handles webhook http POST event usually called from Messenger Platform when user input messages.
This function handles webhook http POST event usually called from Messenger Platform when user input messages .
// Make sure this is a page subscription // Inititalise the RiveScript // Iterate over each entry - there may be multiple if batched // Iterate over each messaging event