A GitHub Actions + Telethon forwarder for the Newsroom Telegram network.
The workflow checks nine specialty Newsroom channels, forwards new posts to @NewsroomHQ, prevents duplicates, keeps the order inside each source chronological, mixes sources randomly, and keeps one interactive Newsroom promotion in second-last position so the final message of a successful run is a forwarded source post.
Sources:
@BusinessNewsroom@GamingNewsroom@TheTechNewsroom@EntertainmentNewsroom@ScienceNewsroomComics News(private channel, ID-1004465768984)@TheSportsNewsroom@HistoryNewsroom(History in Today)@FactsNewsroom(Daily Facts)
Target:
@NewsroomHQ
The Newsroom promotion is intentionally split into two Telegram-native layers:
- Rich Message HTML for the editorial/premium content.
InlineKeyboardMarkupfor the ten channel links below the Rich Message. The Comics button opens a message inside the private Comics News channel and therefore requires Telegram access to that channel.
The Rich Message is sent through Telegram Bot API sendRichMessage using InputRichMessage.html only. It does not use MarkdownV2, InputRichMessage.blocks, <tg-button>, or <tg-button-row>. The photo is supplied through the documented InputRichMessage.media mechanism and uploaded in the same sendRichMessage request.
Current promotion content:
PHOTO (one randomly selected 1200x675 image)
There's more to Newsroom.
Pick the feed you want next and stay close to what matters.
[ centered pull quote ]
One connected network, all the news you need.
[ 💼 Business ] [ 💻 Tech ]
[ 🎮 Gaming ] [ 🔭 Science ]
[ 🎬 Entertainment ] [ 🎓 Career ]
[ 🦸 Comics ] [ 🏆 Sports ]
[ 📜 History ] [ 💡 Facts ]
The photo, Rich Message content, and inline keyboard are sent as one Telegram message through sendRichMessage. The photo is embedded in the Rich Message using tg://photo?id=..., while the ten category links remain a normal InlineKeyboardMarkup attached through reply_markup.
Place 3-5 photos in assets/promo/. Recommended format is exactly 1200 × 675 px (16:9 landscape). Accepted formats are JPG, JPEG, PNG, and WEBP.
At each workflow run, the forwarder randomly selects one available photo and avoids selecting the same filename used by the immediately previous promotion when more than one photo exists. The selected filename is stored in telethon_state.json as footer_photo.
The repository intentionally does not invent or download stock photography. Add your own final promotional images to assets/promo/.
The keyboard is deliberately a normal InlineKeyboardMarkup attached through the reply_markup parameter of sendRichMessage. Telegram's Bot API explicitly supports reply_markup on sendRichMessage, with an inline keyboard represented as rows of InlineKeyboardButton objects. citeturn3view0
- Exactly 2 buttons per row and 5 rows.
- All ten buttons use the same plain URL-button structure and visual treatment.
- Emoji stays at the beginning of every label for fast scanning.
Historyuses📜andFactsuses💡to match the visual language of the other feeds.Entertainmentuses the full label🎬 Entertainment. Telegram clients decide whether that label fits on one line; the code does not use unsupported width, height, padding, or CSS tricks.- No artificial blank lines or padding characters are inserted into button labels.
- No separate category heading, redundant instruction, or generic “Explore our specialty channels” copy is included.
Telegram documents InlineKeyboardMarkup as an array of button rows, and sendRichMessage accepts it through reply_markup. citeturn0search0turn3view0
The promotion is designed to be the second-last message of a successful run. The final message is the last forwarded source post processed in that run.
At the beginning of a run, the previous saved footer message is deleted. During processing, the newest publishable candidate is held back by one position. When all sources are exhausted, the new Rich Message is sent first, then that held source post is forwarded. This produces:
... forwarded source post
PROMOTIONAL MESSAGE
FINAL FORWARDED SOURCE POST
The promotion message ID is stored for deletion on the next run, so the target channel does not accumulate old copies.
Two Telegram authentication mechanisms are used for different jobs.
Used for:
- Reading source-channel history.
- Detecting new source messages.
- Native forwarding.
- Deleting the previous footer when possible.
Required GitHub repository secrets:
API_ID
API_HASH
TELETHON_SESSION
TELETHON_SESSION must be a regular Telegram user StringSession, not a bot session.
Used only for the interactive footer.
Required GitHub repository secret:
TELEGRAM_BOT_TOKEN
Use your existing bot token. Do not create another bot just for this project.
The workflow passes it as:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}The bot also needs permission to send media in @NewsroomHQ.
The bot must be able to post the footer in @NewsroomHQ, send photos there, and delete its own previous footer message. Keep the token secret and never commit it.
Telegram history polling and native forwarding are handled by the Telethon user session. Rich Message footer delivery is handled separately by the Bot API because sendRichMessage is the API method that provides the Rich Message HTML interface and interactive Rich Message blocks. citeturn708593search0
Forwarded source posts are not rewritten. They remain native Telegram forwards.
The first deployment does not intentionally take the newest message as a baseline.
For an uninitialized source, the saved source ID starts at 0 and the forwarder processes available history oldest-first. This allows historical posts to be backfilled.
Backfill is resumable. A source message is not treated as successfully processed until the Telegram forward operation succeeds.
A source can have more than 100 pending messages. The forwarder refills its queue automatically as the previous batch is exhausted.
Messages remain chronological inside each source, but the nine sources are interleaved randomly.
The previous source is excluded from the next choice whenever another source has pending messages. This reduces long consecutive runs from the same channel.
Example:
Business 1
Gaming 1
Tech 1
Science 1
Business 2
Sports 1
Career 1
Gaming 2
...
This changes only cross-channel order. It does not reorder messages inside an individual source.
Two layers are used.
Stores the last successfully processed Telegram message ID for every source and the current footer message ID.
Stores the canonical source URL for every successfully forwarded post, for example:
https://t.me/BusinessNewsroom/123
If a URL is already present, that message is skipped as a duplicate.
The source message ID advances only after a successful forward or a safe non-news/service-message skip.
If a forward fails:
- The failed source is blocked for the current run.
- Its state is not advanced past the failed message.
- Other accessible sources continue.
- The next workflow run retries the failed message.
This prevents a transient Telegram failure from silently losing a source post.
Telegram service messages are not treated as ordinary news posts.
They are skipped safely and the source state advances past the service-message ID so later real posts can continue processing.
The footer is designed to remain the second-last message in a successful run of @NewsroomHQ.
At the beginning of a run:
- Read
footer_message_idfromtelethon_state.json. - Delete the previous footer using that exact destination message ID.
- Continue source processing.
At the end of a run:
- Build the Rich HTML footer.
- Send it with Bot API
sendRichMessage. - Read the returned destination
message_id. - Save that ID to
telethon_state.json. - Forward the one held final source post immediately after the promotion.
The next run repeats the cycle.
If an old footer was already deleted manually, the delete failure is handled as an already-removed message when Telegram reports a known invalid/deleted-message condition.
Workflow file:
.github/workflows/forward-hourly.yml
Schedule:
30 minutes past each scheduled hour
08:30 AM through 01:30 AM Bangladesh time
The cron expression is:
7 2-20 * * *
because Bangladesh Standard Time is UTC+6.
Manual execution is also enabled with workflow_dispatch.
Create these four GitHub repository secrets:
API_ID
API_HASH
TELETHON_SESSION
TELEGRAM_BOT_TOKEN
Do not use a secret named BOT_TOKEN for this V1 workflow unless the workflow is changed to map that name explicitly. The current workflow expects TELEGRAM_BOT_TOKEN.
The Telegram user account stored in TELETHON_SESSION should have:
- Access to all nine source channels.
- Permission to read their history.
- Permission to post/forward into
@NewsroomHQ. - Permission to delete the previous footer in
@NewsroomHQ.
The footer bot should have enough permissions in @NewsroomHQ to post and delete the footer messages it creates.
Use generate_session.py on a trusted machine or Google Colab.
The program asks for API_ID and API_HASH, starts the normal Telegram login flow, and prints the resulting StringSession.
Store only that session string in the GitHub TELETHON_SESSION secret.
Never put it in source code or commit it to the repository.
The repository may contain:
telethon_state.json
posted_urls.txt
These are normal persistent state files and are committed by GitHub Actions after a run when they change.
Do not delete them during normal operation. Deleting them resets the source state and can cause the project to backfill history again.
A clean state is:
{
"initialized": false,
"channels": {},
"footer_message_id": null
}An empty posted_urls.txt is also valid.
Place the project files in the GitHub repository root:
forwarder.py
requirements.txt
generate_session.py
README.md
.github/workflows/forward-hourly.yml
Open:
GitHub → Settings → Secrets and variables → Actions → Repository secrets
Add:
API_ID
API_HASH
TELETHON_SESSION
TELEGRAM_BOT_TOKEN
For TELEGRAM_BOT_TOKEN, paste the same existing bot token you already use for your Newsroom bot infrastructure.
Make sure the Telethon user and footer bot can work in the source channels and @NewsroomHQ.
Open:
GitHub → Actions → Telegram Telethon Hourly Forwarder → Run workflow
A healthy run should show messages similar to:
AUTHENTICATED | username=@YourUser | id=... | bot=False
TARGET RESOLVED | @NewsroomHQ
SOURCE ACCESS PASS | @BusinessNewsroom accessible
SOURCE ACCESS PASS | Comics News accessible | mode=private | id=-1004465768984
...
FORWARD PASS | source=@BusinessNewsroom | source_message_id=...
...
FOOTER POST PASS | method=bot_api | message_id=...
FINISHED | initialized=True | forwarded=... | failed=0 | footer_posted=True | posted_urls=...
The bot token itself is never printed.
After a manual run, @NewsroomHQ should end with one promotion message containing:
- A strong
There's more to Newsroom.heading. - One short personalization/CTA sentence.
- A centered Pull Quote:
One connected network, all the news you need. - Five rows of two inline URL buttons.
- Exactly these ten labels:
💼 Business 💻 Tech
🎮 Gaming 🔭 Science
🎬 Entertainment 🎓 Career
🦸 Comics 🏆 Sports
📜 History 💡 Facts
The ten button destinations are:
Business → https://t.me/BusinessNewsroom
Tech → https://t.me/TheTechNewsroom
Gaming → https://t.me/GamingNewsroom
Science → https://t.me/ScienceNewsroom
Entertainment → https://t.me/EntertainmentNewsroom
Comics → https://t.me/c/4465768984/72 (private)
Sports → https://t.me/TheSportsNewsroom
History → https://t.me/HistoryNewsroom
Facts → https://t.me/FactsNewsroom
The exact button height, width, and line wrapping remain Telegram-client controlled. The implementation does not attempt to override them.
GitHub secret name must be exactly:
TELEGRAM_BOT_TOKEN
The workflow must contain:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}Generate a regular user StringSession. Do not use the bot token for Telethon history polling.
Check:
- The bot token is correct.
- The bot can access
@NewsroomHQ. - The bot has permission to post in the target channel.
- Telegram Bot API Rich Messages are available to the bot account and current Telegram client.
The project first tries deletion through the Telethon user session and then through the Bot API for bot-authored footer messages. Check the permissions of the account and bot in @NewsroomHQ.
That usually means Telegram returned an error while processing that source. The failed source is intentionally blocked for the current run so other sources can continue, and its last successful message ID remains unchanged for retry on the next run.
The workflow requires:
permissions:
contents: writeGitHub Actions must be allowed to push to the repository branch used by the workflow.
Never commit:
- Telegram API credentials.
TELETHON_SESSION.TELEGRAM_BOT_TOKEN.- Login codes or 2FA passwords.
Never print the session string or bot token in logs.
TelegramForwarder-V1/
├── forwarder.py
├── requirements.txt
├── generate_session.py
├── assets/
│ └── promo/
│ └── README.txt
├── README.md
└── .github/
└── workflows/
└── forward-hourly.yml
Telegram source channels (9)
│
▼
Telethon user session
│
history + native forward
│
▼
@NewsroomHQ
│
├── forwarded source posts
│
├── promotion (second-last)
└── final forwarded source post
│
▼
Telegram Bot API
sendRichMessage
│
┌─────────────┴─────────────┐
▼ ▼
InputRichMessage.html InlineKeyboardMarkup
│ │
Heading + CTA 5 × 2 grid
│ │
Pull Quote 10 channel links