UNPKG

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