A while ago I had the idea to build my own workflow for keeping my Slack status up-to-date using events in my calendar and Pipedream. The main hurdle I ran into was that Pipedream doesn’t support triggering a workflow when an event starts. The out-of-the-box Google Calendar Event Start Source does support emitting an event a certain amount of time before the calendar event starts, but it uses polling—meaning if you want an event emitted 1 hour before any calendar event starts, Pipedream has to check at least every hour… the bottom line: the closer to the start you want to get, the more frequently Pipedream has to check, and the more of your limits are used up 😬.
This approach isn’t the fault of Pipedream, it’s mostly just a limitation of the Google Calendar API! Ideally, Google would expose a webhook we could subscribe to, but alas, they do not 😞.
I never ended up building out the full workflow because I started using Clockwise, which effectively does what I wanted anyway, among a bunch of other useful things. But I did discover a way to trigger a Pipedream workflow whenever a calendar event starts, without eating up my limits! The rest of this post will cover how to set this up for yourself!
In short, we will:
1. Setup event notifications to send an email whenever an event starts2. Auto-forward event notifications to Pipedream3. Find the event ID in the email4. Use the event ID to get event data via API
A limitation of this approach is that Out of Office events do not send email notifications and therefore will not trigger the Pipedream workflow.
1. Setup event notifications to send an email whenever an event starts
Go to Google Calendar settings for your desired calendar and configure an event notification for email, 0 minutes. This will send you an email right when any event starts.
2. Auto-forward event notifications to Pipedream
Create an email-triggered workflow in Pipedream and copy the address to use in the forwarding rule.
Configure a forwarding rule to send emails from
calendar-notification@google.com
to the workflow you just created. I also send it straight to trash so I don’t have to deal with it in my inbox. If you already leverage Google Calendar email notifications for other purposes, you may have to get more specific with the filter criteria.
Once you’ve saved the filter, Google will send a test email to the address, containing a code you will use to confirm the forwarding rule. View the test email event in Pipedream and grab the code from the
event.body.html
or event.body.text
property.3. Find the event ID in the email
Once the workflow receives the email, we want to find the event ID in it so we can retrieve structured event data via the API.
Each notification email contains a link to view the event. The link URL contains an
eid
parameter—you would think this is just an abbreviated form of “event ID”, but it’s actually the event ID and the calendar ID encoded together. Thankfully it’s straightforward to decode and separate the two. For more detail, see the code snippet below, which finds the
eid
value in the email and parses out the event ID from it. The snippet can be copy/pasted directly into a Pipedream Node.js step. export default defineComponent({ async run({ steps, $ }) { const eidMatch = /eid=(\w+)/.exec(steps.trigger.event.body.html); if (!eidMatch || !eidMatch[1]) { throw Error('Unable to find eid in HTML body.'); } // event ids are always base32hex, sometimes containing a timestamp // see docs for creating an event https://developers.google.com/calendar/api/v3/reference/events // the decoded eid looks like `{event id} {calendar id}` return Buffer.from(eidMatch[1], 'base64').toString('ascii').split(' ')[0]; }, })
eid
and parse the event ID from it.4. Use the event ID to get event data via API
Now that we have the event ID, we can use the standard Google Calendar component to retrieve structured event data, and we can act upon the event however we want!
And here’s the full workflow!