A Telethon userbot — a script that logs in as your Telegram account (not a bot created via @BotFather), watches specific public channels you've joined, filters messages by keyword, and forwards matches to a destination chat. This approach works on any public channel without needing admin access.
- Go to my.telegram.org and log in with your phone number.
- Navigate to API Development Tools.
- Create a new app (name and description don't matter).
- Copy your
api_idandapi_hash— save them somewhere secure.
Clone this repository directly — no need to create files manually:
git clone https://github.com/kommissarfx/telegram-userbot.git
cd telegram-userbotThis gives you all three required files (main.py, Procfile, requirements.txt) instantly.
If you want your own copy on GitHub (recommended for Railway deployment), push it to a new private repo:
git remote set-url origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git git push -u origin mainThen connect your repo to Railway as described in Step 4.
You need a StringSession — a string that represents your authenticated Telegram login so the bot can act as you on the server without needing your password each time.
Do this once using Replit (no local install needed):
- Go to replit.com, create a free account, and start a new Python Repl.
- In the Shell, run:
pip install telethon - Create and run this script:
from telethon.sync import TelegramClient
from telethon.sessions import StringSession
api_id = int(input("API_ID: ").strip())
api_hash = input("API_HASH: ").strip()
with TelegramClient(StringSession(), api_id, api_hash) as client:
print(">> Sending login code to your Telegram...")
print("STRING_SESSION:", client.session.save())- Enter your
api_idandapi_hashwhen prompted. - Telegram will send a login code to your account — enter it.
- Copy the long string printed after
STRING_SESSION:— this is your session key. Treat it like a password. - You can delete the Repl afterwards.
- Go to railway.app and sign in (use "Continue with GitHub").
- Click New Project → Deploy from GitHub Repo.
- Select your
telegram-userbotrepo. - Railway will detect the
Procfileand set the service type to Worker automatically. Confirm this is the case (not "Web Service").
In Railway, go to your service → Variables tab, and add the following:
| Variable | Value |
|---|---|
API_ID |
Your numeric API ID from my.telegram.org |
API_HASH |
Your API hash string |
STRING_SESSION |
The long session string from Step 3 |
KEYWORDS |
Pipe-separated terms, e.g. Київ|Kyiv|Киев|дрон|Shahed|тривог |
CHANNELS |
Comma-separated channel IDs to watch, e.g. 1223955273,1641260594 |
FORWARD_TO |
Destination chat ID or me for Saved Messages |
WEBHOOK_URL |
(Optional — leave blank if not needed) |
Note on
KEYWORDS: Always set a meaningful value. If left empty, the regex matches everything and the bot will forward every single message from all monitored channels to your destination chat. The code has a default fallback ofКиїв|Kyiv|Киевif the variable is not set at all.
Note on
CHANNELS: If left empty, the bot watches all channels you've joined. It's recommended to list specific channel IDs to reduce noise.
Note on
WEBHOOK_URL: Only needed if you want to trigger an external service (e.g. an iOS Shortcut via Pushcut) when an alert fires. Leave blank for Telegram-only forwarding.
- Click Deploy in Railway.
- Wait for the build to finish and the worker to start.
- Open the Logs tab — you should see:
Userbot running. Watching channels: [...] - To test: send (or find) a message containing one of your keywords in a monitored channel.
- Check your destination chat — the message should appear with a 🚨 prefix.
In Telegram, mute all the noisy source channels. Keep your destination chat (Saved Messages or your alerts chat) unmuted. From now on, you'll only receive notifications for messages that match your keywords.
- Refine keywords anytime by updating
KEYWORDSin Railway Variables (no redeploy needed, just restart the service). - Check logs occasionally for errors.
- If the session expires (rare): repeat Step 3 to generate a new
STRING_SESSIONand update the variable in Railway. - Free tier note: Railway's free plan covers ~750 hours/month per service — enough to run one small bot 24/7. Add a payment card to avoid interruptions if credits run low.