Hi, I need to send a notification from a websocket server to a websocket client when a facebook user send a message to a facebook web page. To receive facebook message I'm using a facebook messenger api and ws module to send a notification from node.js that runs a websocket server to websocket client. So I don't know how code it, I read both guide of tools but I could make it work.
Next code I take from a facebook example (https://github.com/fbsamples/messenger-platform-samples/blob/master/node/app.js): app.post('/webhook', function (req, res) { var data = req.body; if (data.object == 'page') { data.entry.forEach(function(pageEntry) { var pageID = pageEntry.id; var timeOfEvent = pageEntry.time; pageEntry.messaging.forEach(function(messagingEvent) { if (messagingEvent.optin) { . . . } else if (messagingEvent.message) { receivedMessage(messagingEvent); } else { . . } }); )}; function receivedMessage(event) { var senderID = event.sender.id; var recipientID = event.recipient.id; var timeOfMessage = event.timestamp; var message = event.message; . . . var messageText = message.text; if (messageText) { switch (messageText) { . . default: sendTextMessage(senderID, messageText); } } else if (messageAttachments) { . . } } function sendTextMessage(recipientId, messageText) { /* * I NEED TO SEND A MESSAGE TO A WEBSOCKET CLIENT INSIDE THIS FUNCTION */ var messageData = { recipient: { id: recipientId }, message: { text: 'buen dia', metadata: "DEVELOPER_DEFINED_METADATA" } }; callSendAPI(messageData); } -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5bf24eb2-af30-4a40-b1a6-198948b6d536%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
