npm i -S slack-webhook
Setup an incoming webhook and copy the webhook url. This is the only required parameter to initialize the module.
var SlackWebhook =var slack = 'https://hooks.slack.com/services/your/webhook/url'
Optionally, you can pass in a
defaults attribute to set defaults for the webhook's
channel. If no
defaults attribute is used, it will default to the configuration that was used on the set up page.
var slack = 'https://hooks.slack.com/services/your/webhook/url'defaults:username: 'Bot'channel: '#general'icon_emoji: ':robot_face:'
Sending a message
There are two ways to send a message. The first is by passing a string as the argument.
The second is to pass a payload. Any options you pass in here will override the default ones you created at initialization.
Both versions return a promise.
Configuring Promise Library
By default, this module uses Node >= v4's
Promise object, but you can configure it to use your preferred
// define it on initializationvar bluebird =var slack = 'https://hooks.slack.com/services/your/webhook/url'Promise: bluebird// define it after initializationvar q =var slack = 'https://hooks.slack.com/services/your/webhook/url'slackPromise = qPromise