-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·59 lines (50 loc) · 1.54 KB
/
index.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
#!/usr/bin/env node
// API Token from https://api.slack.com/web
function slackClient (apiToken, logseneToken) {
var Slack, autoMark, autoReconnect, slack, slackToken
Slack = require('@slack/client').RtmClient
slackToken = apiToken; autoReconnect = true
autoMark = true
slack = new Slack(slackToken, {logLevel: 'error'})
var Logsene = require('logsene-js')
var logger = new Logsene (logseneToken)
//new Slack(slackToken, autoReconnect, autoMark)
slack.on('authenticated', function (slack) {
return console.log('Connected to ' + slack.team.name + ' as @' + slack.self.name)
})
slack.on('message' , function (message) {
var channel = slack.dataStore.getChannelGroupOrDMById(message.channel);
//var channel = slack.getChannelGroupOrDMByID(message.channel)
var u = slack.dataStore.getUserById(message.user)
if (!u) {
u = {}
}
if (!u.profile) {
u.profile = {}
}
var msg = {
userName: u.name,
userImage: u.profile.image_48,
userFirstName: u.profile.first_name,
userLastName: u.profile.last_name,
channel: channel.name,
message: message.text,
'@timestamp': new Date()
}
logger.log ('info', msg.message, msg)
console.log(msg)
})
slack.on('error', function (err) {
return console.error('Error', err)
})
slack.login()
}
if(!process.argv[2]) {
console.error('Missing Slack Web API token')
process.exit(1)
}
if(!process.argv[3]) {
console.error('Missing Logsene APP token')
process.exit(1)
}
slackClient(process.argv[2], process.argv[3])