Parse iCal events, send webhook when event starts
@dylan
code:
data:privatelast updated:5 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
Cron Scheduler
Deploy to configure a custom schedule
This workflow runs on Pipedream's servers and is triggered on a custom schedule.
steps.
parse_ical
auth
to use OAuth tokens and API keys in code via theauths object
params
iCalendar URL

The iCal URL to fetch events from

 
https://data.nba.net/prod/teams/schedules/2019/thunder_schedule.ics
string ·params.icalurl
HTTP URL

The URL you want to send a webhook to

 
string ·params.url
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
}
37
const differenceInSeconds = require('date-fns/differenceInSeconds')
const get = require("lodash.get")
const ical = require('node-ical')
const moment = require('moment-timezone')

// Adjust as necessary
const FREQUENCY_IN_SECONDS = 60

// We need to massage the format returned by node-ical
// to retrieve the TZ of the calendar and the events
const parsedCal = await ical.async.fromURL(params.icalurl)
// https://docs.pipedream.com/workflows/steps/#step-exports
this.tz = get(Object.values(parsedCal)[0], 'tzid') | 'Etc/UTC'

const events = Object.values(parsedCal).filter(el => el.type === 'VEVENT')
this.eventCount = events.length
this.sampleEvent = events[0]

// Collect start dates, see if any start dates just passed
const now = new Date()

for (const event of events) {
  const { start, summary } = event
  const startDate = moment.tz(start, this.tz).utc().toDate()
  const diff = differenceInSeconds(now, startDate)
  if (diff > 0 && diff < FREQUENCY_IN_SECONDS) {
    // Send the HTTP request.
    // https://docs.pipedream.com/destinations/http/#using-send-http
    $send.http({
      method: "POST",
      url: params.url,
      data: event,  // Send the whole calendar event in the payload
    })
  }
}