8000 GitHub - brentc/node-flowdock: Flowdock client/API for node.js
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

brentc/node-flowdock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-flowdock Build Status

Flowdock Streaming client for node.js. Listen to messages from Flowdock in real-time and post new messages.

Installation

npm install flowdock

or

# in package.json
"dependencies": {
  "node-flowdock": "latest"
}

Example usage

Flows are stringly typed. Either subdomain:flow or subdomain/flow can be used. This may change in future versions.

Opening and closing a stream

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 the stream receives a JSON message.

Listen to messages

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.

Set your status for a flow

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.

Post a chat message to a flow

session.message('example:main', 'Isn\'t this cool?');

Both arguments should be strings. Sending a message is flow specific.

Post a chat message to a private chat

session.privateMessage(12345, 'Hi, this is a secret message!');

The first argument is the recipient's ID.

Fetch and stream all the flows your user has an access

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.

Development

You'll need coffee-script, mocha and colors for development, just run npm install. Code can be compiled to .js with command make build.

About

Flowdock client/API for node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 99.7%
  • JavaScript 0.3%
0