Build a Telegram bot for keyword-based news alerts

News reaches Australians through national coverage, state outlets, specialist trade publications and fast-moving social feeds. A Telegram bot can reduce the checking burden by watching trusted RSS sources and sending only the headlines that match your interests. The result is a focused alert channel rather than an endless stream of general news.

This guide explains how to set up a Telegram bot that sends news alerts based on keywords, using the Telegram Bot API, Python and scheduled RSS checks. The same design can serve a personal reading list, a small business watchlist or a community group, provided participants understand what the bot collects and where alerts are posted.

You will create the bot, connect it to reliable feeds, add keyword filters and test delivery before moving the service onto a long-running host. The implementation favours readable configuration, short source excerpts, original links and controls that let recipients pause or leave an alert channel.

Define the alert scope and keywords

Begin with the decisions that shape every later design: which sources matter, which terms justify an interruption and whether recipients want immediate notifications, a scheduled digest, or both. A narrow subject is easier to tune than a request for “all the news”, especially when several publishers use the same terminology.

Write test cases before writing code. Include an expected match, a near miss that should pass and an ambiguous headline that should be excluded. Exact phrases reduce accidental matches, while exclusions help prevent a term about sport or politics from triggering an unrelated business alert.

Treat these as starting rules rather than permanent settings. Review unmatched articles and false positives after the first week, then tighten the filters. Keep Australian spelling and local naming conventions in mind so terms such as “organisations”, “labour” and “football” behave as intended.

Create the bot and prepare its environment

Open Telegram, find BotFather and send /newbot. Choose a distinct bot name and a username that identifies its purpose. BotFather returns a bot token, which is effectively the bot’s password. Create the application on a computer with Python 3.10 or newer, and keep the token out of source code and chat messages.

On macOS or Linux, create an isolated environment and install the libraries needed for Telegram messages, RSS parsing, configuration and scheduling:

python -m venv .venv
source .venv/bin/activate
pip install python-telegram-bot feedparser httpx python-dotenv apscheduler

On Windows, activate the environment with .venv\Scripts\activate before installing the same packages.

Store TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID in a .env file, using a placeholder for the numeric chat identifier. Start a direct chat with the bot so you can read its identifier from an update payload. If alerts should reach a group, obtain your group ID and add the bot with posting rights. A bot with privacy mode enabled may see only commands and mentions unless an administrator grants broader message visibility.

Choose between polling, scheduling, and webhooks

Long polling and scheduled feed checks solve different problems. Long polling asks Telegram for new messages, allowing recipients to issue commands such as /alerts or /stop. The polling and survey tutorial shows a practical command-response pattern that can be adapted to keyword notifications. A scheduler separately fetches news feeds at regular intervals.

Webhooks offer another route for incoming updates: Telegram sends them to a public HTTPS endpoint instead of the bot waiting for a request. That suits a properly secured server, but it adds certificate, routing and exposure management. A scheduled worker and a long-polling listener can run together; webhook mode and getUpdates polling should not operate for the same bot simultaneously.

Approach Best suited to Main limitation
Scheduled feed checks Regular keyword alerts and daily digests Requires the worker to run and feeds to be reachable
Long polling Chat commands, confirmations and alert controls A process must maintain the connection
Webhooks Server-based bots needing immediate update delivery Needs a public HTTPS endpoint with a valid certificate

For most news-only deployments, schedule checks every ten to fifteen minutes and skip webhook infrastructure. Add long polling when recipients need controls. Reserve webhooks for services already operating behind a reliable public endpoint, and respect Telegram’s per-chat send limits by spacing message bursts.

Fetch and filter incoming news

Use RSS feeds that publishers make available for legitimate syndication, and record the source with every alert. ABC News and The Guardian Australia offer national and international coverage, while industry publications and government sites may supply specialist updates. Do not scrape complete articles when a feed and attribution will suffice.

A simple filter combines the headline and a short summary, converts the text to lowercase and checks each keyword or phrase. Keep case-insensitive matching, remove duplicate URLs and limit each message to a title, brief excerpt and original link.

import os
import feedparser
import httpx
from dotenv import load_dotenv
from telegram import Bot

load_dotenv()
KEYWORDS = ["renewable energy", "battery", "electric vehicle"]
FEEDS = [os.environ["ABC_FEED"], os.environ["GUARDIAN_FEED"]]
CHAT_ID = int(os.environ["TELEGRAM_CHAT_ID"])

async def send_alerts():
    async with Bot(os.environ["TELEGRAM_BOT_TOKEN"]) as bot:
        async with httpx.AsyncClient(timeout=20) as client:
            for url in FEEDS:
                response = await client.get(url)
                response.raise_for_status()
                for item in feedparser.parse(response.content).entries:
                    haystack = f"{item.title} {item.get('summary', '')}".lower()
                    if any(term.lower() in haystack for term in KEYWORDS):
                        await bot.send_message(
                            chat_id=CHAT_ID,
                            text=f"{item.title}\n{item.link}"
                        )

Set ABC_FEED and GUARDIAN_FEED to the current RSS endpoints, then run the function with asyncio.run(send_alerts()). In production, save processed links in SQLite or another durable store so a restart does not resend yesterday’s headlines. Add timeouts and catch feed failures so one unavailable publisher does not stop the cycle.

Run a reliable alert routine

Design each notification for quick reading: publisher, factual headline, one-sentence summary, original link and publication time. Use Python’s zoneinfo module with Australia/Sydney for schedules defined in Sydney time so daylight-saving changes are handled automatically. Brisbane does not shift its clocks, while Perth uses AWST, so a fixed UTC offset can mislabel local times.

For the Australian market, blend national sources such as ABC News with state reporting, specialist trade feeds and official announcements affecting your work or customers. Match the local context: “NRL” in Sydney, “AFL” in Melbourne and “Aussie rules” across parts of the country can be more precise than “football”. Use unambiguous dates such as 24 March 2026, not US-style month-first notation.

Test daylight-saving boundaries, lunchtime digests and noisy keywords before opening a group. A direct message is the safest place to validate the first alert, and separate channels can serve different interests within one organisation. Respect quiet hours and make leaving the channel straightforward for recipients.

Launch with a secure production setup

Protect the bot token as a credential: keep it in environment variables, exclude .env from version control, and rotate it if it appears in a log or repository. Give the bot only the permissions it needs, and obtain consent before posting to a group. Store chat identifiers and message histories in line with your privacy obligations.

Compare a self-hosted build with a managed news alert platform, checking Telegram delivery, feed coverage, attribution terms, data handling and ongoing cost before committing. An external service may reduce infrastructure work, but the operator still needs a clear account of where subscriber data goes and who receives each alert.

Publish the bot’s purpose, source list and a contact for corrections before opening access. Create the bot with two trusted Australian feeds, three precise keywords and one private test chat, then send its first live alert today.