WPPConnect Server Documentation

repository·main·Indexed 21 days ago

https://github.com/wppconnect-team/wppconnect-server

A Node.js (Express, Socket.io) and Puppeteer-based RESTful API for WhatsApp automation. It supports multi-client dynamic authentication, sending/receiving messages, managing contacts, groups, and communities. Features include product catalog management, profile settings updates, and a Swagger UI for interactive API documentation. Version 2.10.1.

Tokens
14.6K
Snippets
74
Records
96
Agent score
76%

What's inside WPPConnect Server

  1. Install WPPConnect Server

    main

    To install the WPPConnect Server, use npm or yarn to install the dependencies.

    Puppeteer Dependencies

    Since the server uses Puppeteer, you must install the required system dependencies for Linux environments:

    sudo apt-get install -y libxshmfence-dev libgbm-dev wget unzip fontconfig locales gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils libvips-dev

    Google Chrome Installation

    Install Google Chrome to ensure the browser environment is correctly set up:

    wget -c https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    sudo apt-get update
    sudo apt-get install libappindicator1
    sudo dpkg -i google-chrome-stable_current_amd64.deb
    yarn install
    #or
    npm install
  2. Configure WPPConnect Server via config.ts

    main

    The server is configured using a config.ts file. Key configuration sections include:

    • secretKey: The key used to generate access tokens. Change this from the default value immediately.
    • host & port: The server network settings.
    • webhook: Configuration for outgoing webhooks, including url, autoDownload (for files), and event triggers like onPresenceChanged or onReactionMessage.
    • db: Settings for MongoDB (token storage) and Redis.
    • aws_s3: Credentials and bucket settings for uploading media to AWS S3.
    • createOptions: Browser arguments passed to Puppeteer (e.g., --no-sandbox).
    • log: Logging level (e.g., silly, info) and targets (console, file).
    {
      secretKey: 'YOUR_SECURE_TOKEN',
      host: 'http://localhost',
      port: '21465',
      deviceName: 'WppConnect',
      // ... other options
    }
  3. Deploy WPPConnect Server using Docker Compose

    main

    You can deploy the WPPConnect Server using Docker Compose. The configuration defines a service named wppconnect that builds from the local context and exposes the server on port 21465.

    To ensure persistence and custom configuration, the following volumes are mapped:

    • ./config.ts: Mapped to /usr/src/wpp-server/config.ts inside the container to provide custom server settings.
    • ./wppconnect_tokens: Mapped to /usr/src/wpp-server/tokens to persist WhatsApp session tokens.

    Note: The wppconnect_tokens volume is managed by Docker to ensure session data survives container restarts.

    version: "3"
    
    services:
      wppconnect:
        container_name: wpp-server
        restart: unless-stopped
        build:
          context: .
        volumes:
          - ./config.ts:/usr/src/wpp-server/config.ts
          - ./wppconnect_tokens:/usr/src/wpp-server/tokens
        ports:
          - "21465:21465"
    
    volumes:
      wppconnect_tokens: {}
  4. Start the WPPConnect Server

    main

    The WPPConnect Server is initialized by calling the initServer function and passing a configuration object. In the default entry point, this is handled by importing the pre-defined config and passing it to initServer.

    import config from './config';
    import { initServer } from './index';
    
    initServer(config);
  5. Troubleshoot Sharp Runtime Errors

    main

    If you encounter errors related to the sharp runtime during installation, try reinstalling it with the following commands:

    yarn add sharp
    #or
    npm install --include=optional sharp
    #or
    yarn add sharp --ignore-engines
    yarn add sharp
    #or
    npm install --include=optional sharp
  6. Send a Text Message

    main

    Send a message to a specific phone number using the send-message endpoint. The payload requires a phone number and the message string.

    curl -X POST --location http://localhost:21465/api/mySession/send-message \
        -H "Content-Type: application/json; charset=utf-8" \
        -H "Accept: application/json" \
        -H "Authorization: Bearer YOUR_FULL_TOKEN" \
        -d '{
              "phone": "5511900000000",
              "message": "*Abner* Rodrigues"
            }'
  7. Start a Session and Get QR Code

    main

    To begin using a WhatsApp session, call the start-session endpoint. If the session is not yet authenticated, calling this endpoint will return the base64 encoded QR code required to scan with WhatsApp.

    curl -X POST --location http://localhost:21465/api/mySession/start-session \
        -H "Accept: application/json" \
        -H "Content-Type: application/json" \
        -H "Authorization: Bearer YOUR_FULL_TOKEN"