Overview
ThemakeWASocket function accepts a comprehensive configuration object that controls every aspect of your WhatsApp connection. This guide covers all available options from the SocketConfig type.
All configuration options are optional and have sensible defaults from
DEFAULT_CONNECTION_CONFIG.Basic Configuration
Connection Options
waWebSocketUrl
The WebSocket URL to connect to WhatsApp servers.'wss://web.whatsapp.com/ws/chat'
connectTimeoutMs
Timeout for establishing the WebSocket connection.20000 (20 seconds)Type:
number (milliseconds)
keepAliveIntervalMs
Interval for ping-pong messages to keep the WebSocket alive.30000 (30 seconds)Type:
number (milliseconds)
defaultQueryTimeoutMs
Default timeout for query requests to WhatsApp.60000 (60 seconds)Type:
number | undefined
Set to
undefined for no timeout, but this is not recommended.Authentication Options
auth
Required. Authentication state containing credentials and keys.AuthenticationState
printQRInTerminal
Automatically print QR code to terminal (deprecated in favor of manual handling).Type:
boolean
qrTimeout
Time to wait for QR code generation.Type:
number (milliseconds)
Browser Configuration
browser
Browser identity shown in WhatsApp’s “Linked Devices”.Browsers.macOS('Chrome')Type:
[platform: string, appName: string, version: string]
Available presets:
Browsers.ubuntu(appName)- Ubuntu 22.04.4Browsers.macOS(appName)- Mac OS 14.4.1Browsers.windows(appName)- Windows 10.0.22631Browsers.baileys(appName)- Baileys 6.5.0Browsers.appropriate(appName)- Auto-detect from OS
version
WhatsApp Web version to use.[2, 3000, 1033846690]Type:
[major: number, minor: number, patch: number]
Message & Media Options
getMessage
Fetch messages from your store for retry handling and poll decryption.async () => undefinedType:
(key: WAMessageKey) => Promise<proto.IMessage | undefined>
customUploadHosts
Custom media upload servers.[]Type:
MediaConnInfo['hosts']
generateHighQualityLinkPreview
Generate high-quality link previews by uploading thumbnails.falseType:
boolean
linkPreviewImageThumbnailWidth
Width for link preview thumbnails.192Type:
number (pixels)
History & Sync Options
syncFullHistory
Request full chat history from WhatsApp.trueType:
boolean
Desktop browsers receive more history than mobile browsers when this is enabled.
shouldSyncHistoryMessage
Control which history messages to process.Type:
(msg: proto.Message.IHistorySyncNotification) => boolean
fireInitQueries
Automatically fire initialization queries on connection.trueType:
boolean
Behavior Options
markOnlineOnConnect
Automatically mark as online when socket connects.trueType:
boolean
Set to
false if you want to receive push notifications on your phone.emitOwnEvents
Emit events for actions performed by this socket.trueType:
boolean
shouldIgnoreJid
Ignore events from specific JIDs.() => falseType:
(jid: string) => boolean | undefined
patchMessageBeforeSending
Modify messages before sending.msg => msg (no modification)Type: Function that returns patched message(s)
Retry & Cache Options
retryRequestDelayMs
Delay between retry attempts for failed messages.250 (milliseconds)Type:
number
maxMsgRetryCount
Maximum number of retry attempts.5Type:
number
msgRetryCounterCache
Cache for tracking message retry counts.Type:
CacheStore
Keep this cache outside the socket to prevent retry loops across reconnections.
mediaCache
Cache for media uploads to avoid re-uploading.Type:
CacheStore
userDevicesCache
Cache for user device lists.Type:
PossiblyExtendedCacheStore
callOfferCache
Cache for call offers.Type:
CacheStore
placeholderResendCache
Cache for tracking placeholder resend requests.Type:
CacheStore
Performance Options
cachedGroupMetadata
Cache group metadata to reduce API calls.async () => undefinedType:
(jid: string) => Promise<GroupMetadata | undefined>
Highly recommended for bots that interact with groups to reduce API load.
enableAutoSessionRecreation
Automatically recreate sessions for failed messages.trueType:
boolean
enableRecentMessageCache
Cache recent messages for retry handling.trueType:
boolean
Network Options
agent
Proxy agent for WebSocket connection.Type:
Agent
fetchAgent
Agent for HTTP fetch requests (media upload/download).Type:
Agent
options
Options for HTTP fetch requests.{}Type:
RequestInit
Advanced Options
countryCode
Alphanumeric country code for the phone number.'US'Type:
string
logger
Logger instance for debugging.Type:
ILogger
transactionOpts
Transaction options for Signal key store operations.{ maxCommitRetries: 10, delayBetweenTriesMs: 3000 }Type:
TransactionCapabilityOptions
appStateMacVerification
Verify app state MACs for security.{ patch: false, snapshot: false }Type:
{ patch: boolean; snapshot: boolean }
makeSignalRepository
Custom Signal protocol repository factory.makeLibSignalRepositoryType: Function
Complete Configuration Example
Configuration Best Practices
1
Implement getMessage
Always implement
getMessage for message retry and poll decryption support.2
Use Latest Version
Fetch and use the latest WhatsApp Web version with
fetchLatestBaileysVersion().3
Cache Group Metadata
Implement
cachedGroupMetadata if your bot works with groups to reduce API calls.4
External Retry Cache
Keep
msgRetryCounterCache outside the socket to prevent retry loops on reconnection.5
Adjust for Environment
Set
markOnlineOnConnect: false if users should receive phone notifications.6
Enable High Quality Previews
Set
generateHighQualityLinkPreview: true for better link preview images.Next Steps
Session Management
Implement getMessage and auth state
Handling Events
Use socket to handle events
Sending Messages
Send messages with your configured socket