IntegrationsIntermediate

How to auto-post your blog RSS feed to a Telegram channel

Watch an RSS or Atom feed and broadcast each new article to a Telegram channel automatically.

9 minIntermediate

If you publish a blog or podcast, you can mirror every new item to a Telegram channel without copy-pasting. The trick is to remember which items you have already posted so you never duplicate. This guide builds a feed watcher that does that.

What you need

  • A bot that is an admin of your channel
  • A public RSS or Atom feed URL
  • Node 18 or newer and a place to run it on a schedule

Step 1: Install a feed parser

zsh - setup
$mkdir rss-tg && cd rss-tg && npm init -y
$npm install rss-parser
added 14 packages in 2s
$

Step 2: Track what you have posted

Store the IDs of items already sent in a small file. On each run, post only items whose guid is not in that file, then add the new ones.

feed.mjs
import Parser from "rss-parser";
import { readFile, writeFile } from "node:fs/promises";

const token = process.env.TELEGRAM_BOT_TOKEN;
const channel = "@my_channel";
const FEED = "https://example.com/blog/rss.xml";
const SEEN = "seen.json";

const parser = new Parser();
const feed = await parser.parseURL(FEED);

let seen = [];
try {
  seen = JSON.parse(await readFile(SEEN, "utf8"));
} catch {
  seen = [];
}

const fresh = feed.items.filter((it) => !seen.includes(it.guid));

for (const item of fresh.reverse()) {
  const text = `<b>${item.title}</b>\n${item.link}`;
  await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({
      chat_id: channel,
      parse_mode: "HTML",
      text,
      disable_web_page_preview: false,
    }),
  });
  seen.push(item.guid);
}

await writeFile(SEEN, JSON.stringify(seen.slice(-500), null, 2));
console.log(`Posted ${fresh.length} new item(s).`);
Post oldest first
Feeds list newest items first. Calling .reverse() on the fresh items posts them in chronological order, so the channel reads top to bottom the way readers expect.

Step 3: Run it on a timer

Check the feed every 15 minutes with cron. The seen file guarantees that re-running does nothing harmful when there are no new posts.

crontab
*/15 * * * * cd /home/me/rss-tg && /usr/bin/node --env-file=.env feed.mjs >> rss.log 2>&1
Telegram - @my_channel
Agent
How we cut our deploy time in half https://example.com/blog/faster-deploys

Result

New blog posts now appear in your channel within minutes of publishing, formatted with a bold title and a link, and never duplicated thanks to the seen file.

Watch related tutorials

Tags
#telegram#rss#auto-post#channel#automation