Socket
Socket
Sign inDemoInstall

flowdock-stream

Package Overview
Dependencies
48
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flowdock-stream

A streaming client for flowdock flows


Version published
Maintainers
1
Install size
3.80 MB
Created

Readme

Source

flowdock-stream

A node module for streaming flowdock flows. NOTE: for the older API, check version 0.1.3.

Installation

npm install flowdock-stream

Usage

var FlowdockStream = require('flowdock-stream');
var org = 'organization';
var flows = ['flow', 'another'];
var apikey = 'personal-apikey';
var defaultRequestOptions = { proxy: 'http://user:pass@proxyserver' };
var flowdockStream = FlowdockStream.createClient(org, flows, apikey, defaultRequestOptions);

flowdockStream.on('ready', function () {
    console.log('flowdockStream is ready, flows:\r\n', flowdockStream.flows);
});

flowdockStream.on('data', function flowDockEventHandler(data) {
    var sourceFlow = flowdockStream.flows[data.flow];
    if (data.event === 'message') {
        var from = (data.user) ? sourceFlow.users[data.user] : null;
        console.log('a message from', from, data.content);
    } else if (data.event === 'join') {
        var flowName = sourceFlow.name;
        flowdockStream.getUsers(flowName, function setUsers(err, users) {
            if (err) return flowdockStream.emit('error', err);
            sourceFlow.users = users;
            flowdockStream.send(flowName, 'Hello ' + users[data.user]);
        });
    }
});

flowdockStream.on('error', function realGoodErrorHandler(err) {
    throw err;
});

Public methods

A stream is created with the only exported function as follows:

FlowdockStream.createClient( organization, flows, apikey, defaultRequestOptions )

  • first three arguments are mandatory, the apikey is a personal apikey, not an apikey of a flow (the module accesses the REST-API that requires the personal key)
  • the flows argument can be either a string (for a sinlge flow) or an array (for multiple flows)
  • the defaultRequestOptions is an object passed to the underlying request-module to use as default options
  • the stream will emit a ready event once the stream is about to start emitting data and the flows property has been set

The stream itself is a readable node.js stream in object-mode (each data-event holds a complete object), but added are a couple of methods for convenience:

flowdockStream.flows

  • Object that contains the names and urikeys as well as all of the users in the flow at the time of joining.

flowdockStream.getFlows( callback )

  • Function that takes a callback-function which returns two arguments error (Error), and flows (Object), this also gets all of the users for each flow.

flowdockStream.getUsers( flow, callback )

  • Function that takes the name of the flow flow and a callback-function which returns two arguments error (Error), and users (Object)

flowdockStream.send( flow, message, [commentToId], [callback] )

  • Function that can be used to send a message to the flow (you can pick the flow-name from the flows-object by the id in an event-callback, see the example). Optionally you can pass an message-id as the third argument to send the message as a comment to a previous message. Also takes an optional callback which is passed to the underlying request module.

License

http://ok.mit-license.org

Keywords

FAQs

Last updated on 06 Sep 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc