JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 54589
  • Score
    100M100P100Q146112F
  • License MIT

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

Package Exports

  • slack-notify
  • slack-notify/slack-notify.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (slack-notify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

slack-notify

Build Status

A simple, flexible, zero-dependency 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

// Import module:

import SlackNotify from 'slack-notify';
const MY_SLACK_WEBHOOK_URL = 'https://hooks.slack.com/services/RANDOMCHARS';
const slack = SlackNotify(MY_SLACK_WEBHOOK_URL);

// Example sending just text, using the Slack-provided configuration:

slack.send('Hello!')
  .then(() => {
    console.log('done!');
  }).catch((err) => {
    console.error(err);
  });

// The Slack-provided configuration can be overridden:

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: '💻',
  username: 'Statistics'
});

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

// Promises are supported:

slack.send('Hello!').then(() => {
  console.log('Done!');
}).catch((err) => {
  console.error('API error:', err);
})

// Three pre-configured methods are provided:

// Posts to #bugs by default:
slack.bug('Something broke!');

// Posts to #alerts by default:
slack.success('Something happened correctly!');
slack.alert('Something important!');

// 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, which is also supported.

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 }
      ]
    }
  ]
});

Running the Test Suite

npm install
npm test

License

MIT. Copyright © 2014-2022 Andrew Childs