This project connects Telegram to MetaTrader 5 (MT5), allowing you to access and analyze Telegram messages and integrate them with trading platforms.
The application consists of two main parts:
- π± Frontend: React application providing the user interface
- βοΈ Backend: Python FastAPI service for Telegram API integration
- π User authentication system with verification
- π¬ Access Telegram messages, channels, and groups
- π Multi-language support with i18next
- π Integration with MetaTrader 5
- π¨ Modern UI with Material UI components
- π± Responsive design for all devices
- πΎ Local data storage for improved performance
- Framework: React 17
- UI Library: Material UI with Emotion styling
- State Management: React Context API
- Internationalization: i18next
- Build Tool: Vite
- Testing: Jest + React Testing Library
- Language: TypeScript
- Framework: FastAPI (Python)
- Telegram API: Telethon library
- Database: SQLAlchemy with SQLite
- Authentication: Token-based
- Node.js (version 14+)
- Python 3.7+
- Telegram API credentials (API ID and hash)
The easiest way to get started is to use the provided initialization script:
./init.shThis script will:
- Set up the Python virtual environment for the backend
- Install all required dependencies
- Start both the backend and frontend servers
- Handle cleanup when terminated (Ctrl+C)
- Navigate to the frontend directory
- Install dependencies:
npm install
- Copy the environment file and configure:
cp .env.example .env
- Start the development server:
npm run dev
-
Navigate to the backend directory
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile with your configuration:# Telegram API Settings (Optional - can be provided via API) TELEGRAM_API_ID= TELEGRAM_API_HASH= TELEGRAM_PHONE= # API Settings PORT=8000 HOST=0.0.0.0 DEBUG=True -
Run the server:
python backend/run.py
./init.sh- Initialize and start both backend and frontend servers
npm run dev- Start the development servernpm run build- Build for productionnpm run lint- Run ESLintnpm run preview- Preview production buildnpm run test- Run tests
python backend/run.py- Run the API serverpython -m app.main- Alternative way to run the server
The backend API documentation is available at http://localhost:8000/docs when running the server.
-
Connect to Telegram:
POST /v1/telegram/connect
-
Get Dialogs (Chats, Channels, Groups):
POST /v1/telegram/dialogs
-
Get Messages:
POST /v1/telegram/messages/{dialog_id} -
Search Messages:
POST /v1/telegram/search
- Store API credentials securely
- Restrict CORS origins in production
- Consider implementing robust authentication
- Use a production-ready database in production environments
frontend/src/
βββ assets/ # Static assets
βββ components/ # UI components
β βββ AppRouter/ # Navigation components
β βββ Background/ # Background components
β βββ Dashboard/ # Dashboard UI
β βββ LanguageSwitcher/ # Language selection
β βββ SignIn/ # Authentication UI
β βββ VerificationCode/ # Verification UI
βββ context/ # React Context providers
βββ i18n/ # Internationalization
βββ services/ # API services
βββ types/ # TypeScript types
βββ __tests__/ # Test files
βββ App.tsx # Main component
βββ main.tsx # Entry point
backend/
βββ app/ # Main application
β βββ api/ # API endpoints
β βββ config/ # Configuration
β βββ core/ # Core functionality
β βββ models/ # Database models
β βββ schemas/ # Pydantic schemas
β βββ services/ # Business logic
β βββ main.py # Entry point
βββ db/ # Database files
For issues or feature requests, please use the issue tracker on the repository.
This project provides a service to connect to Telegram and retrieve or listen for messages in real-time.
- Connect to Telegram using official API
- Retrieve message history from chats, groups, and channels
- Search for specific messages
- Listen for new messages in real-time
- Handle authentication including 2FA
-
Get Telegram API Credentials
- Visit https://my.telegram.org/auth
- Log in with your phone number
- Go to "API development tools"
- Create a new application
- Note down your
api_idandapi_hash
-
Install Dependencies
pip install telethon python-dotenv
-
Configure Environment Create a
.envfile in the project root with:TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_PHONE=your_phone_number # with country code
Run the example script:
python examples/listen_for_messages.pyWhen connecting for the first time, you'll need to enter the verification code sent to your Telegram app. If you have two-factor authentication enabled, you'll also need to enter your password.
import asyncio
from backend.app.services.telegram_service import TelegramService
async def message_handler(message_info):
print(f"New message: {message_info['text']}")
async def main():
# Create the TelegramService instance
service = TelegramService(
api_id=YOUR_API_ID,
api_hash="YOUR_API_HASH",
phone="YOUR_PHONE_NUMBER"
)
await service.connect()
# To get a list of all dialogs
dialogs = await service.get_all_dialogs()
print(dialogs)
# To listen for new messages in specific dialogs
await service.listen_for_new_messages(
dialog_ids=[123456789], # optional, None for all dialogs
callback=message_handler
)
# Don't forget to disconnect when done
await service.disconnect()
if __name__ == "__main__":
asyncio.run(main())MIT
This project includes a service to continuously listen for and store messages from multiple Telegram chats simultaneously.
- π Run multiple Telegram listeners simultaneously
- πΎ Configure different output types (database, file, etc.)
- π REST API to manage sync configurations
- π Automatic reconnection and monitoring
- π Track message history in the database
The sync service is accessible through API endpoints:
# List all sync configurations
GET /v1/sync/
# Create a new sync configuration
POST /v1/sync/You can create a new sync configuration using the API:
curl -X POST "http://localhost:8000/v1/sync/" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1,
"discussion_name": "My Important Channel",
"state": "active"
}'Or use the Swagger UI at http://localhost:8000/docs
The following API endpoints are available:
GET /v1/sync/- List all sync configurationsPOST /v1/sync/- Create a new sync configurationGET /v1/sync/{sync_id}- Get a specific configurationPUT /v1/sync/{sync_id}- Update a configurationDELETE /v1/sync/{sync_id}- Delete a configurationPUT /v1/sync/{sync_id}/state/{state}- Update a sync's state
Synced messages are stored in the database and can be accessed via SQL queries or your preferred ORM.
If you configured file output, messages will also be saved to the specified file path.