makeWASocket
The primary function to create a WhatsApp Web socket connection.
function makeWASocket(config: UserFacingSocketConfig): WASocket
config
UserFacingSocketConfig
required
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
Event emitter for listening to WhatsApp events. See Events for available events.
Information about the authenticated user.
The underlying WebSocket connection.
Current authentication state including credentials and keys.
Messaging Methods
sendMessage(
jid: string,
content: AnyMessageContent,
options?: MessageRelayOptions
): Promise<proto.WebMessageInfo>
Send a message to a chat.content
AnyMessageContent
required
Message content (text, image, video, document, etc.)
Additional options for message sending (quoted message, etc.)
sendReceipt(
jid: string,
participant: string | undefined,
messageIds: string[],
type: MessageReceiptType
): Promise<void>
Send read/delivery receipts for messages.
sendPresenceUpdate(type: WAPresence, toJid?: string): Promise<void>
Update presence status (typing, recording, online, etc.).Presence type: 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
Target JID for the presence update (optional, defaults to general presence)
readMessages(keys: WAMessageKey[]): Promise<void>
Mark messages as read.
Group Methods
groupCreate(subject: string, participants: string[]): Promise<GroupMetadata>
Create a new group.Array of participant JIDs to add to the group
groupMetadata(jid: string): Promise<GroupMetadata>
Fetch metadata for a group.
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(jid: string, subject: string): Promise<void>
Update group name/subject.
groupUpdateDescription(jid: string, description?: string): Promise<void>
Update group description. Pass undefined to remove description.
groupInviteCode(jid: string): Promise<string | undefined>
Get the group invite code.
groupRevokeInvite(jid: string): Promise<string | undefined>
Revoke and regenerate the group invite code.
groupAcceptInvite(code: string): Promise<string | undefined>
Join a group using an invite code.
groupLeave(id: string): Promise<void>
Leave a group.
groupToggleEphemeral(jid: string, ephemeralExpiration: number): Promise<void>
Enable or disable disappearing messages. Set to 0 to disable.Duration in seconds (0 to disable, or 86400 for 1 day, 604800 for 7 days, 7776000 for 90 days)
groupSettingUpdate(
jid: string,
setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'
): Promise<void>
Update group settings (announcement mode or edit restrictions).
groupFetchAllParticipating
groupFetchAllParticipating(): Promise<{ [jid: string]: GroupMetadata }>
Fetch metadata for all groups the user is participating in.
communityCreate(subject: string, body: string): Promise<GroupMetadata | null>
Create a new community.
communityMetadata(jid: string): Promise<GroupMetadata>
Fetch metadata for a community.
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(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(args: UpdateBussinesProfileProps): Promise<BinaryNode>
Update business profile information.
getCatalog(options: GetCatalogOptions): Promise<{
products: Product[]
nextCursor?: string
}>
Get business catalog products.
productCreate(create: ProductCreate): Promise<Product>
Create a new product in the business catalog.
productUpdate(productId: string, update: ProductUpdate): Promise<Product>
Update an existing product.
productDelete(productIds: string[]): Promise<{ deleted: number }>
Delete products from the catalog.
Profile & Privacy Methods
updateProfilePicture(jid: string, content: WAMediaUpload): Promise<void>
Update profile picture for user or group.
removeProfilePicture(jid: string): Promise<void>
Remove profile picture.
updateProfileStatus(status: string): Promise<void>
Update status/about text.
updateProfileName(name: string): Promise<void>
Update profile display name.
updateBlockStatus(jid: string, action: 'block' | 'unblock'): Promise<void>
Block or unblock a user.
fetchBlocklist(): Promise<string[]>
Get list of blocked users.
fetchPrivacySettings(force?: boolean): Promise<{ [key: string]: string }>
Fetch privacy settings.
updateReadReceiptsPrivacy
updateReadReceiptsPrivacy(value: WAReadReceiptsValue): Promise<void>
Update read receipts privacy setting.
updateOnlinePrivacy(value: WAPrivacyOnlineValue): Promise<void>
Update online/last seen privacy.
updateProfilePicturePrivacy
updateProfilePicturePrivacy(value: WAPrivacyValue): Promise<void>
Update profile picture privacy.
Utility Methods
query(node: BinaryNode, timeoutMs?: number): Promise<BinaryNode>
Send a raw binary node query and await response.
sendNode(node: BinaryNode): Promise<void>
Send a raw binary node without expecting a response.
Logout and invalidate the current session.
end(error?: Error | undefined): void
Close the WebSocket connection.
waitForSocketOpen(): Promise<void>
Wait for the WebSocket to be in OPEN state.
waitForConnectionUpdate(
check: (u: Partial<ConnectionState>) => boolean | undefined,
timeoutMs?: number
): Promise<void>
Wait for a specific connection state update.