Nearly Perfect Mediocracy
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

facebook-messenger-streams

0.0.2 • Public • Published

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

Keywords

none

install

npm i facebook-messenger-streams

Downloadsweekly downloads

7

version

0.0.2

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar