Skip to main content

makeWASocket

The primary function to create a WhatsApp Web socket connection.
function makeWASocket(config: UserFacingSocketConfig): WASocket
config
UserFacingSocketConfig
required
Configuration object for the socket connection. See Socket Configuration for details.
WASocket
object
Returns a socket instance with all methods and properties for interacting with WhatsApp Web API.

Example

import makeWASocket from '@whiskeysockets/baileys'
import { useMultiFileAuthState } from '@whiskeysockets/baileys'

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

const sock = makeWASocket({
    auth: state
})

sock.ev.on('connection.update', (update) => {
    const { connection, lastDisconnect, qr } = update
    
    if(qr) {
        console.log('QR Code:', qr)
    }
    
    if(connection === 'close') {
        console.log('Connection closed')
    } else if(connection === 'open') {
        console.log('Connection opened')
    }
})

sock.ev.on('creds.update', saveCreds)

WASocket Methods

The WASocket object returned by makeWASocket includes the following categories of methods:

Core Properties

ev
BaileysEventEmitter
Event emitter for listening to WhatsApp events. See Events for available events.
user
Contact | undefined
Information about the authenticated user.
ws
WebSocket
The underlying WebSocket connection.
authState
AuthenticationState
Current authentication state including credentials and keys.

Messaging Methods

sendMessage
function
sendMessage(
  jid: string,
  content: AnyMessageContent,
  options?: MessageRelayOptions
): Promise<proto.WebMessageInfo>
Send a message to a chat.
jid
string
required
The JID (WhatsApp ID) of the recipient (e.g., “[email protected]” for individual, “[email protected]” for group)
content
AnyMessageContent
required
Message content (text, image, video, document, etc.)
options
MessageRelayOptions
Additional options for message sending (quoted message, etc.)
sendReceipt
function
sendReceipt(
  jid: string,
  participant: string | undefined,
  messageIds: string[],
  type: MessageReceiptType
): Promise<void>
Send read/delivery receipts for messages.
sendPresenceUpdate
function
sendPresenceUpdate(type: WAPresence, toJid?: string): Promise<void>
Update presence status (typing, recording, online, etc.).
type
WAPresence
required
Presence type: 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
toJid
string
Target JID for the presence update (optional, defaults to general presence)
readMessages
function
readMessages(keys: WAMessageKey[]): Promise<void>
Mark messages as read.

Group Methods

groupCreate
function
groupCreate(subject: string, participants: string[]): Promise<GroupMetadata>
Create a new group.
subject
string
required
Group name
participants
string[]
required
Array of participant JIDs to add to the group
groupMetadata
function
groupMetadata(jid: string): Promise<GroupMetadata>
Fetch metadata for a group.
groupParticipantsUpdate
function
groupParticipantsUpdate(
  jid: string,
  participants: string[],
  action: ParticipantAction
): Promise<{ status: string; jid: string; content: BinaryNode }[]>
Add, remove, promote, or demote group participants.
action
ParticipantAction
required
Action to perform: 'add' | 'remove' | 'promote' | 'demote'
groupUpdateSubject
function
groupUpdateSubject(jid: string, subject: string): Promise<void>
Update group name/subject.
groupUpdateDescription
function
groupUpdateDescription(jid: string, description?: string): Promise<void>
Update group description. Pass undefined to remove description.
groupInviteCode
function
groupInviteCode(jid: string): Promise<string | undefined>
Get the group invite code.
groupRevokeInvite
function
groupRevokeInvite(jid: string): Promise<string | undefined>
Revoke and regenerate the group invite code.
groupAcceptInvite
function
groupAcceptInvite(code: string): Promise<string | undefined>
Join a group using an invite code.
groupLeave
function
groupLeave(id: string): Promise<void>
Leave a group.
groupToggleEphemeral
function
groupToggleEphemeral(jid: string, ephemeralExpiration: number): Promise<void>
Enable or disable disappearing messages. Set to 0 to disable.
ephemeralExpiration
number
required
Duration in seconds (0 to disable, or 86400 for 1 day, 604800 for 7 days, 7776000 for 90 days)
groupSettingUpdate
function
groupSettingUpdate(
  jid: string,
  setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'
): Promise<void>
Update group settings (announcement mode or edit restrictions).
groupFetchAllParticipating
function
groupFetchAllParticipating(): Promise<{ [jid: string]: GroupMetadata }>
Fetch metadata for all groups the user is participating in.

Community Methods

communityCreate
function
communityCreate(subject: string, body: string): Promise<GroupMetadata | null>
Create a new community.
communityMetadata
function
communityMetadata(jid: string): Promise<GroupMetadata>
Fetch metadata for a community.
communityCreateGroup
function
communityCreateGroup(
  subject: string,
  participants: string[],
  parentCommunityJid: string
): Promise<GroupMetadata | null>
Create a group within a community.
communityLinkGroup(groupJid: string, parentCommunityJid: string): Promise<void>
Link an existing group to a community.
communityUnlinkGroup(groupJid: string, parentCommunityJid: string): Promise<void>
Unlink a group from a community.
communityFetchLinkedGroups
function
communityFetchLinkedGroups(jid: string): Promise<{
  communityJid: string
  isCommunity: boolean
  linkedGroups: Array<{
    id?: string
    subject: string
    creation?: number
    owner?: string
    size?: number
  }>
}>
Fetch all groups linked to a community.

Business Methods

updateBussinesProfile
function
updateBussinesProfile(args: UpdateBussinesProfileProps): Promise<BinaryNode>
Update business profile information.
getCatalog
function
getCatalog(options: GetCatalogOptions): Promise<{
  products: Product[]
  nextCursor?: string
}>
Get business catalog products.
productCreate
function
productCreate(create: ProductCreate): Promise<Product>
Create a new product in the business catalog.
productUpdate
function
productUpdate(productId: string, update: ProductUpdate): Promise<Product>
Update an existing product.
productDelete
function
productDelete(productIds: string[]): Promise<{ deleted: number }>
Delete products from the catalog.

Profile & Privacy Methods

updateProfilePicture
function
updateProfilePicture(jid: string, content: WAMediaUpload): Promise<void>
Update profile picture for user or group.
removeProfilePicture
function
removeProfilePicture(jid: string): Promise<void>
Remove profile picture.
updateProfileStatus
function
updateProfileStatus(status: string): Promise<void>
Update status/about text.
updateProfileName
function
updateProfileName(name: string): Promise<void>
Update profile display name.
updateBlockStatus
function
updateBlockStatus(jid: string, action: 'block' | 'unblock'): Promise<void>
Block or unblock a user.
fetchBlocklist
function
fetchBlocklist(): Promise<string[]>
Get list of blocked users.
fetchPrivacySettings
function
fetchPrivacySettings(force?: boolean): Promise<{ [key: string]: string }>
Fetch privacy settings.
updateReadReceiptsPrivacy
function
updateReadReceiptsPrivacy(value: WAReadReceiptsValue): Promise<void>
Update read receipts privacy setting.
updateOnlinePrivacy
function
updateOnlinePrivacy(value: WAPrivacyOnlineValue): Promise<void>
Update online/last seen privacy.
updateProfilePicturePrivacy
function
updateProfilePicturePrivacy(value: WAPrivacyValue): Promise<void>
Update profile picture privacy.

Utility Methods

query
function
query(node: BinaryNode, timeoutMs?: number): Promise<BinaryNode>
Send a raw binary node query and await response.
sendNode
function
sendNode(node: BinaryNode): Promise<void>
Send a raw binary node without expecting a response.
logout
function
logout(): Promise<void>
Logout and invalidate the current session.
end
function
end(error?: Error | undefined): void
Close the WebSocket connection.
waitForSocketOpen
function
waitForSocketOpen(): Promise<void>
Wait for the WebSocket to be in OPEN state.
waitForConnectionUpdate
function
waitForConnectionUpdate(
  check: (u: Partial<ConnectionState>) => boolean | undefined,
  timeoutMs?: number
): Promise<void>
Wait for a specific connection state update.

Build docs developers (and LLMs) love