auths
objectThe name of the channel. It's how people refer to your service. If you have an HTML website that contains the same information as your RSS file, the title of your channel should be the same as the title of your website.
Phrase or sentence describing the channel.
The URL to the HTML website corresponding to the channel.
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
const get = require("lodash.get")
const isEqual = require("lodash.isequal")
// Parse hostname from URL to generate feedLinks below
// You can make GET requests to /rss, /json, or /atom
// to retrieve these feeds
const hostname = new URL(event.url).hostname
this.rssFeedLink = `https://${hostname}/rss`
this.jsonFeedLink = `https://${hostname}/json`
this.atomFeedLink = `https://${hostname}/atom`
// We only add the required options here, but you can add
// any of the options from https://www.npmjs.com/package/feed
// See https://validator.w3.org/feed/docs/rss2.html for a
// full description of each element
const { title, description, link } = params
const feedOptions = {
title,
description,
link,
id: link,
feedLinks: {
rss: this.rssFeedLink,
json: this.jsonFeedLink,
atom: this.atomFeedLink,
},
}
// If feedOptions has changed (e.g. if you changed Feed Title),
// save to workflow state.
const savedFeedOptions = get($checkpoint, "feedOptions")
if (!isEqual(savedFeedOptions, feedOptions)) {
// If this is our first time running the workflow,
// $checkpoint will be undefined. Instantiate it to be an object
if (!$checkpoint) $checkpoint = {}
$checkpoint.feedOptions = feedOptions
}
this.feedOptions = feedOptions
auths
objectThe API key you'd like to require on inbound POST requests
return
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps, params) => {
}
const get = require("lodash.get")
// Send an HTTP POST request to add a new item to the feed
// From the RSS spec (https://validator.w3.org/feed/docs/rss2.html):
// "All elements of an item are optional, however at least one of title or description must be present."
// The body of the request must match the properties the feed package
// expects in the addItem method: https://www.npmjs.com/package/feed
if (event.method === "POST") {
// Require secret is present on requests to add items to the feed
if (params.secret !== event.headers.secret) {
$end("Invalid secret")
}
// Get any items stored in state
// This keeps the last MAX_ITEMS items POSTed to this feed
MAX_ITEMS = 15
const items = get($checkpoint, "items", [])
if (items.length > MAX_ITEMS) {
items.shift()
}
items.push(event.body)
if (!$checkpoint) $checkpoint = {}
$checkpoint.items = items
$respond({
body: {
success: true,
msg: "Saved new item to feed"
}
})
$end("Saved new item to feed")
}
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const Feed = require('feed').Feed;
const get = require("lodash.get")
// Build feed object from channel metadata generated above
const feed = new Feed(steps.rss_channel_metadata.feedOptions)
const items = get($checkpoint, "items", [])
for (const item of items) {
feed.addItem(item)
}
// Did the user issue a GET request to retrieve feed data?
if (event.method === "GET") {
this.pathname = new URL(event.url).pathname
let body
switch (this.pathname) {
case '/rss':
body = feed.rss2()
break
case '/json':
body = feed.json1()
break
case '/atom':
body = feed.atom1()
break
default:
body = feed.rss2()
}
$respond({
headers: {
"Content-Type": "application/xml",
},
body,
})
$end(`Retrieved ${this.pathname} feed`)
}