forked from evanyeung/terminal-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_test.js
More file actions
45 lines (37 loc) · 981 Bytes
/
Copy pathdev_test.js
File metadata and controls
45 lines (37 loc) · 981 Bytes
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
var request = require('request'),
WebSocket = require('ws'),
TOKEN = 'xoxp-4806430644-4806430646-4828204363-89ebec';
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);
console.log(data.url);
var ws = new WebSocket(data.url);
ws.on('open', function() { console.log('Opened!'); });
ws.on('message', function(data, flags) {
console.log('Message!');
console.log(data);
});
getChannels(function(error, response, data){
console.log(data);
});
});
function getChannels(callback) {
request.get({
url: 'https://slack.com/api/channels.list',
qs: {
token: TOKEN,
}
},
function(error, response, data) {
callback(error, response, data);
});
}