A Telegram bot that monitors financial news channels, summarizes the content using AI, and sends periodic summaries to subscribers.
- Channel Monitoring: Monitors financial news channels on Telegram (default: "marketfeed")
- AI Summaries: Generates concise summaries using OpenAI's GPT models
- Stock Impact Analysis: Identifies potentially impacted stocks and market sectors
- Sentiment Analysis: Determines if the news has bullish, bearish, or neutral sentiment
- Markdown Formatting: Properly formatted messages with bold text and bullet points
- Subscriber System: Users can subscribe/unsubscribe to receive updates
- Automatic Notifications: Notifies subscribers when the bot starts up
- Python 3.8+
- Telegram API credentials (API ID and API Hash) from my.telegram.org
- Telegram Bot Token from @BotFather
- OpenAI API Key from OpenAI Platform
-
Clone the repository:
git clone <repository-url> cd TelegramBot2
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.envfile with the following variables:TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_BOT_TOKEN=your_bot_token TELETHON_SESSION_STRING=your_session_string OPENAI_API_KEY=your_openai_key TARGET_CHANNEL=channel_name # default is 'marketfeed'
- Go to my.telegram.org and log in
- Create a new application to get your API ID and API Hash
- Add these to your
.envfile asTELEGRAM_API_IDandTELEGRAM_API_HASH
- Talk to @BotFather on Telegram
- Send
/newbotand follow the instructions to create a new bot - Copy the provided token to your
.envfile asTELEGRAM_BOT_TOKEN
The session string allows the bot to connect to Telegram as a user to monitor channels:
python3 session_generator.pyFollow the prompts to authenticate and generate a session string, then add it to your .env file as TELETHON_SESSION_STRING.
- Create an account or log in at OpenAI
- Navigate to the API Keys section
- Generate a new key and add it to your
.envfile asOPENAI_API_KEY
To run the bot in normal mode (5-hour interval between summaries):
python3 simple_solution.pyTo run in test mode with shorter intervals (5 minutes):
python3 simple_solution.py --testTo enable debug logging:
python3 simple_solution.py --debugTo automatically add yourself as a subscriber when starting the bot:
python3 simple_solution.py --admin_id YOUR_TELEGRAM_IDOnce the bot is running, users can interact with it using these commands:
/start- Subscribe to financial news summaries/stop- Unsubscribe from updates/help- Show help message and available commands/status- Show bot status and subscriber count/test- Generate and send a test summary immediately/subscribe_me- Alternative command to subscribe
Railway offers a free tier for hosting applications:
- Sign up at Railway
- Install the Railway CLI:
npm i -g @railway/cli
- Login to Railway:
railway login
- Initialize your project:
railway init
- Add environment variables:
railway vars set TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_BOT_TOKEN=your_bot_token TELETHON_SESSION_STRING=your_session_string OPENAI_API_KEY=your_openai_key TARGET_CHANNEL=channel_name - Deploy your project:
railway up
Render also offers free hosting:
- Create an account at Render
- Create a new Web Service and connect your GitHub repository
- Set the build command:
pip install -r requirements.txt - Set the start command:
python simple_solution.py - Add all environment variables from your
.envfile - Deploy the service
Google Cloud offers a free tier for Cloud Run:
- Create a Google Cloud account
- Install Google Cloud SDK
- Build your Docker container:
gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/financial-news-bot
- Deploy to Cloud Run:
gcloud run deploy --image gcr.io/YOUR_PROJECT_ID/financial-news-bot --platform managed
- Set environment variables in the Google Cloud Console
- Connection Issues: If the bot can't connect to Telegram, verify your API credentials and session string.
- No Summaries Generated: Check your OpenAI API key and ensure the target channel is accessible.
- Messages Not Formatted: The bot uses Markdown formatting with
parse_mode='md'. Make sure your client supports markdown. - Not Receiving Messages: Verify that you've subscribed with
/startor/subscribe_meand check your bot's subscribers list.
This project is licensed under the MIT License.