Coder Social home page Coder Social logo

node-flowdock's Introduction

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.

node-flowdock's People

Contributors

lautis avatar arttu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.