Home > OS >  How to share an calendar via link in a web app?
How to share an calendar via link in a web app?

Time:10-15

I'm hoping to create a web app that can create a subscribable calendar for users. This calendar needs to share via a link so that they can add it to a calendar service like google calendar. I have no idea how to create a link to achieve that functionality. Any help?

CodePudding user response:

There are several protocols for calendars! A good start would be here https://en.wikipedia.org/wiki/Web_Calendar_Access_Protocol and here https://en.wikipedia.org/wiki/ICalendar

Essentially you'd have your app generate the XML when the users request the link.

I saw that you're tagging javascript so here are some good repos to look at https://webdav.io/caldav-javascript/ that would allow you to spin up a calendar server!

CodePudding user response:

You'll need to serve a list of calendar events.

On firebase you could write a serverless function to return a list of events from your database with ical-generator

exports.ical= functions.https.onCall((data, context) => {
  // create an ical instance
  const cal = ical({
    url: 'https://mywebsite.com',
    name: 'my calendar',
  });
  
  // get data from database or somewhere else
  const events = [];
  events.push({
    timestamp: new Date(myEvent.created),
    start: new Date(myEvent.start),
    end: new Date(myEvent.end),
    summary: myEvent.title,
    description: myEvent.description,
    location: myEvent.address,
  });
  ...
  
  // send events to the subscriber
  cal.events(events);
  res.status(200).send(cal.toString());
});
  • Related