A professional-grade NestJS Telegram bot that delivers daily Quran Ayahs with translations in multiple languages. Built with queue processing, scheduled tasks, and a clean architecture.
- Daily Scheduled Ayah: Sends a random Quran Ayah every day at 9:00 AM
- Multi-Language Support:
- ๐ฎ๐ท Farsi (Persian)
- ๐ฌ๐ง English
- Smart Queue System: Bull-based queue for reliable message delivery
- Translation Support: Automatically fetches Ayah translations in selected language
- User Sessions: Maintains user language preferences
- Interactive UI: Inline buttons for easy navigation
- Error Handling: Comprehensive error handling and logging
- Monitoring: Queue statistics and health checks
- Node.js 16+
- Redis Server (for queue processing)
- Telegram Bot Token (from @BotFather)
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Edit .env with your configuration
TELEGRAM_BOT_TOKEN=your_token_here
REDIS_HOST=localhost
REDIS_PORT=6379npm run start:devnpm run build
npm run start:prodsrc/
โโโ config/ # Configuration management
โโโ interfaces/ # TypeScript interfaces
โโโ modules/
โ โโโ telegram/ # Telegram bot handlers and service
โ โโโ quran/ # Quran API service and user management
โ โโโ queue/ # Bull queue producers and consumers
โ โโโ scheduler/ # Cron job scheduling
โโโ services/ # Business logic services
โโโ app.module.ts # Root module
โโโ main.ts # Application entry point
# Telegram Configuration
TELEGRAM_BOT_TOKEN=your_bot_token
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# Application Settings
NODE_ENV=development
LOG_LEVEL=debug
# Daily Ayah Schedule
SEND_AYAH_HOUR=9
SEND_AYAH_MINUTE=0/start
The bot will welcome you and ask to select language:
- ๐ฎ๐ท Farsi
- ๐ฌ๐ง English
After selecting language, the bot sends a random Ayah from the Quran with translation.
Use the "Send Another Ayah" button to get another random Ayah.
The bot automatically sends a random Ayah to all users every day at 9:00 AM (Tehran timezone).
- Handles all Telegram interactions
- Command and callback query processing
- Message formatting
- Quran API integration
- Random Ayah selection
- Translation management
- Bull queue processing
- Job producers and consumers
- Retry logic with exponential backoff
- Daily broadcast scheduling
- Cron job management
The bot uses Bull (Redis-backed queue) for reliable message delivery:
- Job Priority: Daily broadcasts (priority 10), User requests (priority 5)
- Retry Policy: 3 attempts with exponential backoff
- Job Cleanup: Completed jobs automatically removed
{
chatId: number;
language: 'fa' | 'en';
type: 'daily' | 'user_requested';
timestamp: number;
}The bot integrates with the Quran.com API:
- Endpoint:
https://api.quran.com/api/v4 - Automatic Surah caching
- Translation support (Farsi & English)
- Comprehensive error logging
- Graceful fallbacks
- Queue job retry mechanism
- User-friendly error messages
// Service logging
Logger.log('Information message');
Logger.error('Error message', error);
Logger.debug('Debug message');
Logger.warn('Warning message');# Returns queue statistics
- Total jobs
- Active jobs
- Delayed jobs
- Failed jobs
- Completed jobs- Bot connectivity
- Redis connection
- Quran API availability
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY dist ./dist
EXPOSE 3000
CMD ["npm", "run", "start:prod"]# Production
NODE_ENV=production
LOG_LEVEL=error
SEND_AYAH_HOUR=9
SEND_AYAH_MINUTE=0npm run test
npm run test:watch
npm run test:cov- @nestjs/core - NestJS framework
- @nestjs/bull - Queue management
- @nestjs/schedule - Task scheduling
- telegraf - Telegram Bot API
- bull - Queue library
- axios - HTTP client
- redis - Redis client
- Verify
TELEGRAM_BOT_TOKENis correct - Check if Redis is running
- Review logs for connection errors
- Ensure Redis is accessible
- Check Redis connection settings
- Review consumer logs
- Verify Quran API is accessible
- Check language code mapping
- Ensure translation IDs are correct
For issues and questions:
- Check the logs
- Verify environment configuration
- Review NestJS documentation
MIT
Built with โค๏ธ by a Senior Backend Developer
Note: This bot follows production-grade best practices including:
- Clean architecture
- SOLID principles
- Comprehensive error handling
- Scalable queue system
- Type-safe implementation
- Professional logging