# slack-webhook

> Send messages to slack incoming webhook

Latest version **1.0.0** (published 2016-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install slack-webhook
pnpm add slack-webhook
yarn add slack-webhook
bun add slack-webhook
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-04-20 |
| First published | 2016-02-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Patt-tom McDonnell |
| Maintainers | pthm |

## Links

- npm: https://www.npmjs.com/package/slack-webhook
- Repository: https://github.com/pthm/slack-webhook
- Issues: https://github.com/pthm/slack-webhook/issues
- npm.io page: https://npm.io/package/slack-webhook

## Recent versions

- 1.0.0 (latest) — 2016-04-20
- 0.2.1 — 2016-02-09
- 0.2.0 — 2016-02-08
- 0.1.0 — 2016-02-08
- 0.0.1 — 2016-02-08
- 0.0.0 — 2016-02-08

## README

# slack-webhook

## Installation

```bash
npm i -S slack-webhook
```

## Usage

### Initialization

Setup an [incoming webhook](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks) and copy the webhook url. This is the only required parameter to initialize the module.

```js
var SlackWebhook = require('slack-webhook')

var slack = new SlackWebhook('https://hooks.slack.com/services/your/webhook/url')
```

Optionally, you can pass in a `defaults` attribute to set defaults for the webhook's `username`, `icon_emoji` and `channel`. If no `defaults` attribute is used, it will default to the configuration that was used on the set up page.

```js
var slack = new SlackWebhook('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.

```js
slack.send('some text')
```

The second is to pass a payload. Any options you pass in here will override the default ones you created at initialization.

```js
slack.send({
  text: 'some text',
  attachments: [
    // optional attachment data
  ],
  username: 'new username',
  icon_emoji: ':scream_cat:',
  channel: '#another-channel'
})
```

Both versions return a promise.

```js
slack.send('some text').then(function (res) {
  // succesful request
}).catch(function (err) {
  // handle request error
})
```

### Configuring Promise Library

By default, this module uses Node >= v4's `Promise` object, but you can configure it to use your preferred `Promise` library.

```js
// define it on initialization
var bluebird = require('bluebird')
var slack = new SlackWebhook('https://hooks.slack.com/services/your/webhook/url', {
  Promise: bluebird
})

// define it after initialization
var q = require('q')
var slack = new SlackWebhook('https://hooks.slack.com/services/your/webhook/url')
slack.Promise = q.Promise
```

## Tests

```
npm t
```

---
_Source: https://npm.io/package/slack-webhook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
