A simple, straightforward Telegram bot for managing group subscriptions with automatic payment processing and user management.
- π€ Multi-group support - One bot can manage multiple groups
- π€ Single admin per group - Simple admin management
- π³ Payment processing - Receipt upload and verification workflow
- β° Auto-expiry - Users automatically removed after 30 days
- π Webhook mode - Efficient server-side processing
- πΎ JSON persistence - Simple file-based data storage
- Node.js 16+ installed
- Telegram Bot Token from @BotFather
- Public HTTPS URL (use ngrok for development)
- Clone and setup:
git clone <repository-url>
cd telegram-subscription-bot
npm install- Configure environment:
cp .env.example .envEdit .env with your values:
BOT_TOKEN=your_bot_token_from_botfather
WEBHOOK_URL=https://your-domain.com
PORT=3000
NODE_ENV=production- Start the bot:
# Production
npm start
# Development with auto-reload
npm run dev- Message @BotFather on Telegram
- Send
/newbotand follow instructions - Copy the bot token to your
.envfile
For local development, use ngrok:
# Install ngrok
npm install -g ngrok
# Expose local port
ngrok http 3000Copy the HTTPS URL (e.g., https://abc123.ngrok.io) to your .env as WEBHOOK_URL.
Deploy to any Node.js hosting service (Heroku, Railway, DigitalOcean, etc.):
- Set environment variables
- Ensure your domain has HTTPS
- Update
WEBHOOK_URLto your production domain
- Add bot to group - Bot auto-captures group and admin info
- Private message setup - Bot sends admin a private message
- Configure payment details:
- Send
/setupto bot privately - Enter: Bank name, Account name, Account number, Price
- Send
- Setup complete - Users can now subscribe
- Start bot - User sends
/startto bot privately - Payment details - Bot shows payment information
- Make payment - User pays to provided account
- Upload receipt - User uploads payment screenshot
- Confirm payment - User clicks confirmation button
- Admin approval - Admin gets notification and manually adds user
- 30-day access - User gets 30 days access, then auto-removed
src/
βββ bot.js # Main bot logic and webhook handler
βββ handlers/
β βββ admin.js # Admin setup and management
β βββ user.js # User subscription workflow
β βββ group.js # Group event handling
βββ services/
β βββ database.js # JSON file operations
β βββ scheduler.js # 30-day expiry checker
βββ utils/
βββ constants.js # Messages and keyboards
data/
βββ database.json # Persistent data storage
The bot stores data in data/database.json:
{
"groups": {
"groupId": {
"adminId": "123456789",
"config": {
"bankName": "Example Bank",
"accountName": "John Doe",
"accountNumber": "1234567890",
"price": "$10"
},
"isSetupComplete": true,
"users": {
"userId": {
"username": "@username",
"joinDate": "2024-01-01T00:00:00.000Z",
"expiryDate": "2024-01-31T00:00:00.000Z",
"isActive": true
}
}
}
}
}| Command | Who | Description |
|---|---|---|
/start |
Users | Show subscription options |
/setup |
Admin | Configure payment details |
POST /webhook- Telegram webhook endpointGET /health- Health checkGET /- Bot status
- Multi-group support with isolated configurations
- Automatic 30-day user expiry
- Receipt upload and payment confirmation workflow
- Admin notifications for new payments
- Simple JSON-based data persistence
- Duplicate message prevention
- Graceful error handling
- Automatic payment verification (requires manual admin approval)
- Multiple admins per group
- Payment gateway integration
- Advanced user management (ban/unban)
- Message analytics or logging
- Check bot token is correct
- Verify webhook URL is accessible
- Check server logs for errors
- Ensure HTTPS URL is valid
- Test webhook endpoint:
curl https://your-domain.com/health - Check Telegram webhook status:
https://api.telegram.org/bot<TOKEN>/getWebhookInfo
- Users must start bot privately first
- Check if users blocked the bot
- Verify bot has permission to message users
- Bot token should be kept secret
- Use HTTPS for webhook URL
- Validate all user inputs
- Regular backups of database.json recommended
npm run devThe project uses nodemon for development with automatic restart on file changes.
All important events are logged to console with emojis for easy identification.
- Fork the repository
- Create a feature branch
- Make changes following the existing code style
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details.
Need help? Open an issue or contact the maintainer.