Skip to content

About

Whatsapp Chatbot con modelo de lenguaje

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– WhatsApp AI Chatbot

WhatsApp AI chatbot powered by Claude Sonnet 4 (Anthropic API) and Twilio WhatsApp API. Built with Node.js, TypeScript, Express.js, PostgreSQL, and Redis.

πŸ“‹ Features

  • πŸ€– AI-powered conversations using Claude Sonnet 4
  • πŸ’¬ WhatsApp integration via Twilio
  • πŸ—„οΈ PostgreSQL for data persistence
  • ⚑ Redis for conversation context caching
  • πŸ—οΈ Clean Architecture & Domain-Driven Design (DDD)
  • πŸ”’ Security-first approach (Helmet, CORS, rate limiting)
  • πŸ“Š Structured logging with Winston
  • πŸ§ͺ Comprehensive testing (Jest, Supertest)
  • 🐳 Docker support for development and production

πŸ›οΈ Architecture

This project follows Clean Code and Domain-Driven Design (DDD) principles:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Presentation Layer        β”‚  ← Controllers (HTTP handling)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Application Layer         β”‚  ← Services (use cases, orchestration)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Domain Layer              β”‚  ← Entities, Value Objects (business logic)
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Infrastructure Layer      β”‚  ← Repositories, External APIs
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

src/
β”œβ”€β”€ config/           # Configuration (env validation, DB, Redis)
β”œβ”€β”€ controllers/      # HTTP request handlers (thin)
β”œβ”€β”€ services/         # Business logic orchestration
β”œβ”€β”€ repositories/     # Data access layer
β”œβ”€β”€ middleware/       # Express middleware (error, validation, rate limit)
β”œβ”€β”€ utils/            # Utilities (logger, errors, helpers)
β”œβ”€β”€ types/            # TypeScript type definitions
β”œβ”€β”€ routes/           # Route definitions
β”œβ”€β”€ app.ts            # Express app setup
└── server.ts         # Server entry point

πŸš€ Getting Started

Prerequisites

  • Node.js: 20+ (LTS)
  • pnpm: 8+
  • PostgreSQL: 15+
  • Redis: 7+
  • Docker (optional, for development)

Installation

  1. Clone the repository

    git clone <repository-url>
    cd chatbot-whatsapp
  2. Install dependencies

    pnpm install
  3. Setup environment variables

    cp .env.example .env

    Edit .env and fill in your credentials:

    • Database URL (PostgreSQL)
    • Redis URL
    • Twilio credentials (Account SID, Auth Token, Phone Number)
    • Anthropic API key
  4. Start Docker services (PostgreSQL + Redis)

    docker-compose up -d postgres redis
  5. Run database migrations

    pnpm prisma:migrate
    pnpm prisma:generate
  6. Start development server

    pnpm dev

The server will start on http://localhost:3001

πŸ“ Available Scripts

Development

pnpm dev                # Start development server with hot reload
pnpm build              # Build TypeScript to JavaScript
pnpm start              # Start production server

Code Quality

pnpm lint               # Run ESLint
pnpm lint:fix           # Fix ESLint errors
pnpm format             # Format code with Prettier
pnpm format:check       # Check code formatting

Database

pnpm prisma:generate    # Generate Prisma Client
pnpm prisma:migrate     # Run migrations (development)
pnpm prisma:studio      # Open Prisma Studio GUI
pnpm prisma:deploy      # Deploy migrations (production)

Testing

pnpm test               # Run all tests
pnpm test:watch         # Run tests in watch mode
pnpm test:coverage      # Run tests with coverage report

πŸ”§ Configuration

Environment Variables

Variable Description Required Example
NODE_ENV Environment mode No development
PORT Server port No 3001
DATABASE_URL PostgreSQL connection string Yes postgresql://user:pass@localhost:5432/db
REDIS_URL Redis connection string Yes redis://localhost:6379
TWILIO_ACCOUNT_SID Twilio Account SID Yes ACxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN Twilio Auth Token Yes your_auth_token
TWILIO_PHONE_NUMBER Twilio WhatsApp number Yes whatsapp:+14155238886
ANTHROPIC_API_KEY Claude API key Yes sk-ant-xxxxx
LOG_LEVEL Logging level No info

🐳 Docker

Development

# Start all services (app, postgres, redis)
docker-compose up -d

# View logs
docker-compose logs -f app

# Stop services
docker-compose down

Production

docker-compose -f docker-compose.prod.yml up -d

πŸ“Š API Endpoints

Health Check

GET /health

Returns application health status:

{
  "status": "ok",
  "timestamp": "2024-01-01T00:00:00.000Z",
  "uptime": 3600,
  "environment": "development",
  "version": "1.0.0",
  "checks": {
    "server": { "status": "ok" },
    "memory": {
      "status": "ok",
      "usage": {
        "rss": "50MB",
        "heapTotal": "25MB",
        "heapUsed": "20MB"
      }
    }
  }
}

WhatsApp Webhook

POST /webhook/whatsapp

Receives incoming WhatsApp messages from Twilio (to be implemented).

πŸ§ͺ Testing

Run tests with:

pnpm test

Coverage goals:

  • Global: 70%
  • Services: 80%
  • Controllers: 70%

πŸ”’ Security

  • βœ… Helmet.js for secure HTTP headers
  • βœ… CORS configuration
  • βœ… Rate limiting (Redis-based)
  • βœ… Input validation (Zod)
  • βœ… Twilio webhook signature validation
  • βœ… Environment variable validation
  • βœ… No secrets in code

πŸ“š Tech Stack

  • Runtime: Node.js 20+
  • Language: TypeScript 5+
  • Framework: Express.js 4
  • AI: Claude Sonnet 4 (Anthropic API)
  • Messaging: Twilio WhatsApp API
  • Database: PostgreSQL 15+ (Prisma ORM)
  • Cache: Redis 7
  • Logging: Winston
  • Testing: Jest, Supertest
  • Linting: ESLint + Prettier
  • Package Manager: pnpm

🀝 Contributing

This project follows strict Clean Code and DDD principles:

  1. Read .claude/PRINCIPLES.md before contributing
  2. Functions must be < 30 lines
  3. No magic numbers - use constants
  4. TypeScript strict mode (no any)
  5. Comprehensive error handling
  6. Structured logging
  7. Tests required (70%+ coverage)

πŸ“„ License

MIT

πŸ‘₯ Authors

  • Backend Development Team
  • AI Integration Team
  • DevOps Team

Built with ❀️ using Claude Code

About

Whatsapp Chatbot con modelo de lenguaje

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages