Getting Started & Installation
Relevant source files
The following files were used as context for generating this wiki page:
This guide provides a technical overview of setting up and installing the @innovatorssoft/baileys library, a modified WhatsApp API implementation. It covers system requirements, installation procedures, and the architectural flow for establishing an initial connection.
Sources: package.json:2-4
System Requirements
The library requires an environment compatible with modern Node.js standards. It specifies engine requirements that are enforced during the pre-installation phase.
Engine Requirements
| Requirement | Value |
|---|---|
| Node.js Version | >= 20.0.0 |
| Package Manager | yarn@1.22.19 |
Sources: package.json:106-111
Key Dependencies
The project relies on several critical libraries for its core functionality:
- Signal Protocol:
@itsukichan/libsignal-nodefor end-to-end encryption. - Data Handling:
protobufjsfor message serialization and@adiwajshing/keyed-dbfor efficient storage. - Media Processing:
sharpandfluent-ffmpegfor handling images and video. - Utility:
pinofor logging andaxiosfor HTTP requests.
Sources: package.json:44-67
Installation & Build Process
The project uses standard NPM/Yarn scripts for development and deployment.
Build Commands
The build process is managed via the following scripts:
yarn build:tsc: Compiles TypeScript source files into JavaScript located in thelibdirectory.yarn build:docs: Generates technical documentation using TypeDoc.yarn update:version: Executes a script to fetch the latest WhatsApp Web version and update codebase defaults.
Sources: package.json:28-31, scripts/update-version.js:203-207
Initial Setup Flow
The following diagram illustrates the sequence of actions when a developer initiates the build and update process.
The version update mechanism ensures that the connection remains compatible with the latest WhatsApp Web protocols by dynamically fetching the client_revision.
Sources: scripts/update-version.js:28-100, scripts/update-version.js:123-144
Initializing a Connection
To start using the library, a client must be initialized using makeWASocket. This process requires managing authentication state and handling connection updates, such as QR code generation or pairing codes.
Authentication Strategy
The library supports multi-file authentication state to persist credentials across sessions.
const { state, saveCreds } = await useMultiFileAuthState(authDir);
const sock = makeWASocket({
auth: state,
syncFullHistory: false,
logger: require('pino')({ level: 'silent' }),
markOnlineOnConnect: true
});
Sources: assets/examples/example.js:29-41
Connection States
The connection lifecycle is managed through the connection.update event.
Sources: assets/examples/example.js:100-120
Connection Parameters
| Option | Type | Description |
|---|---|---|
auth | AuthenticationState | The credentials and keys used for the session. |
syncFullHistory | boolean | Whether to sync complete chat history on connect. |
logger | Logger | Pino logger instance for debugging. |
markOnlineOnConnect | boolean | Automatically set status to online after connecting. |
Sources: assets/examples/example.js:37-41
Platform Identification
During connection, the library identifies the client platform to WhatsApp servers. This is handled by a platform mapping utility.
Supported Platforms
The system maps internal OS identifiers to WhatsApp-recognized platform names:
win32-> Windows (v10.0.22631)darwin-> Mac OS (v18.5)ubuntu-> Ubuntu (v22.04.4)android-> Android (v14.0.0)
Sources: lib/Utils/generics.js:46-95
Conclusion
Setting up @innovatorssoft/baileys involves ensuring Node.js 20+ is available, running the build scripts to align with the latest WhatsApp Web version, and implementing a multi-file auth state for session persistence. The library's architecture emphasizes automated version alignment and flexible platform spoofing to maintain stable connections.
Sources: package.json:107, scripts/update-version.js:195-200, assets/examples/example.js:115-125