WAHA (WhatsApp HTTP API)

repository·core·Indexed 27 days ago

https://github.com/devlikeapro/waha

A REST API that allows interaction with WhatsApp via HTTP requests. It can be deployed as a Docker container and supports session management, sending text messages, and QR code scanning for account linking. The project offers Core and Plus versions, with support for various storage backends including local files, MongoDB, PostgreSQL, and S3/MinIO, as well as integrations with Chatwoot and n8n.

Tokens
8.4K
Snippets
22
Records
61
Agent score
92%

What's inside WAHA

  1. Set up WAHA for development

    core

    To develop on WAHA, you need Node.js (>=22) and specific prerequisites for the whatsapp-rust-bridge (Bun and a specific Rust nightly toolchain).

    Prerequisites Installation:

    # Bun runtime
    curl -fsSL https://bun.sh/install | bash -s -- bun-v1.3.9
    
    # Rust nightly toolchain
    curl -fsSL https://sh.rustup.rs | bash -s -- -y --default-toolchain nightly-2026-01-30
    rustup target add wasm32-unknown-unknown
    cargo install wasm-pack --vers 0.14.0 --locked

    Running the project:

    yarn install
    yarn gows:proto
    yarn start
    # Install dependencies
    yarn install
    # Fetch and compile proto files
    yarn gows:proto
    # Run
    yarn start
  2. Install WAHA via Docker

    core

    To use the standard WAHA image, ensure Docker is installed and run the following command to pull the image:

    docker pull devlikeapro/waha

    If you are using WAHA Plus, you must log in with your credentials first:

    docker login -u devlikeapro -p {KEY}
    docker pull devlikeapro/waha-plus
    docker logout
  3. Run the WhatsApp HTTP API

    core

    Start the WAHA container using Docker. The API will be accessible at http://localhost:3000. You can view the Swagger documentation at that address to interact with the API.

    docker run -it --rm -p 3000:3000/tcp --name waha devlikeapro/waha
  4. Deploy WAHA using Docker Compose

    core

    You can deploy WAHA using a docker-compose.yaml file. The configuration supports different versions of WAHA (Core vs Plus) and allows for various storage backends like MongoDB, PostgreSQL, or S3 (via MinIO) for sessions and media files.

    Key Configuration Options:

    • Image Selection: Use devlikeapro/waha-plus for the Plus version or devlikeapro/waha:latest for the Core version.
    • DNS Configuration: If you encounter issues resolving web.whatsapp.com, add dns entries (e.g., 1.1.1.1, 8.8.8.8) to the waha service.
    • Session Storage:
      • For local file storage, map ./sessions:/app/.sessions.
      • If using MongoDB, comment out the local session volume.
    • Media Storage:
      • For local file storage, map ./media:/app/.media.
      • For S3-compatible storage, use a service like MinIO.
    • Environment Variables: Configuration can be managed via an .env file using the env_file directive.
    services:
      waha:
        restart: always
        image: devlikeapro/waha-plus
        dns:
          - 1.1.1.1
          - 8.8.8.8
        ports:
          - '127.0.0.1:3000:3000/tcp'
        volumes:
          - './sessions:/app/.sessions'
          - './media:/app/.media'
        env_file:
          - .env
  5. Manage Chatwoot message pulling via CLI

    core

    The Chatwoot integration provides CLI commands to manage the process of pulling messages from WhatsApp into Chatwoot. You can start a pulling process for specific chats or all chats, check the status of a running job, or remove an existing job.

    Start Message Pulling

    Use MessagesPullStart to initiate the message pulling process. You can target a specific chat or use ChatID.ALL to pull from all available chats.

    Options:

    • chat: The ID of the chat to pull from. Use ChatID.ALL for all chats.
    • options: Configuration for the pull process (e.g., period for time range, ignore for JID filters).
    • jobOptions: Configuration for the background job (e.g., timeout).

    Check Pulling Status

    Use MessagesPullStatus to retrieve the current state of the active message pulling job (e.g., whether it is running, completed, or failed).

  6. Send a text message via API

    core

    Send a text message using the POST /api/sendText endpoint.

    Chat ID Format: Use the international phone number without the + symbol, followed by @c.us (e.g., 12132132131@c.us).

    JSON Payload Example:

    {
      "chatId": "12132132130@c.us",
      "text": "Hi there!",
      "session": "default"
    }

    Using cURL:

    export PHONE=12132132130
    curl -d "{\"chatId\": \"${PHONE}@c.us\", \"text\": \"Hello from WhatsApp HTTP API\" }" -H "Content-Type: application/json" -X POST http://localhost:3000/api/sendText
    # Phone without +
    export PHONE=12132132130
    curl -d "{\"chatId\": \"${PHONE}@c.us\", \"text\": \"Hello from WhatsApp HTTP API\" }" -H "Content-Type: application/json" -X POST http://localhost:3000/api/sendText
  7. Start a new WhatsApp session

    core

    To initialize a WhatsApp session, send a POST request to /api/sessions. The name field in the payload identifies the session. In WAHA Plus, you can use different names to run multiple WhatsApp accounts within a single container.

    Payload Example:

    {
      "name": "default"
    }
  8. Configure WAHA via Docker Compose environment variables

    core

    When running WAHA using Docker Compose, you can configure its behavior using several environment variables. These settings control API security, dashboard access, the WhatsApp engine, and media storage.

    environment:
      - WAHA_API_KEY=321
      - WAHA_DASHBOARD_USERNAME=admin
      - WAHA_DASHBOARD_PASSWORD=admin
      - WHATSAPP_DEFAULT_ENGINE=WEBJS
      - WAHA_PRINT_QR=False
      - WAHA_MEDIA_STORAGE=LOCAL
      - WHATSAPP_FILES_LIFETIME=0
      - WHATSAPP_FILES_FOLDER=/app/.media
  9. Configure MongoDB for WAHA sessions

    core

    To use MongoDB for storing WhatsApp sessions instead of local files, uncomment the mongodb service block in your docker-compose.yaml. Ensure you provide the required root credentials via environment variables.

    Required Environment Variables:

    • MONGO_INITDB_ROOT_USERNAME
    • MONGO_INITDB_ROOT_PASSWORD
    mongodb:
      image: mongo
      container_name: mongodb
      ports:
        - '127.0.0.1:27017:27017/tcp'
      volumes:
        - mongodb_data:/data/db
      environment:
        - MONGO_INITDB_ROOT_USERNAME=mongouser
        - MONGO_INITDB_ROOT_PASSWORD=mongopassword
    
    volumes:
      mongodb_data: {}
  10. Configure Postgres and Redis for Chatwoot

    core

    The Chatwoot stack requires Postgres and Redis services.

    Postgres Configuration:

    • Image: pgvector/pgvector:pg16
    • Environment Variables:
      • POSTGRES_DB: Defaults to chatwoot.
      • POSTGRES_USER: Defaults to postgres.
      • POSTGRES_PASSWORD: Must be provided by the user (defaults to postgres in this file).
    • Volume: Uses chatwoot_pg_data for persistence.

    Redis Configuration:

    • Image: redis:alpine
    • Password: Uses the REDIS_PASSWORD environment variable from .chatwoot.env. If not provided, it defaults to redis.
    • Persistence: Configured with AOF (appendonly yes) and RDB snapshots.
    postgres:
        image: pgvector/pgvector:pg16
        environment:
          - POSTGRES_DB=chatwoot
          - POSTGRES_USER=postgres
          - POSTGRES_PASSWORD=postgres
    
    redis:
        image: redis:alpine
        command:
          - 'sh'
          - '-c'
          - >
            redis-server --bind 0.0.0.0 --port 6379 --requirepass
            ${REDIS_PASSWORD:-redis} --timeout 300 --tcp-keepalive 60 --save 900 1
            --save 300 10 --save 60 10000 --appendonly yes --appendfsync everysec
        env_file: .chatwoot.env