websocket + facebook

23 views
Skip to first unread message

Marcelo Pignataro

unread,
Mar 28, 2017, 9:54:04 PM3/28/17
to nodejs
Hi community,

I'm using ws module on node.js and I'm trying to send a notification to a webrtc client when I receive a facebook chat from a facebook user, but I can't integrate ws code with node.js code for facebook API.


I have this node.js code using ws module: 

var WebSocketServer = require('ws');
var wss = new WebSocketServer.Server({port: 8080});
wss.on('connection', function(ws) {
      ws.on('message', function(message) {
          console.log('received: %s', message);
      });
      ws.send('something');
  });

And I have this node.js code for facebook api:

function sendTextMessage(recipientId, messageText) {

((HERE I NEED TO MAKE A ws.send('something'); ))
  var messageData = {
    recipient: {
      id: recipientId
    },
    message: {
      text: 'hi, I'm a bot',
      metadata: "DEVELOPER_DEFINED_METADATA"
    }
  };

  callSendAPI(messageData);
}

LAST CODE (facebook) is taken from a code published as example on facebook quick start tutorial such as "first steps with facebook messenger platform"(https://github.com/fbsamples/messenger-platform-samples/blob/master/node/app.js
Reply all
Reply to author
Forward
0 new messages