Send a calendar on Discord using node-red

I translated the flow from french but didn't test it ! Use with caution !

I create a discord bot to read LabSud calendar and display new workshops.

However, It was harder then I thought to convert the ical format to something readable.
I didn't find any plugins which do this 😐
Ical format isn't that hard to read so it wasn't really an issue.
It is far from being optimised but it works!

There was a problem when I compare the saved calendar with the current version, when I read the file, it add a \n at then end, so I added a function bug which remove it.

In order to keep the new version of the calendar, i put it inside a flow variable.

If there isn't any new workshop, it will discard it and doesn't send a new message on discord.

I should have compare the raw version of the calendar, but the DSTAMP variable change at each request so it was a pain in the ass.

Here is a tutorial on how to create a bot on discord : https://www.freecodecamp.org/news/how-to-create-a-discord-bot-under-15-minutes-fb2fd0083844/

Here is the flow (pro-tip credentials is not saved inside flows)

Dependencies (manage palettes)

  • node-red-contrib-fs-ops
  • node-red-contrib-discord

Node to change

  • Retrieve HTTP ical (link to ical)
  • Calendar.xml exists ? (Path / Filename)
  • Read calendar.xml (Path / Filename)
  • Create calendar.xml (Path / Filename)
  • Write calendar.xml (Path / Filename)
  • Send to Discord (Token Discord / Channel ID)
  • Delete calendar.xml