> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/whiskeysockets/Baileys/llms.txt
> Use this file to discover all available pages before exploring further.

# SocketConfig

> Complete interface documentation for Baileys socket configuration

## Overview

The `SocketConfig` interface defines all available configuration options for a Baileys WhatsApp Web socket connection. When using `makeWASocket`, you pass a `UserFacingSocketConfig` which is `Partial<SocketConfig>` with a required `auth` property.

## Type Definition

```typescript theme={null}
type UserFacingSocketConfig = Partial<SocketConfig> & { auth: AuthenticationState }
```

## Configuration Properties

### Connection Settings

<ParamField path="waWebSocketUrl" type="string | URL" default="'wss://web.whatsapp.com/ws/chat'">
  The WebSocket URL to connect to WhatsApp Web.

  ```typescript theme={null}
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat'
  ```
</ParamField>

<ParamField path="connectTimeoutMs" type="number" default="20000">
  Fails the connection if the socket times out in this interval (milliseconds).

  ```typescript theme={null}
  connectTimeoutMs: 20_000 // 20 seconds
  ```
</ParamField>

<ParamField path="defaultQueryTimeoutMs" type="number | undefined" default="60000">
  Default timeout for queries in milliseconds. Set to `undefined` for no timeout.

  ```typescript theme={null}
  defaultQueryTimeoutMs: 60_000 // 60 seconds
  ```
</ParamField>

<ParamField path="keepAliveIntervalMs" type="number" default="30000">
  Ping-pong interval for WebSocket connection (milliseconds).

  ```typescript theme={null}
  keepAliveIntervalMs: 30_000 // 30 seconds
  ```
</ParamField>

### Version & Browser

<ParamField path="version" type="WAVersion" default="[2, 3000, 1033846690]">
  WhatsApp Web version to connect with. Type: `[number, number, number]`

  ```typescript theme={null}
  import { fetchLatestBaileysVersion } from '@whiskeysockets/baileys'

  const { version } = await fetchLatestBaileysVersion()
  const sock = makeWASocket({ version, auth: state })
  ```
</ParamField>

<ParamField path="browser" type="WABrowserDescription" default="Browsers.macOS('Chrome')">
  Browser configuration as a tuple `[OS, Browser, Version]`. Use the `Browsers` constant for predefined configurations.

  ```typescript theme={null}
  import { Browsers } from '@whiskeysockets/baileys'

  // Options:
  browser: Browsers.ubuntu('Chrome')
  browser: Browsers.macOS('Safari')
  browser: Browsers.windows('Edge')
  browser: Browsers.baileys('MyApp')
  browser: Browsers.appropriate('Chrome') // Based on your OS
  ```
</ParamField>

### Network & Proxy

<ParamField path="agent" type="Agent">
  HTTPS proxy agent for the WebSocket connection.

  ```typescript theme={null}
  import { Agent } from 'https'
  import { HttpsProxyAgent } from 'https-proxy-agent'

  const agent = new HttpsProxyAgent('http://proxy-server:8080')
  const sock = makeWASocket({ agent, auth: state })
  ```
</ParamField>

<ParamField path="fetchAgent" type="Agent">
  Agent used for fetch requests when uploading/downloading media.

  ```typescript theme={null}
  fetchAgent: new Agent({ keepAlive: true })
  ```
</ParamField>

### Logging

<ParamField path="logger" type="ILogger" default="logger.child({ class: 'baileys' })">
  Logger instance for debugging and logging. Compatible with Pino logger.

  ```typescript theme={null}
  import P from 'pino'

  const logger = P({ level: 'debug' })
  const sock = makeWASocket({ logger, auth: state })
  ```
</ParamField>

### Authentication

<ParamField path="auth" type="AuthenticationState" required>
  Authentication state object to maintain the auth state. Use `useMultiFileAuthState()` to create this.

  ```typescript theme={null}
  import { useMultiFileAuthState } from '@whiskeysockets/baileys'

  const { state, saveCreds } = await useMultiFileAuthState('auth_info')
  const sock = makeWASocket({ auth: state })

  sock.ev.on('creds.update', saveCreds)
  ```
</ParamField>

### Events

<ParamField path="emitOwnEvents" type="boolean" default="true">
  Whether events should be emitted for actions done by this socket connection.

  ```typescript theme={null}
  emitOwnEvents: true // Emit events for messages you send
  ```
</ParamField>

### Media Settings

<ParamField path="customUploadHosts" type="MediaConnInfo['hosts']" default="[]">
  Custom upload hosts to upload media to.

  ```typescript theme={null}
  customUploadHosts: []
  ```
</ParamField>

<ParamField path="linkPreviewImageThumbnailWidth" type="number" default="192">
  Width for link preview images in pixels.

  ```typescript theme={null}
  linkPreviewImageThumbnailWidth: 192
  ```
</ParamField>

<ParamField path="generateHighQualityLinkPreview" type="boolean" default="false">
  Generate high quality link preview by uploading the jpegThumbnail to WhatsApp.

  ```typescript theme={null}
  generateHighQualityLinkPreview: true
  ```
</ParamField>

### Retry & Error Handling

<ParamField path="retryRequestDelayMs" type="number" default="250">
  Time to wait between sending new retry requests (milliseconds).

  ```typescript theme={null}
  retryRequestDelayMs: 250
  ```
</ParamField>

<ParamField path="maxMsgRetryCount" type="number" default="5">
  Maximum retry count for failed messages.

  ```typescript theme={null}
  maxMsgRetryCount: 5
  ```
</ParamField>

<ParamField path="enableAutoSessionRecreation" type="boolean" default="true">
  Enable automatic session recreation for failed messages.

  ```typescript theme={null}
  enableAutoSessionRecreation: true
  ```
</ParamField>

<ParamField path="enableRecentMessageCache" type="boolean" default="true">
  Enable recent message caching for retry handling.

  ```typescript theme={null}
  enableRecentMessageCache: true
  ```
</ParamField>

### QR Code & Pairing

<ParamField path="qrTimeout" type="number">
  Time to wait for the generation of the next QR code in milliseconds.

  ```typescript theme={null}
  qrTimeout: 60_000 // 60 seconds
  ```
</ParamField>

<ParamField path="printQRInTerminal" type="boolean" deprecated>
  This feature has been removed. Should the QR code be printed in the terminal.
</ParamField>

### History Sync

<ParamField path="syncFullHistory" type="boolean" default="true">
  Whether Baileys should ask the phone for full history (will be received async).

  ```typescript theme={null}
  syncFullHistory: true
  ```
</ParamField>

<ParamField path="shouldSyncHistoryMessage" type="(msg: proto.Message.IHistorySyncNotification) => boolean">
  Function to manage history processing. By default, syncs everything except FULL sync type.

  ```typescript theme={null}
  shouldSyncHistoryMessage: ({ syncType }) => {
    return syncType !== proto.HistorySync.HistorySyncType.FULL
  }
  ```
</ParamField>

### Initialization

<ParamField path="fireInitQueries" type="boolean" default="true">
  Whether Baileys should fire init queries automatically.

  ```typescript theme={null}
  fireInitQueries: true
  ```
</ParamField>

<ParamField path="markOnlineOnConnect" type="boolean" default="true">
  Marks the client as online whenever the socket successfully connects. Set to `false` to receive notifications in WhatsApp app.

  ```typescript theme={null}
  markOnlineOnConnect: false // To receive notifications on phone
  ```
</ParamField>

### Country Code

<ParamField path="countryCode" type="string" default="'US'">
  Alphanumeric country code (e.g., USA -> US) for the number used.

  ```typescript theme={null}
  countryCode: 'US'
  ```
</ParamField>

### Caching

<ParamField path="mediaCache" type="CacheStore">
  Cache to store media, so it doesn't have to be re-uploaded.

  ```typescript theme={null}
  import NodeCache from '@cacheable/node-cache'

  const mediaCache = new NodeCache()
  const sock = makeWASocket({ mediaCache, auth: state })
  ```
</ParamField>

<ParamField path="msgRetryCounterCache" type="CacheStore">
  Map to store retry counts for failed messages; used to determine whether to retry a message.

  ```typescript theme={null}
  import NodeCache from '@cacheable/node-cache'

  const msgRetryCounterCache = new NodeCache()
  const sock = makeWASocket({ msgRetryCounterCache, auth: state })
  ```
</ParamField>

<ParamField path="userDevicesCache" type="PossiblyExtendedCacheStore">
  Cache to store a user's device list.

  ```typescript theme={null}
  const userDevicesCache = new NodeCache()
  const sock = makeWASocket({ userDevicesCache, auth: state })
  ```
</ParamField>

<ParamField path="callOfferCache" type="CacheStore">
  Cache to store call offers.

  ```typescript theme={null}
  const callOfferCache = new NodeCache()
  const sock = makeWASocket({ callOfferCache, auth: state })
  ```
</ParamField>

<ParamField path="placeholderResendCache" type="CacheStore">
  Cache to track placeholder resends.

  ```typescript theme={null}
  const placeholderResendCache = new NodeCache()
  const sock = makeWASocket({ placeholderResendCache, auth: state })
  ```
</ParamField>

### Message Handling

<ParamField path="shouldIgnoreJid" type="(jid: string) => boolean | undefined" default="() => false">
  Function that returns if a JID should be ignored. No event for that JID will be triggered and messages from that JID will not be decrypted.

  ```typescript theme={null}
  import { isJidBroadcast } from '@whiskeysockets/baileys'

  shouldIgnoreJid: (jid) => isJidBroadcast(jid) // Ignore broadcasts
  ```
</ParamField>

<ParamField path="patchMessageBeforeSending" type="Function" default="msg => msg">
  Optionally patch the message before sending out.

  ```typescript theme={null}
  patchMessageBeforeSending: (msg, recipientJids) => {
    // Modify message before sending
    return msg
  }
  ```

  Full signature:

  ```typescript theme={null}
  (msg: proto.IMessage, recipientJids?: string[]) => 
    Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> |
    PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID
  ```
</ParamField>

<ParamField path="getMessage" type="(key: WAMessageKey) => Promise<proto.IMessage | undefined>" default="async () => undefined">
  Fetch a message from your store. Implement this so that messages that failed to send can be retried. This solves the "this message can take a while" issue.

  ```typescript theme={null}
  getMessage: async (key) => {
    // Retrieve message from your database/store
    const msg = await db.messages.findOne({ id: key.id })
    return msg?.message
  }
  ```
</ParamField>

### Group Metadata

<ParamField path="cachedGroupMetadata" type="(jid: string) => Promise<GroupMetadata | undefined>" default="async () => undefined">
  Cached group metadata function to prevent redundant requests to WhatsApp and speed up message sending. Highly recommended for group usage.

  ```typescript theme={null}
  import NodeCache from '@cacheable/node-cache'

  const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })

  const sock = makeWASocket({
    cachedGroupMetadata: async (jid) => groupCache.get(jid),
    auth: state
  })

  sock.ev.on('groups.update', async ([event]) => {
    const metadata = await sock.groupMetadata(event.id)
    groupCache.set(event.id, metadata)
  })
  ```
</ParamField>

### Security & Verification

<ParamField path="appStateMacVerification" type="object" default="{ patch: false, snapshot: false }">
  Verify app state MACs for enhanced security.

  ```typescript theme={null}
  appStateMacVerification: {
    patch: false,
    snapshot: false
  }
  ```
</ParamField>

### Signal Repository

<ParamField path="transactionOpts" type="TransactionCapabilityOptions" default="{ maxCommitRetries: 10, delayBetweenTriesMs: 3000 }">
  Transaction capability options for SignalKeyStore.

  ```typescript theme={null}
  transactionOpts: {
    maxCommitRetries: 10,
    delayBetweenTriesMs: 3000
  }
  ```
</ParamField>

<ParamField path="makeSignalRepository" type="Function" default="makeLibSignalRepository">
  Function to create signal repository.

  ```typescript theme={null}
  import { makeLibSignalRepository } from '@whiskeysockets/baileys'

  makeSignalRepository: makeLibSignalRepository
  ```

  Full signature:

  ```typescript theme={null}
  (auth: SignalAuthState, logger: ILogger, 
   pnToLIDFunc?: (jids: string[]) => Promise<LIDMapping[] | undefined>) => 
    SignalRepositoryWithLIDStore
  ```
</ParamField>

### HTTP Options

<ParamField path="options" type="RequestInit" default="{}">
  Options for HTTP fetch requests.

  ```typescript theme={null}
  options: {
    headers: {
      'User-Agent': 'MyCustomAgent/1.0'
    }
  }
  ```
</ParamField>

### Deprecated Options

<ParamField path="mobile" type="boolean" deprecated>
  This feature has been removed. Should Baileys use the mobile API instead of the multi-device API.
</ParamField>

## CacheStore Interface

```typescript theme={null}
type CacheStore = {
  /** Get a cached key and change the stats */
  get<T>(key: string): Promise<T> | T | undefined
  /** Set a key in the cache */
  set<T>(key: string, value: T): Promise<void> | void | number | boolean
  /** Delete a key from the cache */
  del(key: string): void | Promise<void> | number | boolean
  /** Flush all data */
  flushAll(): void | Promise<void>
}
```

## PossiblyExtendedCacheStore Interface

```typescript theme={null}
type PossiblyExtendedCacheStore = CacheStore & {
  mget?: <T>(keys: string[]) => Promise<Record<string, T | undefined>>
  mset?: <T>(entries: { key: string; value: T }[]) => Promise<void> | void | number | boolean
  mdel?: (keys: string[]) => void | Promise<void> | number | boolean
}
```

## Complete Example

```typescript theme={null}
import makeWASocket, {
  useMultiFileAuthState,
  makeCacheableSignalKeyStore,
  fetchLatestBaileysVersion,
  Browsers
} from '@whiskeysockets/baileys'
import NodeCache from '@cacheable/node-cache'
import P from 'pino'

const logger = P({ level: 'info' })
const msgRetryCounterCache = new NodeCache()
const groupCache = new NodeCache({ stdTTL: 5 * 60, useClones: false })

const { state, saveCreds } = await useMultiFileAuthState('auth_info')
const { version } = await fetchLatestBaileysVersion()

const sock = makeWASocket({
  // Connection
  version,
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
  connectTimeoutMs: 20_000,
  defaultQueryTimeoutMs: 60_000,
  keepAliveIntervalMs: 30_000,
  
  // Browser & Version
  browser: Browsers.ubuntu('MyApp'),
  
  // Auth
  auth: {
    creds: state.creds,
    keys: makeCacheableSignalKeyStore(state.keys, logger),
  },
  
  // Logging
  logger,
  
  // Events
  emitOwnEvents: true,
  
  // Retry
  retryRequestDelayMs: 250,
  maxMsgRetryCount: 5,
  msgRetryCounterCache,
  enableAutoSessionRecreation: true,
  enableRecentMessageCache: true,
  
  // History
  syncFullHistory: true,
  shouldSyncHistoryMessage: ({ syncType }) => {
    return syncType !== proto.HistorySync.HistorySyncType.FULL
  },
  
  // Media
  generateHighQualityLinkPreview: true,
  linkPreviewImageThumbnailWidth: 192,
  
  // Behavior
  markOnlineOnConnect: true,
  fireInitQueries: true,
  
  // Group metadata caching
  cachedGroupMetadata: async (jid) => groupCache.get(jid),
  
  // Message retrieval
  getMessage: async (key) => {
    // Implement message store retrieval
    return undefined
  },
  
  // Country
  countryCode: 'US',
})

// Save credentials on update
sock.ev.on('creds.update', saveCreds)

// Cache group metadata
sock.ev.on('groups.update', async ([event]) => {
  const metadata = await sock.groupMetadata(event.id)
  groupCache.set(event.id, metadata)
})
```

## See Also

* [makeWASocket](/api/makewasocket) - Main socket creation function
* [Browsers](/api/browsers) - Browser configuration options
* [DEFAULT\_CONNECTION\_CONFIG](https://github.com/WhiskeySockets/Baileys/blob/master/src/Defaults/index.ts) - Default configuration values
