UNPKG

3.63 kBJavaScriptView Raw
1var icalToolkit = require('ical-toolkit')
2var sendmail = require('../sendmail')({silent: true})
3
4// Create a builder
5var builder = icalToolkit.createIcsFileBuilder()
6
7/*
8 * Settings (All Default values shown below. It is optional to specify)
9 * */
10builder.spacers = true // Add space in ICS file, better human reading. Default: true
11builder.NEWLINE_CHAR = '\r\n' // Newline char to use.
12builder.throwError = false // If true throws errors, else returns error when you do .toString() to generate the file contents.
13builder.ignoreTZIDMismatch = true // If TZID is invalid, ignore or not to ignore!
14
15/**
16 * Build ICS
17 * */
18
19// Name of calander 'X-WR-CALNAME' tag.
20builder.calname = 'Yo Cal'
21
22// Cal timezone 'X-WR-TIMEZONE' tag. Optional. We recommend it to be same as tzid.
23builder.timezone = 'america/new_york'
24
25// Time Zone ID. This will automatically add VTIMEZONE info.
26builder.tzid = 'america/new_york'
27
28// Method
29builder.method = 'REQUEST'
30
31// Add events
32builder.events.push({
33
34 // Event start time, Required: type Date()
35 start: new Date(),
36
37 // Event end time, Required: type Date()
38 end: new Date(),
39
40 // transp. Will add TRANSP:OPAQUE to block calendar.
41 transp: 'OPAQUE',
42
43 // Event summary, Required: type String
44 summary: 'Test Event',
45
46 // All Optionals Below
47
48 // Alarms, array in minutes
49 alarms: [15, 10, 5],
50
51 // Optional: If you need to add some of your own tags
52 additionalTags: {
53 'SOMETAG': 'SOME VALUE'
54 },
55
56 // Event identifier, Optional, default auto generated
57 uid: null,
58
59 // Optional, The sequence number in update, Default: 0
60 sequence: null,
61
62 // Optional if repeating event
63 repeating: {
64 freq: 'DAILY',
65 count: 10,
66 interval: 10,
67 until: new Date()
68 },
69
70 // Optional if all day event
71 allDay: true,
72
73 // Creation timestamp, Optional.
74 stamp: new Date(),
75
76 // Optional, floating time.
77 floating: false,
78
79 // Location of event, optional.
80 location: 'Home',
81
82 // Optional description of event.
83 description: 'Testing it!',
84
85 // Optional Organizer info
86 organizer: {
87 name: 'Jason Humphrey',
88 email: 'jason@yourdomain.com',
89 sentBy: 'person_acting_on_behalf_of_organizer@email.com' // OPTIONAL email address of the person who is acting on behalf of organizer.
90 },
91
92 // Optional attendees info
93 attendees: [
94 {
95 name: 'A1', // Required
96 email: 'a1@email.com', // Required
97 status: 'TENTATIVE', // Optional
98 role: 'REQ-PARTICIPANT', // Optional
99 rsvp: true // Optional, adds 'RSVP=TRUE' , tells the application that organiser needs a RSVP response.
100 },
101 {
102 name: 'A2',
103 email: 'a2@email.com'
104 }
105 ],
106
107 // What to do on addition
108 method: 'PUBLISH',
109
110 // Status of event
111 status: 'CONFIRMED',
112
113 // Url for event on core application, Optional.
114 url: 'http://google.com'
115})
116
117// Optional tags on VCALENDAR level if you intent to add. Optional field
118builder.additionalTags = {
119 'SOMETAG': 'SOME VALUE'
120}
121
122// Try to build
123var icsFileContent = builder.toString()
124
125// Check if there was an error (Only required if yu configured to return error, else error will be thrown.)
126if (icsFileContent instanceof Error) {
127 console.log('Returned Error, you can also configure to throw errors!')
128 // handle error
129}
130
131sendmail({
132 from: 'test@yourdomain.com',
133 to: 'info@yourdomain.com',
134 replyTo: 'jason@yourdomain.com',
135 subject: 'MailComposer sendmail',
136 html: 'Mail of test sendmail ',
137 alternatives: [{
138 contentType: 'text/calendar; charset="utf-8"; method=REQUEST',
139 content: icsFileContent.toString()
140 }]
141}, function (err, reply) {
142 console.log(err && err.stack)
143 console.dir(reply)
144})
145