JSPM

slackless

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q22627F
  • License MIT

Lightweight Slack package for Node.

Package Exports

  • slackless

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 (slackless) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Slackish

A lightweight module providing the functionality to send messages to Slack.

Installation

npm install slackless

Usage

Initialization

var slack = require('slackless')('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX');

The URL that you need to input is acquired when setting up incoming webhooks for your Slack domain. https://YOUR_DOMAIN.slack.com/apps/manage/custom-integrations

Set global options

slack.setUsername('B0T');
slack.setIcon('ghost');
slack.setChannel('general');

Send message

slack.send('Test message.');

or

slack.send({
    text: 'Test message.'
});

Send message with attachments

slack.send({
    text: 'Test message.',
    attachments: [
        {
            "fallback": "Required plain-text summary of the attachment.",
            "color": "#36a64f",
            "pretext": "Optional text that appears above the attachment block",
            "author_name": "Bobby Tables",
            "author_link": "http://flickr.com/bobby/",
            "author_icon": "http://flickr.com/icons/bobby.jpg",
            "title": "Slack API Documentation",
            "title_link": "https://api.slack.com/",
            "text": "Optional text that appears within the attachment",
            "fields": [
                {
                    "title": "Priority",
                    "value": "High",
                    "short": false
                }
            ],
            "image_url": "http://my-website.com/path/to/image.jpg",
            "thumb_url": "http://example.com/path/to/thumb.png",
            "footer": "Slack API",
            "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
            "ts": 123456789
        }
    ]
});

Override global options when sending the message

slack.send({
    text: 'Test message.',
    icon_emoji: 'banana', // Will override the icon set using setIcon().
    username: 'B0T', // Will override the username set using setUsername().
    channel: '#general' // Will override the channel set using setChannel().
});

Tests

npm test

Release History

  • 1.0.1 - 2017-02-29

    Updated error handling.
    Fixed a bug when icon wasn't set.

  • 1.0.0 - 2017-02-28

    Initial release