A modern, location-based attendance management system using Telegram bot integration, built with Next.js, TypeScript, Prisma, and PostgreSQL.
- Location-Based Verification: GPS validation within 100m radius of office
- Telegram Bot Integration: Easy-to-use bot interface for employees
- Real-Time Tracking: Instant check-in/check-out with working hours calculation
- Admin Dashboard: Comprehensive web interface for management
- Late/Early Detection: Automatic detection with reason collection
- Secure & Scalable: Modern architecture with comprehensive logging
- Location: El Mansoura CIH Office
- Coordinates: 31.0417Β°N, 31.3778Β°E (29R3+7Q El Mansoura 1, Egypt)
- Verification Radius: 100 meters
- Work Hours: 09:00 - 17:00 (configurable)
- Node.js 18+ and npm/yarn
- PostgreSQL database
- Telegram Bot Token (from @BotFather)
- Clone and setup
git clone <repository-url>
cd mansoura-attendance-system
npm install
- Environment Configuration
cp .env.example .env
Edit .env
with your configuration:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/attendance_db"
# Telegram Bot
TELEGRAM_BOT_TOKEN="your_bot_token_here"
TELEGRAM_WEBHOOK_URL="https://your-domain.com/api/bot/webhook"
# Office Location (El Mansoura CIH)
OFFICE_LATITUDE=31.0417
OFFICE_LONGITUDE=31.3778
OFFICE_RADIUS=100
# Work Hours
WORK_START_HOUR=9
WORK_END_HOUR=17
# Security
NEXTAUTH_SECRET="your_secure_secret_here"
NEXTAUTH_URL="http://localhost:3000"
# Admin Settings
ADMIN_PASSWORD="secure_admin_password"
- Database Setup
# Generate Prisma client
npx prisma generate
# Run database migrations
npx prisma db push
# Optional: Add sample data
npx prisma db seed
- Start Development Server
npm run dev
Visit http://localhost:3000
to see the application.
-
Create Bot with @BotFather
- Send
/newbot
to @BotFather - Choose name:
CIH Mansoura Attendance
- Choose username:
CIH_Mansoura_bot
- Save the token to your
.env
file
- Send
-
Set Webhook
curl -X POST "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook" \
-d "url=https://your-domain.com/api/bot/webhook"
- Bot Commands
/start
- Register as new employee/status
- Check current attendance status/history
- View attendance history/help
- Show available commands
mansoura-attendance-system/
βββ prisma/
β βββ schema.prisma # Database schema
βββ src/
β βββ app/
β β βββ api/ # API routes
β β β βββ attendance/ # Attendance management
β β β βββ bot/ # Telegram webhook
β β β βββ employees/ # Employee management
β β βββ admin/ # Admin dashboard
β β βββ globals.css # Global styles
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Landing page
β βββ components/ # React components
β βββ lib/
β β βββ prisma.ts # Database connection
β β βββ telegram-bot.ts # Bot implementation
β βββ types/
β β βββ index.ts # TypeScript types
β βββ utils/
β βββ date.ts # Date utilities
β βββ location.ts # Location utilities
βββ .env.example # Environment template
βββ next.config.js # Next.js configuration
βββ package.json # Dependencies
βββ tailwind.config.js # Tailwind CSS config
βββ tsconfig.json # TypeScript config
GET /api/attendance
- Get attendance recordsPOST /api/attendance
- Create attendance record
GET /api/employees
- List employeesPOST /api/employees
- Create employeePUT /api/employees
- Update employeeDELETE /api/employees
- Deactivate employee
POST /api/bot/webhook
- Telegram webhook endpoint
Access the admin dashboard at /admin
to:
- View real-time attendance statistics
- Monitor recent employee activity
- Manage employee records
- Generate attendance reports
- Configure system settings
# View database in browser
npx prisma studio
# Reset database
npx prisma db push --force-reset
# Generate new migration
npx prisma migrate dev --name description
# Run type checking
npm run type-check
# Run linting
npm run lint
# Build for production
npm run build
- Database: Set up PostgreSQL (recommended: Vercel Postgres, Supabase, or Railway)
- Hosting: Deploy to Vercel, Netlify, or similar platform
- Environment Variables: Configure all required environment variables
-
Connect Repository
- Import project to Vercel
- Configure environment variables
- Deploy
-
Database Setup
# After deployment, run migrations npx prisma db push
-
Webhook Configuration
# Update Telegram webhook with production URL curl -X POST "https://api.telegram.org/bot<TOKEN>/setWebhook" \ -d "url=https://your-app.vercel.app/api/bot/webhook"
# Build Docker image
docker build -t mansoura-attendance .
# Run container
docker run -p 3000:3000 --env-file .env mansoura-attendance
- Start conversation with the bot
- Share contact information
- Complete registration form
- Go to office location (within 100m)
- Send location to bot via Telegram
- Bot automatically detects check-in/out intent
- Receive confirmation with working hours
- Send
/status
to see current attendance - Send
/history
for attendance history
- Location-based verification
- Encrypted data transmission
- Comprehensive audit logging
- Rate limiting on API endpoints
- Input validation and sanitization
Modify work hours in environment variables:
WORK_START_HOUR=9
WORK_END_HOUR=17
Update office coordinates:
OFFICE_LATITUDE=31.0417
OFFICE_LONGITUDE=31.3778
OFFICE_RADIUS=100
Configure bot settings:
TELEGRAM_BOT_TOKEN="your_token"
TELEGRAM_WEBHOOK_URL="https://your-domain.com/api/bot/webhook"
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature
) - Commit changes (
git commit -m 'Add amazing feature'
) - Push to branch (
git push origin feature/amazing-feature
) - Open Pull Request
-
Bot not responding
- Check webhook URL configuration
- Verify bot token
- Check server logs
-
Location verification failing
- Ensure GPS permissions enabled
- Check office coordinates configuration
- Verify radius settings
-
Database connection issues
- Verify DATABASE_URL format
- Check database server status
- Run
npx prisma db push
For support or questions:
- Check logs in admin dashboard
- Review environment configuration
- Verify all required services are running
This project is licensed under the MIT License - see the LICENSE file for details.
El Mansoura CIH - Modern Attendance Management System π 29R3+7Q El Mansoura 1, Egypt