1 | ![travis-ci](https://travis-ci.org/chenka/node-slackr.svg)
|
2 |
|
3 | # This module has been deprecated.
|
4 | please move to [Slack offecial API](https://github.com/slackapi/node-slack-sdk)
|
5 |
|
6 | Summary
|
7 | =======
|
8 | A simple node.js library for send notifications to [Slack](https://slack.com/) via Incoming WebHooks.
|
9 |
|
10 |
|
11 | Installation
|
12 | =======
|
13 | You can also install via npm:
|
14 | ```sh
|
15 | npm install node-slackr
|
16 | ```
|
17 |
|
18 | Initialize client:
|
19 |
|
20 | ```js
|
21 | Slack = require('node-slackr');
|
22 | slack = new Slack('https://<incoming-hook-url>');
|
23 | ```
|
24 |
|
25 | Initialize with options:
|
26 | ```js
|
27 | slack = 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 |
|
37 | If channel is not set default channel is *#general*
|
38 | ```js
|
39 | slack.notify("Message"); //without callback
|
40 | slack.notify("Message", function(err, result){
|
41 | console.log(err,result);
|
42 | });
|
43 |
|
44 | ```
|
45 |
|
46 | ### Customized Appearance:
|
47 |
|
48 | You can customize the name and icon of your Incoming Webhook.
|
49 |
|
50 | ```js
|
51 | messages = {
|
52 | text: "Message",
|
53 | channel: "#random",
|
54 | username: "new-bot-name",
|
55 | icon_url: "https://slack.com/img/icons/app-57.png"
|
56 | }
|
57 |
|
58 | slack.notify(messages);
|
59 | ```
|
60 |
|
61 | Send multiple channels:
|
62 | ```js
|
63 | messages = {
|
64 | text: "Message",
|
65 | channel: ["#channel1","#channel2","#channel3"]
|
66 | }
|
67 |
|
68 | slack.notify(messages);
|
69 | ```
|
70 |
|
71 |
|
72 | ### Message Attachments:
|
73 | To 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
|
76 | messages = {
|
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 |
|
99 | slack.notify(messages, function(err, result) {
|
100 | console.log(err, result);
|
101 | });
|
102 |
|
103 | ```
|
104 |
|
105 | ### Documentation
|
106 |
|
107 | For 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)
|