MCPcopy Index your code
hub / github.com/andrewchilds/slack-notify

github.com/andrewchilds/slack-notify @v2.0.7

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.7 ↗ · + Follow
14 symbols 30 edges 4 files 0 documented · 0% 2 cross-repo links updated 2y ago★ 2476 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
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: ':computer:',
  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 }
      ]
    }
  ]
});

// Set slack message color

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

Running the Test Suite

npm install
npm test

CJS / ESM support

This library supports CommonJS and ES Modules.

// Require as Common JS:
const SlackNotify = require('slack-notify');

// Import as ES Module:
import SlackNotify from 'slack-notify';

// Either:
const slack = SlackNotify(MY_SLACK_WEBHOOK_URL);

License

MIT. Copyright © 2014-2023 Andrew Childs

Extension points exported contracts — how you extend this code

SlackNotifier (Interface)
(no doc)
src/index.d.ts
SlackNotify (Interface)
(no doc)
src/index.d.ts
SendArgs (Interface)
(no doc)
src/index.d.ts
SendAttachment (Interface)
(no doc)
src/index.d.ts
SendAttachmentField (Interface)
(no doc)
src/index.d.ts

Core symbols most depended-on inside this repo

extend
called by 7
src/index.d.ts
send
called by 6
src/index.d.ts
alert
called by 2
src/index.d.ts
isString
called by 2
src/esm/index.mjs
isString
called by 2
src/cjs/index.js
success
called by 1
src/index.d.ts
bug
called by 1
src/index.d.ts
post
called by 1
src/esm/index.mjs

Shape

Interface 5
Method 5
Function 4

Languages

TypeScript100%

Modules by API surface

src/index.d.ts10 symbols
src/esm/index.mjs2 symbols
src/cjs/index.js2 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add slack-notify \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page