whatsapp-web-api Documentation

repository·master·Indexed 23 days ago

https://github.com/chrishubert/whatsapp-api

A REST API wrapper for whatsapp-web.js built on Express. It provides programmatic access to WhatsApp functionality, including session management, attachment handling, and webhook support. The API can be configured via environment variables and deployed using Docker.

Tokens
891
Snippets
2
Records
9
Agent score
79%

What's inside whatsapp-web-api

  1. Initialize the WhatsApp API Express application

    master

    The WhatsApp API is built on an Express application instance. When importing the module, the application is pre-configured with body-parser middleware to handle JSON and URL-encoded payloads. The payload size limit is dynamically set based on the maxAttachmentSize configuration plus a 1MB buffer to accommodate metadata. The application also automatically calls restoreSessions() upon initialization to recover previous WhatsApp sessions.

    To use the application, require the module in your entry point. The exported object is a standard Express app instance.

  2. Start the WhatsApp API server

    master
    The application is started by running server.js. The server requires the BASE_WEBHOOK_URL environment variable to be configured; if this variable is missing, the process will terminate with exit code 1. The server listens on the port specified by the PORT environment variable, defaulting to 3000 if not provided.
  3. Configure WhatsApp Web API via Docker Environment Variables

    master

    The whatsapp-web-api service can be configured using environment variables in a docker-compose.yml file. These variables control security, rate limiting, webhook behavior, and WhatsApp Web versioning.

    services:
      app:
        image: chrishubert/whatsapp-web-api:latest
        ports:
          - "3000:3000"
        environment:
          - API_KEY=your_global_api_key_here
          - BASE_WEBHOOK_URL=http://localhost:3000/localCallbackExample
          - ENABLE_LOCAL_CALLBACK_EXAMPLE=TRUE
          - MAX_ATTACHMENT_SIZE=5000000
          - SET_MESSAGES_AS_SEEN=TRUE
          - DISABLED_CALLBACKS=message_ack|message_reaction
          - ENABLE_SWAGGER_ENDPOINT=TRUE
        volumes:
          - ./sessions:/usr/src/app/sessions
  4. Configure the WhatsApp API via environment variables

    master
    The WhatsApp API is configured using environment variables. You can define these in a .env file or set them in your system environment. The following variables control session management, security, webhooks, and API behavior.
  5. Reference: Available WhatsApp Callbacks

    master

    The following callback types are supported by the API. You can use DISABLED_CALLBACKS to prevent specific ones from being sent to your webhook.

    auth_failure|authenticated|call|change_state|disconnected|group_join|group_leave|group_update|loading_screen|media_uploaded|message|message_ack|message_create|message_reaction|message_revoke_everyone|qr|ready|contact_changed
  6. Required environment variables for the server

    master

    The server relies on the following environment variables for correct operation:

    • BASE_WEBHOOK_URL: Required. The base URL used for webhooks. If this is not set, the application will exit with an error.
    • PORT: Optional. The port on which the HTTP server will listen. Defaults to 3000.