WABotJS exports a collection of general-purpose helper functions under theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
Utils namespace, along with shared constants under Constants. These utilities are used internally throughout the SDK and are also available to application code. They cover four areas: converting arbitrary values to common types, asserting the type of function arguments, resolving WhatsApp JID identifiers, and simple async primitives.
Import
Converters
Utils.toString(value)
- If the value is already a
string, it is returned as-is. - If the value is an object (and not
null), it is serialized withJSON.stringify. - All other values (numbers, booleans,
null,undefined, etc.) are converted withString().
Utils.toError(value)
Error instance:
- If
valueis already anError, it is returned unchanged. - Otherwise,
Utils.toString(value)is called on it and the result is wrapped innew Error(...).
catch blocks where the caught value may be any type.
Type Assertions
All assertion functions returntrue (narrowing the TypeScript type of the first argument) when the check passes, or throw a TypeError with a descriptive message when it fails. The error message includes the expected type, the name parameter you provide, and the actual type or constructor name received.
Utils.assertString(param, name)
TypeError if param is not a string.
Utils.assertNumber(param, name)
TypeError if param is not a number or is NaN.
Utils.assertBuffer(param, name)
TypeError if param is not a Node.js Buffer instance.
Utils.assertUint8Array(param, name)
TypeError if param is not a Uint8Array instance. Note that Buffer is a subclass of Uint8Array, so Buffer instances also pass this check.
Utils.assertFunction(param, name)
TypeError if param is not callable.
JID Utilities
WhatsApp uses two parallel JID formats: LID JIDs (@lid) and PN (phone-number) JIDs (@s.whatsapp.net). These helpers scan a variadic argument list and extract or pair the relevant JID strings, normalizing them via Baileys’ jidNormalizedUser.
Utils.resolveLID(...args)
args for the first string that is a LID JID (identified via Baileys’ isLidUser). Returns the normalized LID JID, or undefined if none is found.
Utils.resolvePN(...args)
args for the first string that is a PN JID (identified via Baileys’ isPnUser). Returns the normalized PN JID, or undefined if none is found.
Utils.resolveLIDAndPN(...args)
resolveLID and resolvePN on the same argument list. Returns an object containing both the normalized LID and PN JIDs if both are found in args, or undefined if either is missing.
The normalized LID JID extracted from
args.The normalized PN JID extracted from
args.Async
Utils.delay(ms)
Promise that resolves after ms milliseconds. A thin wrapper around setTimeout that integrates cleanly with async/await. Throws TypeError via assertNumber if ms is not a valid number.
Number of milliseconds to wait. Must be a valid, non-NaN number.
Constants
Constants.USER_AGENT
Constants.MSG_STORE_TTL
Stores.Message store, in milliseconds. Equals five days (1000 × 60 × 60 × 24 × 5 = 432,000,000). Messages cached by the message store are automatically purged after this duration.