Flowdock Streaming client for node.js. Listen to messages from Flowdock in real-time and post new messages.
npm install flowdock
or
# in package.json
"dependencies": {
"node-flowdock": "latest"
}
Flows are stringly typed. Either subdomain:flow or subdomain/flow can be used. This may change in future versions.
var Session = require('./flowdock').Session;
var session = new Session(username, password);
var stream = session.stream('example/main');
stream.end();
The argument(s) for stream() can be a string ('subdomain/flow') or an array (['subdomain/flow', 'subdomain/anotherflow']).
session.stream() returns an instance of EventEmitter. Currently it emits two types of events:
error
is emitted with a response status code and an error message. This can happen when a connection can't be estabilished or you don't have access to one or more flows you tried to stream.message
is emitted when thestream
receives a JSON message.
stream = session.stream(flow);
stream.on('message', function(message) {
// Do stuff with message
return stream.end();
});
The full message format specification for different message types is in Flowdock API Message documentation.
session.status('example:main', 'I just got the first message through the Flowdock stream API.');
Both arguments should be strings. Setting a status is flow specific.
session.message('example:main', 'Isn\'t this cool?');
Both arguments should be strings. Sending a message is flow specific.
session.message(12345, 'Hi, this is a secret message!');
The first argument is the recipient's ID, and has to be a number.
session.flows(function(flows) {
var anotherStream, flowIds;
flowIds = flows.map(function(f) {
return f.id;
});
anotherStream = session.stream(flowIds);
return anotherStream.on('message', function(msg) {
console.log('message from stream:', msg);
// variable 'msg' being something like:
// {
// event: 'activity.user',
// flow: 'subdomain:flow',
// content: { last_activity: 1329310503807 },
// user: '12345',
// .. plus few other fields
// }
});
});
The full message format specification for different message types is in Flowdock API Message documentation.
You'll need coffee-script
, mocha
and colors
for development, just run npm install
. Code can be compiled to .js with command make build
.