0.1.0 • Published 7 years ago
slack-wh-send v0.1.0
#SlackWhSend
Utility for send Slack Webhook messages in a simple way
##How to use
###npm
npm install --save slack-wh-send
import SlackWhSend from 'slack-wh-send';
const slackWhSend = new SlackWhSend('https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZZZZZZZZ');
##Example
With this code:
import SlackWhSend from '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) {
log('send ' + res);
}).catch(console.error)
We generated this message in Slack:
Or we can use preformated attachments:
import SlackWhSend from '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) {
log('send ' + res);
}).catch(console.error)
And we generated this message in Slack:
0.1.0
7 years ago