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.
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
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.
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).`);.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.
*/15 * * * * cd /home/me/rss-tg && /usr/bin/node --env-file=.env feed.mjs >> rss.log 2>&1Result
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
25:00
18:00
60:00
27:30
22:00
25:00