punwave-slack-notifier

0.2.0 • Public • Published

punwave-slack-notifier

NPM version Build Status Coverage Status

Code friendly notifier to send messages to Slack channel via webhook

Install

$ npm install --save punwave-slack-notifier

Usage

const SlackNotifier = require('punwave-slack-notifier')
 
const notifier = new SlackNotifier(WEBHOOK_URL, {
  channel: '#general',
  username: 'webhookbot',
})
 
notifier.send({
  text: 'This is a line of text.\nAnd this is another one.'
}, (err, response) => {
  if (err) console.error(err)
  console.log(response)
})

API

notifier.send(options, callback)

Send message to Slack channel.


Options

For setting attachement of message, please see Slack API documentation for reference.

options.text

If you want to display some specific information, such as error stack trace, JavaScript object information or JSON (JavaScript Object Notation) formatted string for notifications, you can pass { text: [{ title: TITLE, code: CODE }] } for options to create code blocks.

options.attachements

It used for customizing your notifications.

If your pass { attachements: [] } for options, it will override default settings.


notifier.success(options, callback)

Send message that indicates a successful or positive action to Slack channel.


notifier.warning(options, callback)

Send message that indicates a warning that might need attention to Slack channel.


notifier.danger(options, callback)

Send message that indicates a dangerous or potentially negative action to Slack channel.

License

MIT

Package Sidebar

Install

npm i punwave-slack-notifier

Weekly Downloads

0

Version

0.2.0

License

MIT

Last publish

Collaborators

  • chunkai1312