https://github.com/lmfresneda/slack-wh-send
Utility for send Slack Webhook messages in a simple way
https://github.com/lmfresneda/slack-wh-send
javascript slack slack-webhook slack-webhook-messages
Last synced: 2 months ago
JSON representation
Utility for send Slack Webhook messages in a simple way
- Host: GitHub
- URL: https://github.com/lmfresneda/slack-wh-send
- Owner: lmfresneda
- License: mit
- Created: 2017-02-20T17:26:13.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-01T20:45:53.000Z (almost 9 years ago)
- Last Synced: 2026-03-28T12:40:57.256Z (3 months ago)
- Topics: javascript, slack, slack-webhook, slack-webhook-messages
- Language: JavaScript
- Size: 36.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# slack-wh-send
[](https://www.npmjs.com/package/slack-wh-send) [](https://www.npmjs.com/package/slack-wh-send)
Utility for send Slack Webhook Messages in a simple way
## How to use
```bash
npm install --save slack-wh-send
```
```js
const SlackWhSend = require('slack-wh-send');
const slackWhSend = new SlackWhSend('https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ');
```
## Example
With this code:
```js
const SlackWhSend = require('slack-wh-send');
const slackWhSend = new SlackWhSend('https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ');
slackWhSend
.init('Pretext on message')
.username('lmfresneda')
.channel('#random')
.icon(':space_invader:')
.newAttachment('This is the new attachment number 1')
.color('good')
.author('Luis Miguel')
.footer('My footer')
.footerValue('For my awesome footer')
.newAttachment('This is the new attachment number 3')
.color('#BDBDBD')
.field('A field')
.fieldMessage('Message for field')
.newAttachment('This is the new attachment number 2')
.color('danger')
.defaultFooter()
.send().then(function (res) {
console.log('send ' + res);
}).catch(console.error)
```
We generated this message in Slack:

Or we can use preformated attachments:
```js
const SlackWhSend = require('slack-wh-send');
const slackWhSend = new SlackWhSend('https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ');
const attachments = [
{
"text": "Error service in blablabla...",
"color": "danger",
"author_name": "Log client service xxx",
"fields": [
{
"title": "Type",
"value": "Error",
"short": true
}
],
"footer": "Date",
"ts": 1487430840
}
]
slackWhSend
.init('Pretext on message')
.username('log_error')
.channel('#errors')
.icon(':space_invader:')
.useAttachments(attachments) // use my attachments
.send().then(function (res) {
console.log('send ' + res);
}).catch(console.error)
```
And we generated this message in Slack:
