Simple Telegram Bot With Ngrok Webhook Setup
A simple Telegram bot with multilanguage support that uses webhooks instead of polling, with ngrok for local development and testing. The bot responds to /start and /help commands and provides a default response for all other messages.
- Webhook-based Telegram bot using Flask
- Ngrok integration for exposing local server to the internet
- Separate configuration file for easy setup
- Clean shutdown and resource cleanup
- Comprehensive logging
- Python 3.7 or higher
- Telegram Bot Token (from @BotFather)
- Ngrok account (free tier works fine) and auth token
- Clone the repository
git clone https://github.com/IvanDeus/Simple-Telegram-Bot.git
cd Simple-Telegram-Bot- Install dependencies
pip install -r requirements.txt- Set up configuration
Copy the example config file:
cp config.py.example config.pyEdit config.py and add your tokens:
# Telegram Bot Token (get from @BotFather)
BOT_TOKEN = "your_telegram_bot_token_here"
# Ngrok Auth Token (get from https://dashboard.ngrok.com/auth)
NGROK_AUTH_TOKEN = "your_ngrok_auth_token_here"
# Local server configuration (default values work fine)
LOCAL_HOST = "0.0.0.0"
LOCAL_PORT = 7777
WEBHOOK_PATH = "/webhook"- Run the bot
python bot.py- Expected output
INFO:__main__:Ngrok tunnel established: https://xxxx-xx-xxx-xxx.ngrok-free.app
INFO:__main__:Setting webhook to: https://xxxx-xx-xxx-xxx.ngrok-free.app/webhook
INFO:__main__:Webhook set successfully!
INFO:__main__:Starting Flask server on 127.0.0.1:7777
- Test your bot
- Open Telegram and find your bot
- Send
/startand/helpcommands - Send any other message
- The bot should respond accordingly
Simple-Telegram-Bot/
├── bot.py # Main bot application
├── config.py # Configuration file (create from example)
├── config.py.example # Example configuration template
├── messages.json # All bot messages in several languages
├── requirements.txt # Python dependencies
├── README.md # This file
└── .gitignore # Git ignore rules
- Flask Server: Runs locally on port 7777, handling webhook requests at
/webhook - Ngrok Tunnel: Creates a secure public URL that forwards to your local server
- Telegram Webhook: Configures Telegram to send updates to your ngrok URL
- Message Handlers:
/startcommand: Returns a welcome message- All other messages: Returns a simple default response
The bot automatically:
- Removes the webhook on shutdown
- Kills ngrok processes
- Performs proper resource cleanup
- The ngrok URL changes each time you restart the bot (free tier)
- Keep the script running to maintain the webhook
- The bot will stop responding if you close the terminal
- For production, consider using a VPS instead of ngrok
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
2026 [ ivan deus ]