forked from evanyeung/terminal-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slackClient.js
108 lines (105 loc) · 2.88 KB
/
slackClient.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
var request = require('request'),
WebSocket = require('ws'),
TOKEN = process.env.SLACK_TOKEN;
module.exports = {
init: function(callback) {
var self = this;
request.get({
url: 'https://slack.com/api/rtm.start',
qs: {
token: TOKEN
}
},
function(error, response, data) {
if (response.statusCode != 200) {
console.log("Error: ", response.statusCode);
return;
}
data = JSON.parse(data);
var ws = new WebSocket(data.url);
callback(data, ws);
});
},
getChannels: function(callback) {
request.get({
url: 'https://slack.com/api/channels.list',
qs: {
token: TOKEN,
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
},
joinChannel: function(name, callback) {
request.get({
url: 'https://slack.com/api/channels.join',
qs: {
token: TOKEN,
name: name
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
},
getChannelHistory: function(id, callback) {
request.get({
url: 'https://slack.com/api/channels.history',
qs: {
token: TOKEN,
channel: id
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
},
markChannel: function(id, timestamp, callback) {
request.get({
url: 'https://slack.com/api/channels.mark',
qs: {
token: TOKEN,
channel: id,
ts: timestamp
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
},
getDMs: function(callback) {
request.get({
url: 'https://slack.com/api/im.list',
qs: {
token: TOKEN
}
},
function(error, response, data) {
if(callback) callback(error,response, data);
});
},
getUsers: function(callback) {
request.get({
url: 'https://slack.com/api/users.list',
qs: {
token: TOKEN,
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
},
getUserName: function(id, callback) {
request.get({
url: 'https://slack.com/api/users.info',
qs: {
token: TOKEN,
user: id
}
},
function(error, response, data) {
if(callback) callback(error, response, data);
});
}
};