forked from TeamNovaSoft/novabot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar.js
More file actions
47 lines (38 loc) · 1.27 KB
/
calendar.js
File metadata and controls
47 lines (38 loc) · 1.27 KB
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
const { google } = require('googleapis');
const path = require('path');
const fs = require('fs');
const { FIREBASE_CONFIG } = require('./src/config');
const credentialsPath = path.join(__dirname, 'google-keys.json');
if (
!fs.existsSync(credentialsPath) &&
FIREBASE_CONFIG.scheduledCalendarEnabled
) {
throw new Error('The credential file do not exist. Verify route.');
}
const auth = new google.auth.GoogleAuth({
keyFile: credentialsPath,
scopes: FIREBASE_CONFIG.scopes,
});
const calendar = google.calendar({ version: 'v3', auth });
async function listEvents() {
const now = new Date();
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
const endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0);
const response = await calendar.events.list({
calendarId: FIREBASE_CONFIG.email,
timeMin: startOfMonth,
timeMax: endOfMonth,
singleEvents: true,
orderBy: 'startTime',
});
const events = response.data.items;
return events.map((event) => {
return {
summary: event.summary,
start: { dateTime: event.start.dateTime, timeZone: event.start.timeZone },
end: { dateTime: event.end.dateTime, timeZone: event.end.timeZone },
hangoutLink: event.hangoutLink,
};
});
}
module.exports = { listEvents };