A comprehensive Telegram bot for driver onboarding and management with AI-powered document analysis, built with Node.js, TypeScript, Supabase, and Digital Ocean Spaces.
- Step-by-step onboarding process with guided prompts
- Document collection: CDL, DOT Medical Certificate, Driver Photo
- AI-powered document analysis using OpenAI GPT-4 Vision
- Automatic data extraction from uploaded documents
- HR notification system for review and approval
- Status tracking: Pending, Active, Inactive, Suspended
- Profile management with all driver information
- Document expiry tracking and notifications
- Advance payment requests with amount and reason
- Vacation requests with date range and reason
- Automatic routing to appropriate departments
- Status tracking for all requests
- Document analysis for CDL and DOT Medical Certificates
- Data validation and confidence scoring
- Automatic information extraction from uploaded documents
- Supabase PostgreSQL for data storage
- Digital Ocean Spaces (S3-compatible) for file storage
- Secure document management with public URLs
- Backend: Node.js, TypeScript, Express
- Bot Framework: Telegraf
- Database: Supabase (PostgreSQL)
- File Storage: Digital Ocean Spaces (S3-compatible)
- AI: OpenAI GPT-4 Vision
- Validation: Joi
- Security: Helmet, CORS
- Node.js 18+
- npm or yarn
- Telegram Bot Token (from @BotFather)
- OpenAI API Key
- Supabase Account
- Digital Ocean Spaces Account
-
Clone the repository
git clone <repository-url> cd tg-driver-helper
-
Install dependencies
npm install
-
Set up environment variables
cp env.example .env
Edit
.envwith your configuration:# Telegram Bot Configuration TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here TELEGRAM_HR_GROUP_ID=your_hr_group_chat_id_here # OpenAI Configuration OPENAI_API_KEY=your_openai_api_key_here # Supabase Configuration SUPABASE_URL=your_supabase_url_here SUPABASE_ANON_KEY=your_supabase_anon_key_here SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key_here # Digital Ocean Spaces (S3) Configuration DO_SPACES_ENDPOINT=your_do_spaces_endpoint_here DO_SPACES_KEY=your_do_spaces_access_key_here DO_SPACES_SECRET=your_do_spaces_secret_key_here DO_SPACES_BUCKET=your_bucket_name_here DO_SPACES_REGION=your_region_here # Application Configuration NODE_ENV=development PORT=3000
-
Build the project
npm run build
-
Start the application
npm start
# Run in development mode with hot reload
npm run dev
# Run with nodemon for auto-restart
npm run watchCREATE TABLE drivers (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
telegram_id BIGINT UNIQUE NOT NULL,
full_name TEXT NOT NULL,
phone_number TEXT,
cdl_number TEXT,
cdl_expiry_date DATE,
dot_medical_certificate TEXT,
dot_medical_expiry_date DATE,
driver_photo_url TEXT,
status TEXT DEFAULT 'pending',
onboarding_completed BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);CREATE TABLE advance_payment_requests (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
driver_id UUID REFERENCES drivers(id) ON DELETE CASCADE,
amount DECIMAL(10,2) NOT NULL,
reason TEXT NOT NULL,
status TEXT DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);CREATE TABLE vacation_requests (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
driver_id UUID REFERENCES drivers(id) ON DELETE CASCADE,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
reason TEXT NOT NULL,
status TEXT DEFAULT 'pending',
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);/start- Start onboarding or show main menu/request_advance- Request advance payment/request_vacation- Request vacation/status- Check your status/help- Show help message
/approve_[driver_id]- Approve driver application/reject_[driver_id]- Reject driver application
- Driver starts bot with
/start - Collects basic information:
- Full name
- Phone number
- CDL number and expiry
- DOT Medical Certificate and expiry
- Uploads documents:
- Driver photo
- CDL document
- DOT Medical Certificate
- AI analysis of uploaded documents
- HR notification with all information
- HR approval/rejection process
- Driver status update and notification
- Environment variable validation
- Input sanitization and validation
- Secure file uploads with content type validation
- CORS protection
- Helmet security headers
- Graceful error handling
src/
βββ config/
β βββ database.ts # Supabase configuration
β βββ storage.ts # Digital Ocean Spaces configuration
βββ services/
β βββ ai.ts # OpenAI integration
β βββ telegram.ts # Telegram bot logic
βββ types/
β βββ index.ts # TypeScript type definitions
βββ index.ts # Main application entry point
- Set up a production server (VPS, Heroku, Railway, etc.)
- Configure environment variables
- Set up SSL certificate for HTTPS
- Configure webhook URL for Telegram bot
- Create Supabase project
- Run database migrations
- Configure RLS (Row Level Security) policies
- Set up backup strategy
- Create Digital Ocean Spaces bucket
- Configure CORS policies
- Set up access keys
- Test file upload/download
- Create bot with @BotFather
- Get bot token
- Add bot to HR group
- Get group chat ID
- Configure webhook (optional)
- Create OpenAI account
- Generate API key
- Configure billing
- Test API access
- Create Supabase project
- Get project URL and keys
- Configure database schema
- Set up authentication (if needed)
- Create Spaces bucket
- Generate access keys
- Configure CORS
- Test file operations
GET /health- Application health status
-
Bot not responding
- Check bot token
- Verify webhook configuration
- Check server logs
-
Database connection issues
- Verify Supabase credentials
- Check network connectivity
- Validate database schema
-
File upload failures
- Check Digital Ocean Spaces credentials
- Verify bucket permissions
- Check file size limits
-
AI analysis errors
- Verify OpenAI API key
- Check API quota
- Validate image format
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the documentation
Stay updated with the latest features and bug fixes by:
- Following the repository
- Checking release notes
- Monitoring the changelog