facebook-messenger-streams
v0.0.2
Published
Facebook Messenger Streaming API
Downloads
3
Readme
Facebook Messenger Streams
Wrap Facebook Messenger API in a stream-oriented interface. Using streams allows using a piping/filtering metaphor on incoming/outgoing messages which may help structure code better.
Usage
var FBInputStream = require('facebook-messenger-streams').InputStream;
var FBUserOutputStream = require('facebook-messenger-streams').UserOutputStream;
var fbInputStream = new FBInputStream(
'mysecrettoken',
process.env.APP_SECRET
);
fbInputStream.on('data', function (data) {
var senderId = data.sender.id;
console.log('got data from user', senderId, data);
var userOutputStream = new FBUserOutputStream(
process.env.PAGE_TOKEN,
senderId
);
userOutputStream.write({ text: 'Hi there!' });
});
var app = new express.Router();
app.listen(process.env.PORT || 3000);
app.use('/webhook', fbInputStream.webhookRouter);