Check for morning meetings, alert if I have one so I make it to work
@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.
check_last_notification_time
auth
to use OAuth tokens and API keys in code via theauths object
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) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
}
16
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")
}
steps.
list_events_in_next_n_hours
auth
to use OAuth tokens and API keys in code via theauths object
(auths.google_calendar)
params
N Hours Out

How many hours in the future to check for meetings

2
integer ·params.n
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, auths) => {
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
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}`
steps.
email_me
Customize and send an email to the email address you registered with Pipedream. The email will be sent by notifications@pipedream.com.
params
Subject
{{steps.list_events_in_next_n_hours.message}}
string ·params.subject
Text
Go to work!
string ·params.text
Optional
code
async params => {
1
2
3
4
5
6
7
8
9
10
11
12
}
13
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)
steps.
chat_post_message
auth
to use OAuth tokens and API keys in code via theauths object
(auths.slack)
params
Channel

Channel, private group, or IM channel to send message to. Can be an encoded ID, or a name. See below for more details.

 
C1234567890
string ·params.channel
Text

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.

 
Hello world
string ·params.text
Optional
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, auths) => {
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
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)
steps.
save_last_notification_time
auth
to use OAuth tokens and API keys in code via theauths object
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) => {
1
2
3
4
5
6
}
7
// 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(),
}