Skip to main content
Generic utilities provide common functionality needed throughout Baileys, including Buffer serialization, timing functions, and message key operations.

BufferJSON

JSON serialization utilities for handling Buffers and Uint8Arrays.

replacer

Converts Buffers to JSON-serializable objects.
any
The key being stringified
any
The value being stringified
any
JSON-serializable representation of the value

reviver

Converts JSON objects back to Buffers.
any
The key (unused)
any
The value being parsed
any
Reconstructed Buffer or original value
Example:
When to use:
  • When storing authentication state to JSON files
  • For serializing keys and cryptographic data
  • With useMultiFileAuthState or custom auth state handlers
  • Any time you need to JSON.stringify/parse objects containing Buffers

getKeyAuthor

Extracts the author/sender JID from a message key.
WAMessageKey | undefined | null
The message key to analyze
string
default:"'me'"
Your JID to use if the message is from you
string
The JID of the message author
Example:
When to use:
  • To identify who sent a message
  • For displaying sender information in UI
  • When processing reactions, poll updates, or event responses
  • Handles group messages with participants correctly

unixTimestampSeconds

Converts a Date to Unix timestamp in seconds.
Date
default:"new Date()"
The date to convert (defaults to current time)
number
Unix timestamp in seconds
Example:
When to use:
  • When creating messages (for messageTimestamp)
  • For comparing message times
  • Any time you need Unix timestamps for WhatsApp protocol

delay

Creates a promise that resolves after a specified time.
number
required
Milliseconds to delay
Promise<void>
Promise that resolves after the delay
Example:
When to use:
  • To add delays between operations
  • For rate limiting message sending
  • In retry logic with backoff
  • To avoid triggering WhatsApp’s anti-spam

generateRegistrationId

Generates a random 14-bit registration ID for Signal protocol.
number
Random 14-bit number (0-16383)
Example:
When to use:
  • Automatically used when creating new authentication credentials
  • You rarely need to call this directly
  • Part of the Signal protocol setup

fetchLatestBaileysVersion

Fetches the latest Baileys version from GitHub.
RequestInit
Fetch options (headers, dispatcher, etc.)
object
Object containing version array, isLatest flag, and optional error
Example:
When to use:
  • To ensure your bot uses the latest WhatsApp Web version
  • Recommended for production bots
  • Call once on startup

fetchLatestWaWebVersion

Fetches the latest WhatsApp Web version directly from WhatsApp servers.
RequestInit
Fetch options
object
Object containing version array, isLatest flag, and optional error
Example:
When to use:
  • Alternative to fetchLatestBaileysVersion
  • Gets version directly from WhatsApp instead of Baileys repo
  • Use if you want the absolute latest WA Web version

toNumber

Converts Long or number types to JavaScript number.
Long | number | null | undefined
Value to convert (from protobuf Long type)
number
JavaScript number (returns 0 for null/undefined)
Example:
When to use:
  • When working with protobuf message fields
  • To convert timestamps from messages
  • Handles Long type from WAProto definitions