function receivedPostback(msg) {
  let senderID = msg.sender.id
  let recipientID = msg.recipient.id
  let timeOfPostback = msg.timestamp

  // The 'payload' param is a developer-defined field which is set in a postback 
  // button for Structured Messages. 
  let payload = msg.postback.payload

  console.log("Received postback for user %d and page %d with payload '%s' " + 
    "at %d", senderID, recipientID, payload, timeOfPostback)

  let parts = payload.split('_')
  let command = parts[0]
  if (command === 'GETSTOCKPRICE') {
    let symbol = parts[1]
    let stockName = decodeURI(parts[2])
    SDB.loadUserRecord(senderID, recipientID).then((record) => {
      let state = null
      if (record && record.Item && record.Item.vars)
        state = record.Item.vars
      RS.setUserState(senderID, state)
      return external.getStockPriceBySimbolFromYahoo(symbol)
    }).then((csv) => {
      console.log('csv', csv)
      let parts = csv.split(',')
      let price = parts[2]
      sendTextMessage(senderID, stockName + ' stock price is ' + price)
    })  
  } else {
    console.error('Unhandled payload: ' + payload)      
  }
  // When a postback is called, we'll send a message back to the sender to 
  // let them know it was successful
}
/**
 * This function handles Postback type message from Messenger. Postback messages usually are our defined payload response to various actions.
 * @param {object} msg Message object pass by Mssenger
 */
This function handles Postback type message from Messenger. Postback messages usually are our defined payload response to various actions.
@param {object} msg Message object pass by Mssenger
This function handles Postback type message from Messenger . Postback messages usually are our defined payload response to various actions . @param { object } msg Message object pass by Mssenger
function receivedPostback(msg) {
  let senderID = msg.sender.id
  let recipientID = msg.recipient.id
  let timeOfPostback = msg.timestamp
  let payload = msg.postback.payload
  console.log("Received postback for user %d and page %d with payload '%s' " + 
    "at %d", senderID, recipientID, payload, timeOfPostback)
  let parts = payload.split('_')
  let command = parts[0]
  if (command === 'GETSTOCKPRICE') {
    let symbol = parts[1]
    let stockName = decodeURI(parts[2])
    SDB.loadUserRecord(senderID, recipientID).then((record) => {
      let state = null
      if (record && record.Item && record.Item.vars)
        state = record.Item.vars
      RS.setUserState(senderID, state)
      return external.getStockPriceBySimbolFromYahoo(symbol)
    }).then((csv) => {
      console.log('csv', csv)
      let parts = csv.split(',')
      let price = parts[2]
      sendTextMessage(senderID, stockName + ' stock price is ' + price)
    })  
  } else {
    console.error('Unhandled payload: ' + payload)      
  }
}
function receivedPostback ( msg ) { let senderID = msg . sender . id let recipientID = msg . recipient . id let timeOfPostback = msg . timestamp let payload = msg . postback . payload console . log ( "Received postback for user %d and page %d with payload '%s' " + "at %d" , senderID , recipientID , payload , timeOfPostback ) let parts = payload . split ( '_' ) let command = parts [ 0 ] if ( command === 'GETSTOCKPRICE' ) { let symbol = parts [ 1 ] let stockName = decodeURI ( parts [ 2 ] ) SDB . loadUserRecord ( senderID , recipientID ) . then ( ( record ) => { let state = null if ( record && record . Item && record . Item . vars ) state = record . Item . vars RS . setUserState ( senderID , state ) return external . getStockPriceBySimbolFromYahoo ( symbol ) } ) . then ( ( csv ) => { console . log ( 'csv' , csv ) let parts = csv . split ( ',' ) let price = parts [ 2 ] sendTextMessage ( senderID , stockName + ' stock price is ' + price ) } ) } else { console . error ( 'Unhandled payload: ' + payload ) } }
This function handles Postback type message from Messenger.
This function handles Postback type message from Messenger .
// The 'payload' param is a developer-defined field which is set in a postback  // button for Structured Messages.  // When a postback is called, we'll send a message back to the sender to  // let them know it was successful