
- Replaced Python/FastAPI implementation with Node.js/Express/TypeScript
- Added Prisma ORM with SQLite database
- Implemented JWT authentication with bcrypt password hashing
- Created comprehensive task management API with CRUD operations
- Integrated Twilio WhatsApp Business API for notifications
- Added OpenAI integration for intelligent task scheduling
- Implemented automated background jobs with node-cron
- Added comprehensive error handling and validation
- Structured logging with Winston
- Complete API documentation and setup instructions
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
5.4 KiB
5.4 KiB
WhatsApp AI Task Scheduling Service
A Node.js/Express/TypeScript application that provides intelligent task scheduling with WhatsApp notifications and AI-powered optimization.
Features
- Task Management: Create, update, delete, and track tasks with priorities and due dates
- AI-Powered Scheduling: Uses OpenAI to suggest optimal times for task completion
- WhatsApp Integration: Sends task reminders and notifications via WhatsApp using Twilio
- User Authentication: JWT-based authentication system
- Automated Scheduling: Background jobs for daily reminders and overdue task notifications
- Health Monitoring: Built-in health check endpoints
Tech Stack
- Runtime: Node.js with TypeScript
- Framework: Express.js
- Database: SQLite with Prisma ORM
- Authentication: JWT tokens with bcrypt password hashing
- WhatsApp: Twilio WhatsApp Business API
- AI: OpenAI GPT-3.5 for intelligent scheduling
- Scheduling: node-cron for background jobs
- Logging: Winston for structured logging
Prerequisites
- Node.js 18+ and npm
- Environment variables (see below)
Installation
- Clone the repository
- Install dependencies:
npm install
- Copy environment configuration:
cp .env.example .env
-
Configure environment variables in
.env
file -
Generate Prisma client and run migrations:
npm run prisma:generate
npm run prisma:migrate
- Build the application:
npm run build
- Start the server:
npm start
For development:
npm run dev
Required Environment Variables
# Database
DATABASE_URL="file:./storage/db/database.db"
# JWT Authentication
JWT_SECRET="your-super-secret-jwt-key-here"
JWT_EXPIRES_IN="24h"
# Twilio WhatsApp Integration
TWILIO_ACCOUNT_SID="your-twilio-account-sid"
TWILIO_AUTH_TOKEN="your-twilio-auth-token"
TWILIO_WHATSAPP_FROM="whatsapp:+14155238886"
# OpenAI for AI Features
OPENAI_API_KEY="your-openai-api-key"
# Server Configuration
PORT=3000
NODE_ENV="development"
API Endpoints
Base URL
- GET
/
- Service information and documentation links - GET
/docs
- API documentation - GET
/api/health
- Health check endpoint
Authentication
- POST
/api/auth/register
- Register new user - POST
/api/auth/login
- User login
Tasks (Protected Routes)
- POST
/api/tasks
- Create new task - GET
/api/tasks
- Get user's tasks (with pagination and filtering) - GET
/api/tasks/:id
- Get specific task - PUT
/api/tasks/:id
- Update task - DELETE
/api/tasks/:id
- Delete task - POST
/api/tasks/:id/remind
- Send WhatsApp reminder for task
Usage Examples
Register User
curl -X POST http://localhost:3000/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "securepassword",
"fullName": "John Doe",
"whatsappNumber": "+1234567890"
}'
Create Task
curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "Complete project proposal",
"description": "Write and review the Q1 project proposal",
"priority": "HIGH",
"dueDate": "2024-02-15T17:00:00.000Z"
}'
Features Details
AI-Powered Scheduling
The service uses OpenAI to analyze task priority, due dates, and optimal work hours to suggest the best time to work on tasks.
WhatsApp Notifications
- Daily reminders for scheduled tasks (9 AM UTC)
- Overdue task notifications (6 PM UTC)
- Manual reminder triggers via API
Background Jobs
- Daily Reminders: Sends WhatsApp reminders for tasks scheduled for today
- Overdue Checks: Notifies users about overdue tasks
Database Schema
Users Table
id
,email
,password
(hashed)fullName
,phoneNumber
,whatsappNumber
isActive
,createdAt
,updatedAt
Tasks Table
id
,title
,description
status
(PENDING, IN_PROGRESS, COMPLETED, CANCELLED)priority
(LOW, MEDIUM, HIGH, URGENT)dueDate
,scheduledAt
,aiSuggestedTime
whatsappReminderSent
,whatsappCompletionSent
ownerId
, timestamps
Development
Available Scripts
npm run dev
- Start development server with hot reloadnpm run build
- Build TypeScript to JavaScriptnpm start
- Start production servernpm run lint
- Run ESLintnpm run lint:fix
- Fix ESLint issuesnpm run prisma:generate
- Generate Prisma clientnpm run prisma:migrate
- Run database migrationsnpm run prisma:studio
- Open Prisma Studio
Project Structure
src/
├── controllers/ # Request handlers
├── middleware/ # Express middleware
├── models/ # Database models (Prisma)
├── routes/ # API route definitions
├── services/ # Business logic services
├── types/ # TypeScript type definitions
└── utils/ # Utility functions
Error Handling
The application includes comprehensive error handling with:
- Structured error responses
- Request validation using Joi
- Database error handling
- Authentication error handling
- Rate limiting protection
Logging
Winston logger provides structured logging with different levels:
- Development: Console output with colors
- Production: File-based logging (error.log, combined.log)
Contributing
This project was generated by BackendIM, an AI-powered backend generation platform.