Templates / Scheduled jobs

Daily RSS digest by email

Every morning, fetch your RSS feeds, pick the new items and email yourself a digest with Resend. No server, no cron box to maintain.

Turn a handful of blogs and changelogs into one morning email. The function fetches each feed, skips items it already sent, and emails the rest — nothing if there’s nothing new.

Build it with Wisp

Type this into Wisp, or press Build this — it writes the code below, deploys it and gives you a URL:

Every day at 7am, fetch the RSS feeds in the FEEDS variable, keep only items I haven’t seen, and email me a digest with links via the Resend API (RESEND_API_KEY, DIGEST_FROM, DIGEST_TO).

The code

*rss-digest · schedule `0 7 * `*

import { createHash } from 'node:crypto';
import { config, kv } from 'wisp';

const decode = (s) => s.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g, '$1').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').trim();
const tag = (xml, name) => decode(xml.match(new RegExp(`<${name}[^>]*>([\\s\\S]*?)</${name}>`))?.[1] ?? '');
const esc = (s) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');

async function items(feed) {
  const xml = await (await fetch(feed, { signal: AbortSignal.timeout(10_000) })).text();
  // RSS uses <item>; Atom uses <entry> with <link href="…">.
  return [...xml.matchAll(/<(item|entry)\b[\s\S]*?<\/\1>/g)].map(([x]) => ({
    title: tag(x, 'title'),
    link: tag(x, 'link') || x.match(/<link[^>]*href="([^"]+)"/)?.[1] || '',
  }));
}

export async function handler() {
  const feeds = config.require('FEEDS').split(',').map((f) => f.trim());
  const fresh = [];
  for (const feed of feeds) {
    for (const item of (await items(feed).catch(() => [])).slice(0, 20)) {
      const key = 'seen:' + createHash('sha1').update(item.link || item.title).digest('hex');
      if (await kv.get(key)) continue;
      await kv.set(key, true, { ttl: 60 * 86_400 });
      fresh.push(item);
    }
  }
  if (fresh.length === 0) return { sent: 0 };
  await fetch('https://api.resend.com/emails', {
    method: 'POST',
    headers: { authorization: `Bearer ${config.require('RESEND_API_KEY')}`, 'content-type': 'application/json' },
    body: JSON.stringify({
      from: config.require('DIGEST_FROM'),
      to: config.require('DIGEST_TO'),
      subject: `${fresh.length} new posts`,
      html: '<ul>' + fresh.map((i) => `<li><a href="${esc(i.link)}">${esc(i.title)}</a></li>`).join('') + '</ul>',
    }),
  });
  return { sent: fresh.length };
}

Set it up

Add these in the project’s Variables & secrets (secrets are encrypted and never shown in logs):

Try it

Press Run: the first run emails everything currently in the feeds (up to 20 per feed); run it again and it sends nothing until there are new posts.

How it works

Variations

Questions

Why not use an RSS library? You can — add a package such as rss-parser. The regex version avoids a dependency and handles the common feeds; a library handles odd ones better.

Build it with Wisp — free trial

Related