This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function receivedPostback(event) { | |
| let senderID = event.sender.id; | |
| let recipientID = event.recipient.id; | |
| let timeOfPostback = event.timestamp; | |
| // The 'payload' param is a developer-defined field which is set in a postback | |
| // button for Structured Messages. | |
| let payload = event.postback.payload; | |
| console.log(`Received postback for user ${senderID} and page ${recipientID} with payload ${payload} at ${timeOfPostback}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sendGenericMessage(recipientId) { | |
| let messageData = { | |
| recipient: { | |
| id: recipientId | |
| }, | |
| message: { | |
| attachment: { | |
| type: "template", | |
| payload: { | |
| template_type: "generic", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function callSendAPI(messageData) { | |
| const http_options = { | |
| "method": "POST", | |
| "body": JSON.stringify(messageData), | |
| "headers": { | |
| 'Content-Type': 'application/json' | |
| } | |
| }; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sendTextMessage(recipientId, messageText) { | |
| let messageData = { | |
| recipient: { | |
| id: recipientId | |
| }, | |
| message: { | |
| text: messageText | |
| } | |
| }; | |
| callSendAPI(messageData); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function receivedMessage(event) { | |
| let senderID = event.sender.id; | |
| let recipientID = event.recipient.id; | |
| let timeOfMessage = event.timestamp; | |
| let message = event.message; | |
| console.log(`Received message for user ${senderID} and page ${recipientID} at ${timeOfMessage} with message: ${JSON.stringify(message)}`); | |
| let messageId = message.mid; | |
| let messageText = message.text; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // process POST request (send/receive messages) | |
| } else { | |
| let data = JSON.parse(request.body); | |
| // Make sure this is a page subscription | |
| if (data.object === 'page') { | |
| // Iterate over each entry - there may be multiple if batched | |
| data.entry.forEach(function(entry) { | |
| let pageID = entry.id; | |
| let timeOfEvent = entry.time; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default (request, response) => { | |
| const pubnub = require('pubnub'); | |
| const kvstore = require('kvstore'); | |
| const xhr = require('xhr'); | |
| let headersObject = request.headers; | |
| let paramsObject = request.params; | |
| let methodString = request.method; | |
| let bodyString = request.body; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default (request, response) => { | |
| const pubnub = require('pubnub'); | |
| const kvstore = require('kvstore'); | |
| const xhr = require('xhr'); | |
| let headersObject = request.headers; | |
| let paramsObject = request.params; | |
| let methodString = request.method; | |
| let bodyString = request.body; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| PUBNUB.replay({ | |
| source : 'my_channel', | |
| destination : 'new_channel' | |
| }); | |
| */ | |
| 'replay' : function(args, callback) { | |
| var callback = callback || args['callback'] || function(){} | |
| , auth_key = args['auth_key'] || AUTH_KEY | |
| , source = args['source'] |