npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zapzap-hashino

v1.0.0

Published

Production-ready WhatsApp Business API backend with AI image analysis using OpenAI and Anthropic

Readme

WhatsApp AI Backend

A comprehensive WhatsApp Business API backend with AI-powered image analysis capabilities using OpenAI and Anthropic.

🚀 Features

  • WhatsApp Business API Integration: Send/receive messages via WhatsApp webhook
  • AI-Powered Image Analysis: Analyze images using OpenAI GPT-4 Vision and Anthropic Claude-3
  • Multi-Provider AI Support: Switch between OpenAI and Anthropic for different use cases
  • File Upload & Processing: Upload and process images with automatic resizing
  • Rate Limiting: Built-in rate limiting for API protection
  • Comprehensive Logging: Winston-based logging with different levels
  • Health Monitoring: Health check endpoints for monitoring
  • Type-Safe: Full TypeScript implementation with strict typing

📋 Prerequisites

  • Node.js 18+
  • TypeScript
  • WhatsApp Business Account with API access
  • OpenAI API Key
  • Anthropic API Key

🛠️ Installation

  1. Clone and navigate to the project:
cd whatsapp-ai-backend
  1. Install dependencies:
npm install
  1. Copy environment configuration:
cp .env.example .env
  1. Configure your environment variables in .env:
# Server Configuration
PORT=3000
NODE_ENV=development

# AI Services
OPENAI_API_KEY=your_openai_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here

# WhatsApp Business API
WHATSAPP_API_URL=https://graph.facebook.com/v18.0
WHATSAPP_ACCESS_TOKEN=your_whatsapp_access_token_here
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id_here
WHATSAPP_VERIFY_TOKEN=your_verify_token_here

# File Upload
MAX_FILE_SIZE=10485760
UPLOAD_PATH=./uploads

# Logging
LOG_LEVEL=info
LOG_FILE=app.log

# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX=100

🚀 Usage

Development

npm run dev

Production

npm run build
npm start

Testing

npm test

Linting & Type Checking

npm run lint
npm run typecheck

📡 API Endpoints

WhatsApp Endpoints

GET /api/whatsapp/webhook

Webhook verification for WhatsApp Business API.

POST /api/whatsapp/webhook

Webhook endpoint for receiving WhatsApp messages.

POST /api/whatsapp/send-message

Send messages via WhatsApp Business API.

Body:

{
  "to": "+5511999999999",
  "message": "Hello from AI!",
  "type": "text"
}

AI Endpoints

POST /api/ai/analyze

Analyze images or text using AI.

Body:

{
  "imageUrl": "https://example.com/image.jpg",
  "text": "Optional text to analyze",
  "provider": "openai",
  "options": {
    "prompt": "Analyze this image",
    "temperature": 0.7,
    "max_tokens": 500
  }
}

POST /api/ai/analyze-upload

Upload and analyze an image.

Form Data:

  • image: Image file
  • prompt: Analysis prompt
  • provider: AI provider (openai/anthropic)

POST /api/ai/generate

Generate text responses.

Body:

{
  "prompt": "Write a haiku about technology",
  "provider": "anthropic"
}

GET /api/ai/providers

Get available AI providers and their capabilities.

Health Endpoints

GET /api/health

Get application health status.

GET /api/health/ready

Check if application is ready to serve requests.

🤖 WhatsApp Bot Features

The bot automatically responds to different types of messages:

  • Text Messages: Generates AI-powered responses
  • Images: Analyzes images and provides detailed descriptions
  • Greetings: Responds with welcome message in Portuguese/English
  • Help Requests: Provides usage instructions

Supported Commands

  • Send "hello", "hi", or "oi" for greetings
  • Send "help" or "ajuda" for assistance
  • Send images for AI analysis
  • Use keywords like "analyze" or "describe" for detailed analysis

🏗️ Project Structure

src/
├── types/           # TypeScript type definitions
├── services/        # Business logic services
│   ├── aiService.ts     # AI integration (OpenAI + Anthropic)
│   └── whatsappService.ts # WhatsApp Business API
├── routes/          # API route handlers
│   ├── ai.ts           # AI-related endpoints
│   ├── whatsapp.ts     # WhatsApp webhook endpoints
│   └── health.ts       # Health check endpoints
├── middleware/      # Express middleware
│   ├── errorHandler.ts # Error handling
│   └── rateLimiter.ts  # Rate limiting
├── utils/           # Utility functions
│   ├── config.ts       # Environment configuration
│   └── logger.ts       # Winston logging setup
└── index.ts         # Application entry point

🔧 Configuration

AI Providers

  • OpenAI: GPT-4 Vision for image analysis, GPT-3.5 Turbo for text
  • Anthropic: Claude-3 Sonnet for image analysis, Claude-3 Haiku for text

File Upload

  • Maximum file size: 10MB (configurable)
  • Supported formats: JPEG, PNG, GIF, WebP
  • Automatic image resizing to 1024x1024 max
  • Files stored in ./uploads directory

Rate Limiting

  • Default: 100 requests per 15 minutes per IP
  • Configurable via environment variables

📊 Monitoring

Logging

  • Winston-based logging with multiple transports
  • Separate error log file
  • Structured JSON logging for production
  • Console logging for development

Health Checks

  • /api/health: Application status
  • /api/health/ready: Readiness probe
  • Memory usage monitoring
  • Uptime tracking

🔒 Security Features

  • Helmet: Security headers
  • CORS: Cross-origin resource sharing
  • Rate Limiting: Request throttling
  • Input Validation: Joi schema validation
  • Error Handling: Secure error responses
  • File Upload Security: Type and size validation

🐳 Docker Support (Optional)

Create Dockerfile:

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
EXPOSE 3000
CMD ["npm", "start"]

📝 License

MIT License - See LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📞 Support

For support, create an issue in the GitHub repository.