Urgent.News

What's breaking now, across thousands of outlets.

Tech

Create calendar invites in Node.js that update and cancel cleanly

Create calendar invites in Node.js that update and cancel cleanly Send .ics calendar invites from Node.js with Nodemailer, then move and cancel them without leaving duplicate events in anyone's calendar. Sending one calendar invite is easy. The bugs show up on the second email. You move the meeting by an hour and every attendee now has two events. You cancel it and the event stays on everyone's…

Creating, updating, and canceling calendar invites in Node.js requires following a specific set of rules to avoid duplicate events. These rules are defined in RFC 5546 (iCalendar Transport Protocol) and RFC 5545 (iCalendar).

1. Keep the UID: Every event has a unique UID. Updates and cancellations must reuse the same UID; otherwise, it will be treated as a new event.

2. Increment SEQUENCE: When updating an event, the organizer must increment the SEQUENCE number. Clients ignore updates whose sequence is not higher than what they already have.

3. Match METHOD: The email's calendar part must carry the same METHOD (REQUEST or CANCEL) as the file. If the METHOD does not match, clients treat it as a plain attachment.

To generate the .ics file, there are three common approaches:

1. Hand-written string: This method requires no dependencies and provides full control. However, it involves dealing with line folding, escaping, DTSTAMP, and time zone blocks manually. This approach is suitable for a single static event but may lead to errors due to the sharp edges of the RFC format.

2. ics npm package: This open-source package runs locally and supports UID, SEQUENCE, METHOD, attendees, alarms, and recurrence. It accepts start times in either local or UTC format. However, conversion from named zones to UTC is the responsibility of the developer. This option is suitable when using UTC times or when dealing with a single event.

3. ICS generator API: This approach uses an API that takes JSON input and returns a .ics file or a signed download link for "add to calendar" buttons. It is particularly useful when events come from users in various time zones or when an AI agent is the one creating the events. This method simplifies the process by eliminating the need to handle the .ics file manually.

The provided Node.js script demonstrates how to create, update, and cancel calendar invites using the ICS generator API. It requires Node.js version 18 or later and uses the Nodemailer library to send the invite via email. The script imports the necessary libraries, sets up the API and Transport configurations, and defines functions to build the .ics file, send the invite, and handle updates and cancellations.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Tech Giants Back Andreessen Horowitz’s Alternative Tech Academy

Venture capital firm Andreessen Horowitz launched an alternative school for rising tech talent, The Wall Street Journal reported Tuesday (Sept. 22). The idea is to keep budding entrepreneurs from dropping out of school to launch a company and instead attend the Horowitz Andreessen Academy, according to the report.

More from Tuesday 22 September →