Giter VIP home page Giter VIP logo

slackstream's Introduction

Slackstream

Pipe things into Slack or Mattermost.

Can be used as a module or on the command line.

const slackstream = require('slackstream');
let stream = slackstream('https://mm.example.com/hooks/abcd1234');
stream.write('This will show up in Slack or Mattermost.');

Usage (Module)

slackstream(webhookURL[, options ])

Returns a new writable stream that will make POST requests to the specified webhookURL. The optional options argument accepts the following options:

  • defaults: (Object) A template object that will be used for each request. The defaults will be overwritten by anything that you pass to stream.write().
  • wait: (Integer|Boolean) Do not send requests immediately on stream.write(), instead input will be buffered until no writes have occurred for the specified number of milliseconds (defaults to 200ms if passed true instead of an integer). Input will be sent immediately once it reaches Mattermost's limit of 4000 characters.
    Note: This option will disable object mode. The stream will emit an error if you try to write an object. Buffers and strings work as expected and will be joined together when the input is eventually sent.

stream.write(payload)

Sends payload to the webhookURL specified when the stream was created.

payload can be an object, in which case it will be used as the payload, or anything else, in which case it will be stringified and used as the payload's text property.

payload.text must be set and will always be stringified. All other properties of payload will be used as they are.

Default values for the payload can be specified when the stream is first created.

Example

const slackstream = require('slackstream');
const URL = 'https://mm.example.com/hooks/abcd1234';

let stream = slackstream(URL);
stream.write('This will show up in Slack or Mattermost.');
stream.write({
  text: 'This message will appear to come from octocat.',
  username: 'octocat' });

let cookieMonster = slackstream(URL,
  { defaults: { username: 'Cookie Monster' } });
cookieMonster.write('Me like cookies!');
cookieMonster.write({ text: 'I don\'t like cookies.',
  username: 'Probably Not Cookie Monster' })

Usage (CLI)

npm install -g slackstream
echo "Hello world" | slackstream http://mm.example.com/hooks/abcd1234 \
  --defaults.username octocat \
  --defaults.channel town-square

slackstream's People

Contributors

pbock avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

beejhuff

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.