Socket
Socket
Sign inDemoInstall

slack-notify

Package Overview
Dependencies
48
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    slack-notify

A simple Node.js wrapper around the Slack webhook API.


Version published
Weekly downloads
75K
decreased by-19.51%
Maintainers
1
Install size
4.52 MB
Created
Weekly downloads
 

Readme

Source

slack-notify

Build Status

A simple, flexible Node.js wrapper around the Slack webhook API. Makes it easy to send notifications to Slack from your application.

Installation

npm install slack-notify

Usage


// Require module:

var MY_SLACK_WEBHOOK_URL = 'https://myaccountname.slack.com/services/hooks/incoming-webhook?token=myToken';
var slack = require('slack-notify')(MY_SLACK_WEBHOOK_URL);

// Bundled notification types:

slack.bug('Something bad happened!'); // Posts to #bugs by default
slack.success('Something good happened!'); // Posts to #alerts by default
slack.alert('Something important happened!'); // Posts to #alerts by default
slack.note('Here is a note.'); // Posts to #alerts by default

// Send custom fields which are nicely displayed by the Slack client:

slack.alert({
  text: 'Current server stats',
  fields: {
    'CPU usage': '7.51%',
    'Memory usage': '254mb'
  }
});

// The `fields` object is custom shorthand for the `attachments` array:

slack.alert({
  text: 'Current server stats',
  attachments: [
    {
      fallback: 'Required Fallback String',
      fields: [
        { title: 'CPU usage', value: '7.51%', short: true },
        { title: 'Memory usage', value: '254mb', short: true }
      ]
    }
  ]
});

// Everything is overridable:

slack.send({
  channel: '#myCustomChannelName',
  icon_url: 'http://example.com/my-icon.png',
  text: 'Here is my notification',
  unfurl_links: 1,
  username: 'Jimmy'
});

// Roll your own notification type:

var statLog = slack.extend({
  channel: '#statistics',
  icon_emoji: ':computer:',
  username: 'Statistics'
});

statLog({
  text: 'Current server statistics',
  fields: {
    'CPU usage': '7.51%',
    'Memory usage': '254mb'
  }
});

// Callbacks and a generic onError function are supported:

slack.alert('Hello', function (err) {
  if (err) {
    console.log('API error:', err);
  } else {
    console.log('Message received!');
  }
});

slack.onError = function (err) {
  console.log('API error:', err);
};

Running the Test Suite

npm install
npm test

License

MIT. Copyright © 2014 Andrew Childs

Keywords

FAQs

Last updated on 09 Jan 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