-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
37 lines (32 loc) · 1.02 KB
/
app.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
require('dotenv').config();
const Influx = require('./lib/influx');
const SlackBot = require('slackbots');
const Weather = require('./lib/weather');
// Create & Configure Slackbot
let bot = new SlackBot({
token: process.env.SLACK_API_TOKEN,
name: process.env.SLACK_BOT_NAME,
});
let channel = process.env.SLACK_CHANNEL;
let params = {icon_emoji: ':wu:'};
let updateFrequency = process.env.UPDATE_FREQUENCY;
// Alert To Slax=ck We have Started
bot.postMessageToGroup(channel, 'Portland Weather Has Started', params);
// Catch errors
bot.on('error', (data) => {
console.log(data);
});
function getData() {
Weather.getData().then(Influx.writeInflux).then(function() {
setTimeout(getData, updateFrequency);
}).catch(function(e) {
bot.postMessageToGroup(channel, 'Error: ' + e.message);
console.log('Error: ' + e.message);
// Retry on error, but timeout for 5 minutes
setTimeout(getData, 300000);
});
};
// Start after 10 seconds
setTimeout(function() {
getData();
}, 10000);