auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const isToday = require('date-fns/isToday')
const parseISO = require('date-fns/parseISO')
// $checkpoint allows you to store workflow-specific state in one
// execution and read it in the next. See the docs:
// https://docs.pipedream.com/workflows/steps/code/#managing-state
const { lastNotificationTime } = $checkpoint || {}
// If we've already sent a notification today, don't send another
// isToday operates relative to UTC, but you can modify this code to be
// timezone-aware: https://date-fns.org/v2.7.0/docs/Time-Zones
if (lastNotificationTime && isToday(parseISO(lastNotificationTime))) {
$end("Already sent a notification today")
}
auths
objectHow many hours in the future to check for meetings
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const addHours = require('date-fns/addHours')
// this.property allows us to "export" its value so we can
// observe it below the code step. See the docs:
// https://docs.pipedream.com/workflows/steps/#step-exports
this.timeMax = addHours(new Date(), params.n)
const { items } = await require("@pipedreamhq/platform").axios(this, {
url: `https://www.googleapis.com/calendar/v3/calendars/primary/events`,
headers: {
Authorization: `Bearer ${auths.google_calendar.oauth_access_token}`,
},
params: {
// Only return meetings from now until the end of our window
timeMin: (new Date()).toISOString(),
timeMax: this.timeMax,
}
})
// Skip all-day events
this.meetings = items.filter(event => event.start && event.start.dateTime && event.end && event.end.dateTime)
// If we have no meetings, exit
if (!this.meetings || !this.meetings.length) {
$end(`No meetings in the next ${params.n} hours`)
}
// Otherwise, proceed
this.message = `You have a meeting this morning: ${this.meetings[0].summary}`
async
params => {
}
const options = {
subject: params.subject,
text: params.text,
}
if (params.html) {
options.html = params.html
}
if (params.include_collaborators) {
options.include_collaborators = params.include_collaborators
}
$send.email(options)
auths
objectChannel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.
Text of the message to send. See below for an explanation of formatting. This field is usually required, unless you're providing only attachments instead. Provide no more than 40,000 characters or risk truncation.
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params, auths) => {
}
const data = {
channel: params.channel,
text: params.text,
as_user: params.as_user,
attachments: params.attachments,
blocks: params.blocks,
icon_emoji: params.icon_emoji,
icon_url: params.icon_url,
link_names: params.link_names,
mrkdwn: params.mrkdwn,
parse: params.parse,
reply_broadcast: params.reply_broadcast,
thread_ts: params.thread_ts,
unfurl_links: params.unfurl_links,
unfurl_media: params.unfurl_media,
username: params.username,
}
const config = {
method: "post",
url: `https://slack.com/api/chat.postMessage`,
headers: {
Authorization: `Bearer ${auths.slack.oauth_access_token}`,
},
params,
}
return await require("@pipedreamhq/platform").axios(this, config)
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// If we made it this far, we need to save the time we sent our
// notification so we don't send another today
$checkpoint = {
lastNotificationTime: (new Date()).toISOString(),
}