-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (37 loc) · 908 Bytes
/
index.js
File metadata and controls
39 lines (37 loc) · 908 Bytes
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
const Calendar = require("ics");
const moment = require("moment");
exports.handler = (request, context, callback) => {
var {
title,
description,
start,
duration,
organizer,
location,
url
} = request.queryStringParameters;
var dateArray = `[${moment(start, "h A D MMM").format("YYYY, M, D, H, m")}]`;
Calendar.createEvent(
{
url,
title,
description,
location,
status: "CONFIRMED",
organizer: { name: organizer },
start: JSON.parse(dateArray),
duration: { minutes: duration || 60 }
},
(err, event) => {
callback(err, {
isBase64Encoded: false,
statusCode: err ? "400" : "200",
headers: {
"Content-type": "text/calendar",
"Content-Disposition": `inline; filename="${title}.ics`
},
body: err ? err.message : event.toString()
});
}
);
};