Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 4 days 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 (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-01T20:45:53.000Z (over 7 years ago)
- Last Synced: 2023-12-25T10:42:57.425Z (about 1 year ago)
- Topics: javascript, slack, slack-webhook, slack-webhook-messages
- Language: JavaScript
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# slack-wh-send
[![npm](https://img.shields.io/npm/v/slack-wh-send.svg?style=flat-square)](https://www.npmjs.com/package/slack-wh-send) [![npm](https://img.shields.io/npm/dt/slack-wh-send.svg?style=flat-square)](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:
![](./doc/example-msg.png)
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:
![](./doc/example-msg-2.png)