UNPKG

2.25 kBMarkdownView Raw
1![travis-ci](https://travis-ci.org/chenka/node-slackr.svg)
2
3Summary
4=======
5A simple node.js library for send notifications to [Slack](https://slack.com/) via Incoming WebHooks.
6
7
8Installation
9=======
10You can also install via npm:
11```sh
12npm install node-slackr
13```
14
15Initialize client:
16
17```js
18Slack = require('node-slackr');
19slack = new Slack('https://<incoming-hook-url>');
20```
21
22Initialize with options:
23```js
24slack = new Slack('https://<incoming-hook-url>',{
25 channel: "#development",
26 username: "slack-bot",
27 icon_url: "http://domain.com/image.png",
28 icon_emoji: ":ghost:"
29});
30```
31
32###Send message:
33
34If channel is not set default channel is *#general*
35```js
36slack.notify("Message"); //without callback
37slack.notify("Message", function(err, result){
38 console.log(err,result);
39});
40
41```
42
43###Customized Appearance:
44
45You can customize the name and icon of your Incoming Webhook.
46
47```js
48messages = {
49 text: "Message",
50 channel: "#random",
51 username: "new-bot-name",
52 icon_url: "https://slack.com/img/icons/app-57.png"
53}
54
55slack.notify(messages);
56```
57
58Send multiple channels:
59```js
60messages = {
61 text: "Message",
62 channel: ["#channel1","#channel2","#channel3"]
63}
64
65slack.notify(messages);
66```
67
68
69###Message Attachments:
70To display a richly-formatted message attachment in Slack, you can use the same JSON payload as above, but add in an attachments array. Each element of this array is a hash containing the following parameters:
71
72```js
73messages = {
74 text: "Server Down",
75 channel: "#alert"
76 attachments: [
77 {
78 fallback: "Detected server down",
79 color: "#36a64f", // Can either be one of 'good', 'warning', 'danger'
80 fields: [
81 {
82 title: "Uptime",
83 value: "30 Hours",
84 short: false
85 },
86 {
87 title: "Downtime",
88 value: "20 Minutes",
89 short: false
90 }
91 ]
92 }
93 ]
94};
95
96slack.notify(messages, function(err, result) {
97 console.log(err, result);
98});
99
100```
101
102###Documentation
103
104For more information such as send URL link, Message Formatting, @mention and Parsing modes, please follow the link below
105
106[Formatting](https://api.slack.com/docs/formatting)
107
108[Incomg Webook](https://my.slack.com/services/new/incoming-webhook)
109
110