auths
objectThe iCal URL to fetch events from
The URL you want to send a webhook to
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
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
})
}
}