forked from SarahSexton/MeetupBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreminder.js
44 lines (39 loc) · 1.35 KB
/
reminder.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
var Botkit = require("botkit");
var controller = Botkit.slackbot();
var https = require("https");
var meetupKey = process.env.MEETUP_KEY;
var today = new Date();
if (today.getDay() !== 1){
process.exit();
}
var options = {
weekday: "long", year: "numeric", month: "short",
day: "numeric", hour: "2-digit", minute: "2-digit"
};
var bot = controller.spawn({
token: process.env.SLACK_TOKEN
}).startRTM(function(){
https.get("https://api.meetup.com/self/calendar" + "?key=" + meetupKey + "&page=5&fields=plain_text_description", function (res)
{
var buffer = "", mupdata;
res.on('data', function (d) { buffer += d; });
res.on('end', function (err) {
mupdata = JSON.parse(buffer);
for (var i=0; i < mupdata.length; i++){
var date = new Date(mupdata[i].time);
var venueInfo = mupdata[i].venue ? mupdata[i].venue.name + " (" + mupdata[i].venue.address_1 + ")\n" : ""
bot.send({text: "*" + mupdata[i].name + "*\n" +
date.toLocaleTimeString("en-us", options) + "\n" +
venueInfo +
mupdata[i].link.replace(/https?:\/\//,"") + "\n" +
"========================================",
unfurl_links: false,
unfurl_media: false,
channel: 'C25F7DFK9'
});
}
});
}).on('error', function (e) {
console.error(e);
});
});