/r/doggos subreddit top posts -> Slack
@dylburger
code:
data:privatelast updated:4 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 800,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.
fetch_top_reddit_post
auth
to use OAuth tokens and API keys in code via theauths object
(auths.reddit)
params
Name of subreddit (without /r/)
doggos
string ·params.subreddit
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
// You can use any npm package using just a require()
const axios = require("axios")

// Click Connect Account below to connect your Reddit account.
// The access token and other Reddit auth info is exposed in 
// your code in the 'auths.reddit' object.
const { oauth_access_token, oauth_uid } = auths.reddit

// The "Subreddit" you enter in the form below this step
// is passed as 'params.subreddit' here.
const { subreddit } = params

// Saving data to properties of 'this' exports that data,
// making it available to other steps.
this.story = (await axios({
  method: "GET",
  url: `https://oauth.reddit.com/r/${subreddit}/hot`,
  headers: {
    "Authorization": `Bearer ${oauth_access_token}`,
    "User-Agent": `pipedream/u/${oauth_uid}`
  }
})).data.data.children[0].data // Story data is deeply nested in the Reddit API response
steps.
check_stories_processed_so_far
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
// We save the stories we've seen before to the $checkpoint 
// variable. You can think of $checkpoint like a key-value 
// store specific to a workflow. You can read the contents of
// $checkpoint in future executions of our workflow.
// See https://docs.pipedream.com/workflows/steps/code/#managing-state
const { id } = steps.fetch_top_reddit_post.story 
if ($checkpoint && $checkpoint.lastStoryId && $checkpoint.lastStoryId === id) {
  $end(`We've already processed story ${id}. Exiting`)
} 

$checkpoint = {
  lastStoryId: id,
}
steps.
send_to_slack
auth
to use OAuth tokens and API keys in code via theauths object
(auths.slack)
params
Slack Channel
 
string ·params.channel
Bot username
Doggo bot
string ·params.bot_username
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
const axios = require("axios")
const { WebClient } = require('@slack/web-api')

// The "Channel" you enter in the form below this step
// is passed as params.channel here.
const { channel, bot_username } = params

const { permalink, title } = steps.fetch_top_reddit_post.story
const url = `https://reddit.com${permalink}`
const text = `*${title}* : ${url}`

// Send to Slack
const web = new WebClient(auths.slack.oauth_access_token)
await web.chat.postMessage({
  channel,
  text,
  as_user: false,
  username: bot_username,
})