Method to Auto-Publish Blogger Posts Update to Telegram Channel for Free (Using Cloudflare Workers)

Learn how to auto-publish Blogger posts to your Telegram Channel using Cloudflare Workers. A complete step-by-step guide to serverless automation.

Auto-Publish Blogger Posts to Telegram Channel

As a blogger, sharing your content across social media platforms is crucial for traffic. While tools like IFTTT or Zapier exist, they often come with limitations, delays, or premium pricing.

Connect Blogger RSS feed to Telegram Channel using Cloudflare Workers for automatic posting

Here, I am going to share a completely free, serverless, and instant method to automatically send your new Blogger (Blogspot) posts to your Telegram Channel using Cloudflare Workers.

This method is fast, customizable, and runs 24/7 without costing a penny.

Prerequisites

Before we start, make sure you have:

  • A Blogger website (obviously!).
  • A Cloudflare account (Free tier is enough).
  • A Telegram account.

Step 1: Create a Telegram Bot

We need a bot to act as the "sender" in your Telegram Channel.

  1. Open Telegram and search for @BotFather.
  2. Start a chat and send the command: /newbot
  3. Give your bot a name (e.g., MyBlogUpdateBot) and a unique username (ending in bot).
  4. BotFather will give you an HTTP API Token.
    Keep this token safe; we will need it later.

Step 2: Set Up Your Telegram Channel

  1. Create a new Telegram Channel (or use an existing one).
  2. Add your new Bot as an Administrator to this channel (this allows the bot to post messages).
  3. Get your Channel ID:
    • Send a generic message (e.g., "Hello") to your channel.
    • Forward that message to a bot called @userinfobot or @JsonDumpBot.
    • It will reply with an ID that looks like -100123456789. Copy this ID.

Step 3: Create a Cloudflare Worker

Now, let's set up the automation engine.

  1. Log in to your Cloudflare Dashboard.
  2. Go to Workers & Pages on the left sidebar.
  3. Click Create Application > Create Worker.
  4. Name your worker (e.g., blogger-to-telegram) and click Deploy.
  5. Once deployed, click on Edit Code.

Step 4: The Automation Code

Delete the existing code in the editor and paste the JavaScript code provided below.

Note: Don't forget to replace the BOT_TOKEN, CHAT_ID, and RSS_URL at the top with your own details.


const BOT_TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN';
const CHAT_ID = 'YOUR_TELEGRAM_CHAT_ID';
const RSS_URL = 'https://www.yourblog.com/feeds/posts/default?alt=rss';

export default {
  async scheduled(event, env, ctx) {
    ctx.waitUntil(handleTask(env));
  },
  async fetch(request, env, ctx) {
    return new Response(await handleTask(env));
  }
};

async function handleTask(env) {
  try {
    const response = await fetch(RSS_URL);
    const xml = await response.text();
    const match = xml.match(/<link>(.*?)<\/link>/);
    
    if (!match) return "RSS feed error.";
    const lastPostLink = match[1];
    
    const lastSent = await env.MY_STORE.get("last_post");

    if (lastPostLink !== lastSent) {
      const message = `New Blog Post!\n\n${lastPostLink}`;
      const telegramUrl = `https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}&text=${encodeURIComponent(message)}&parse_mode=Markdown`;
      
      await fetch(telegramUrl);
      await env.MY_STORE.put("last_post", lastPostLink);
      return "Success: Post sent to Telegram.";
    }
    return "No new posts.";
  } catch (err) {
    return "Error: " + err.message;
  }
}

Step 5: Configure KV Namespace (Crucial Step!)

To prevent the bot from sending the same post repeatedly, we use Cloudflare KV (Key-Value) storage to remember the last sent post.

  1. Go back to the Cloudflare Dashboard (leave the code editor for a moment).
  2. Navigate to Workers & Pages > KV.
  3. Click Create a Namespace. Name it MY_STORE_KV and click Add.
  4. Now, go back to your Worker settings:
    • Click on your Worker name > Settings > Variables.
    • Scroll down to KV Namespace Bindings.
    • Click Add Binding.
    • Variable name: MY_STORE (Must match the code exactly!).
    • KV Namespace: Select MY_STORE_KV from the dropdown.
    • Click Save and Deploy.

Step 6: Set Up Automation (Cron Triggers)

Finally, we need to tell Cloudflare to check your blog automatically.

  1. Go to your Worker > Triggers.
  2. Scroll to Cron Triggers.
  3. Click Add Cron Trigger.
  4. Select a frequency. I recommend every 30 minutes or 1 hour. (Cron expression: */30 * * * *).
  5. Click Add Trigger.

Conclusion

That's it! Now, every time you publish a new article on Blogger, your Cloudflare Worker will wake up, detect the new link, and instantly share it with your Telegram audience.

Why use this method?

  • Zero Cost: Cloudflare Workers allow 100,000 requests per day for free.
  • No Third Parties: You don't need to give access to Zapier or IFTTT.
  • Fast: The execution takes milliseconds.

If you found this guide helpful, share it with other bloggers! Happy blogging!

Post a Comment

Write your feedback or openion.