Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate ics files directly #44

Open
jaredlt opened this issue Apr 29, 2023 · 4 comments
Open

Generate ics files directly #44

jaredlt opened this issue Apr 29, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@jaredlt
Copy link
Owner

jaredlt commented Apr 29, 2023

Currently, we generate a data-uri for iCal which can be used to download an .ics file.

But if we want to attach an .ics file to emails, we need to generate it directly (otherwise the url encoding for the data-uri borks the calendar display when imported into a calendar.

image

@jaredlt jaredlt added the enhancement New feature or request label Apr 29, 2023
@jaredlt
Copy link
Owner Author

jaredlt commented Apr 30, 2023

I don't currently need this feature, but if someone does let me know as I'd be willing to implement it.

@jaredlt
Copy link
Owner Author

jaredlt commented Oct 13, 2023

CGI.unescape(cal.ical_url) and then handle last edge cases

@hegwin
Copy link

hegwin commented Sep 26, 2024

Hi! I also need this feature.
Currently, the following works when users are viewing HTML in browers:

<a download="calendar-event.ics" href="<%= @cal.ical_url %>">Download iCal</a>

But when I send this HTML partial in an email as a event reminder, it won't work because the download link is escaped/removed by the email provide such as Google.

As an alternative, I'd like to send the ICS file directly for the link Add to iCal in the email, so it won't be blocked.

@jared-thoughtbot
Copy link
Collaborator

@hegwin sorry for the mega delay. Life and all that 🙃

I took a quick look at this and you can generate an ICS file like so:

cal = AddToCalendar::URLs.new(start_datetime: Time.new(2020,12,12,13,30,00,0), title: "Christmas party!", timezone: 'Europe/London')

ical_without_data_prefix = cal.ical_url.delete_prefix("data:text/calendar;charset=utf8,")

ical_file_content = URI.decode_www_form_component(ical_without_data_prefix)

File.open("event_filename.ics", "w") { |file| file.write(ical_file_content) }

There might be a weird extra \ occasionally in the ics file if you've added manual newlines in the description or commas in the location but it should still work fine. Have a go and let me know how you get on :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants