-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
49 lines (40 loc) · 1.29 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
var Botkit = require('botkit')
var Witbot = require('witbot')
var slackToken = process.env.SLACK_TOKEN
var witToken = process.env.WIT_TOKEN
var openWeatherApiKey = process.env.OPENWEATHER_KEY
var controller = Botkit.slackbot({
debug: false
})
controller.spawn({
token: slackToken
}).startRTM(function (err, bot, payload) {
if (err) {
throw new Error('Error connecting to slack: ', err)
}
console.log('Connected to slack')
})
var witbot = Witbot(witToken)
controller.hears('.*', 'direct_message,direct_mention', function (bot, message) {
witbot.process(message.text, bot, message)
})
witbot.hears('hello', 0.5, function (bot, message, outcome) {
bot.reply(message, 'Hello to you as well!')
})
var weather = require('./weather')(openWeatherApiKey)
witbot.hears('weather', 0.5, function (bot, message, outcome) {
console.log(outcome.entities.location)
if (!outcome.entities.location || outcome.entities.location.length === 0) {
bot.reply(message, 'I\'d love to give you the weather but for where?')
return
}
var location = outcome.entities.location[0].value
weather.get(location, function (error, msg) {
if (error) {
console.error(error)
bot.reply(message, 'uh oh, there was a problem getting the weather')
return
}
bot.reply(message, msg)
})
})