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.
|
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 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);
}