A full-stack application that integrates a Telegram bot with Plaid's banking API, allowing users to securely connect their bank accounts and view financial information directly through Telegram.
-
Telegram Bot Interface
- Interactive command-based navigation
- User-friendly keyboard buttons
- Real-time account balance viewing
- Transaction history retrieval
- Secure user authentication
-
Plaid Banking Integration
- Secure bank account linking via Plaid Link
- Multi-account support
- Real-time balance fetching
- Transaction history (last 30 days)
- Webhook support for updates
-
Security & Privacy
- AES-256-GCM encryption for access tokens
- Environment-based configuration
- Rate limiting protection
- No credential storage
- Bank-level security through Plaid
-
Robust Backend
- RESTful API with Express.js
- PostgreSQL database with connection pooling
- Comprehensive error handling
- Winston logging system
- Docker support for easy deployment
Unlike traditional web apps, this bot uses Telegram as the entire user interface:
- No frontend code needed - Telegram handles all UI rendering
- Cross-platform - Works on iOS, Android, Web, Desktop automatically
- Built-in auth - Telegram manages user identity
- Rich UI - Buttons, keyboards, inline menus provided by Telegram
- Users interact via chat - Simple commands like
/balanceor/transactions
The flow: User's Telegram App β Your Bot β Express API β PostgreSQL + Plaid β Bank Data
π For complete deployment instructions, see DEPLOYMENT.md
Before you begin, ensure you have the following installed:
- Node.js 18.x or higher
- PostgreSQL 14.x or higher
- npm or yarn package manager
- Telegram Bot Token (from @BotFather)
- Plaid Account (Sign up at Plaid.com)
git clone https://github.com/yourusername/telegram-plaid-bot.git
cd telegram-plaid-botnpm installCopy the example environment file and configure it:
cp .env.example .envEdit .env with your credentials:
# Telegram Bot Token (get from @BotFather)
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
# Plaid Credentials (from Plaid Dashboard)
PLAID_CLIENT_ID=your_plaid_client_id
PLAID_SECRET=your_plaid_secret
PLAID_ENV=sandbox # Use 'sandbox' for testing, 'production' for live
# Database Connection
DATABASE_URL=postgresql://user:password@localhost:5432/telegram_plaid
# Server Configuration
PORT=3000
API_BASE_URL=http://localhost:3000
# Security (IMPORTANT: Change these!)
ENCRYPTION_KEY=your_32_character_encryption_key_here
JWT_SECRET=your_jwt_secret_here
# Logging
LOG_LEVEL=infoImportant Security Notes:
ENCRYPTION_KEYmust be exactly 32 characters- Never commit
.envfile to version control - Use strong, random values for encryption keys
- In production, use environment variables or secrets management
Create the database:
createdb telegram_plaidInitialize the schema:
npm run init-dbdocker-compose up -d dbThe database will be automatically initialized with the schema.
npm run devThis uses nodemon for automatic reloading on file changes.
npm startBuild and run everything with Docker Compose:
docker-compose up -dStop the application:
docker-compose downView logs:
docker-compose logs -f app| Command | Description |
|---|---|
/start |
Welcome message and initialization |
/link |
Connect your bank account via Plaid |
/balance |
View all connected account balances |
/transactions |
View recent transactions (last 30 days) |
/help |
Display help information |
The bot also provides interactive buttons:
- π³ Link Account - Same as
/link - π° Balance - Same as
/balance - π Transactions - Same as
/transactions - β Help - Same as
/help
POST /api/plaid/create-link-token
Content-Type: application/json
{
"telegram_id": 123456789
}
Response:
{
"success": true,
"link_token": "link-sandbox-xxx",
"expiration": "2024-01-01T12:00:00Z"
}POST /api/plaid/exchange-token
Content-Type: application/json
{
"public_token": "public-sandbox-xxx",
"telegram_id": 123456789
}
Response:
{
"success": true,
"institution_name": "Chase"
}GET /api/plaid/accounts/:telegram_id
Response:
{
"success": true,
"accounts": [
{
"name": "Plaid Checking",
"balance": 100.00,
"available": 95.00,
"type": "depository",
"subtype": "checking",
"institution": "Chase"
}
]
}GET /api/plaid/transactions/:telegram_id?start_date=2024-01-01&end_date=2024-01-31
Response:
{
"success": true,
"transactions": [
{
"transaction_id": "xxx",
"name": "Uber",
"amount": 12.50,
"date": "2024-01-15",
"category": ["Transportation"],
"pending": false,
"institution": "Chase"
}
]
}POST /api/webhook/plaid
Content-Type: application/json
{
"webhook_type": "TRANSACTIONS",
"webhook_code": "DEFAULT_UPDATE",
"item_id": "xxx"
}
Response:
{
"received": true
}GET /health
Response:
{
"status": "ok",
"timestamp": "2024-01-01T12:00:00.000Z"
}Plaid provides a sandbox environment for testing without real bank connections.
When using Plaid Link in sandbox mode:
- Institution: Search for "First Platypus Bank"
- Username:
user_good - Password:
pass_good - MFA:
1234(if prompted)
- Start the bot with
/start - Use
/linkto get a link token - In a real implementation, you'd complete Plaid Link flow in a web interface
- The bot will guide you through the connection process
- Use
/balanceto view connected accounts - Use
/transactionsto see transaction history
telegram-plaid-bot/
βββ src/
β βββ bot/ # Telegram bot
β β βββ index.js # Bot initialization
β β βββ commands/ # Command handlers
β β β βββ start.js
β β β βββ link.js
β β β βββ balance.js
β β β βββ transactions.js
β β β βββ help.js
β β βββ middleware/ # Bot middleware
β β βββ auth.js
β βββ api/ # Express API
β β βββ server.js # Server setup
β β βββ routes/ # Route definitions
β β β βββ plaid.js
β β β βββ webhook.js
β β βββ controllers/ # Request handlers
β β βββ plaidController.js
β β βββ webhookController.js
β βββ services/ # Business logic
β β βββ plaidService.js # Plaid API wrapper
β β βββ userService.js # User operations
β β βββ encryptionService.js # Token encryption
β βββ models/ # Data models
β β βββ User.js
β β βββ PlaidConnection.js
β βββ database/ # Database setup
β β βββ connection.js # DB connection pool
β β βββ init.sql # Schema definition
β β βββ init.js # Initialization script
β βββ config/ # Configuration
β β βββ index.js
β βββ utils/ # Utilities
β β βββ logger.js # Winston logger
β β βββ errorHandler.js # Error handling
β βββ index.js # Application entry point
βββ .env.example # Environment template
βββ .gitignore
βββ package.json
βββ Dockerfile
βββ docker-compose.yml
βββ DEPLOYMENT.md # Complete deployment guide
βββ README.md
This application can be deployed to various platforms. The Telegram bot serves as your GUI - no frontend deployment needed!
-
Heroku (Easiest for beginners)
heroku create my-telegram-bot heroku addons:create heroku-postgresql:mini git push heroku main
-
DigitalOcean/VPS (Best for production)
- Install Node.js, PostgreSQL, PM2
- Clone repo, configure .env
- Start with
pm2 start src/index.js
-
Docker (Recommended)
docker-compose up -d
- Get Telegram Bot Token: Talk to @BotFather on Telegram
- Get Plaid Credentials: Sign up at Plaid.com
- Set Environment Variables: Copy
.env.exampleand fill in your credentials - Initialize Database: Run
npm run init-db - Start Application: The bot will be your GUI automatically!
π For detailed deployment instructions (cloud, VPS, Docker, monitoring), see DEPLOYMENT.md
-
Token Encryption
- All Plaid access tokens encrypted with AES-256-GCM
- Unique initialization vectors for each encryption
- Authentication tags for integrity verification
-
Environment Security
- All secrets in environment variables
.envexcluded from version control- Validation of required environment variables on startup
-
API Security
- Helmet.js for HTTP security headers
- CORS configured for controlled access
- Rate limiting (60 requests/minute per IP)
- Input validation on all endpoints
-
Database Security
- Parameterized queries prevent SQL injection
- Connection pooling with timeouts
- CASCADE deletes for data integrity
-
Error Handling
- No sensitive data in error messages
- Production mode hides stack traces
- Comprehensive logging without secrets
-
Production Recommendations
- Use HTTPS for all communications
- Set up SSL/TLS for database connections
- Implement proper secrets management (AWS Secrets Manager, etc.)
- Enable webhook signature verification
- Regular security audits
- Keep dependencies updated
- Verify
TELEGRAM_BOT_TOKENis correct - Check bot is running:
docker-compose psor check process - Review logs:
docker-compose logs apportail -f combined.log
- Ensure PostgreSQL is running
- Verify
DATABASE_URLis correct - Check database exists:
psql -l - Run database initialization:
npm run init-db
- Verify
PLAID_CLIENT_IDandPLAID_SECRET - Check
PLAID_ENVmatches your credentials (sandbox/production) - Review Plaid error codes in logs
- Ensure test credentials are correct for sandbox
ENCRYPTION_KEYmust be exactly 32 characters- Don't change key after encrypting tokens (they'll be unreadable)
- If needed, generate new key:
node -e "console.log(crypto.randomBytes(16).toString('hex'))"
- Default: 60 requests/minute
- Adjust in
src/api/server.jsif needed - Wait or increase limit for legitimate high-volume use
Check application logs:
# Combined logs
tail -f combined.log
# Error logs only
tail -f error.log
# Docker logs
docker-compose logs -f appContributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow existing code style
- Add comments for complex logic
- Update README for new features
- Test thoroughly before submitting
- Keep commits focused and descriptive
This project is licensed under the MIT License - see the LICENSE file for details.
- Plaid for the banking API
- Telegraf for the Telegram bot framework
- Express for the web framework
- All contributors and supporters
For issues and questions:
- Open an issue on GitHub
- Check the Plaid API Documentation
- Review Telegraf Documentation
This bot handles sensitive financial information. Always:
- Use in compliance with local regulations
- Implement additional security measures for production
- Never store or log sensitive user data
- Follow Plaid's terms of service
- Obtain proper user consent
- Keep all dependencies updated
Happy Banking! π¦