WASocket
The main socket interface returned by makeWASocket(). It provides all methods for interacting with WhatsApp.
export type WASocket = ReturnType<typeof makeWASocket>
Core properties
ev
BaileysEventEmitter
required
Event emitter for all WhatsApp events
Underlying WebSocket connection
authState
AuthenticationState
required
Current authentication state and credentials
Your own user information
signalRepository
SignalRepositoryWithLIDStore
required
Signal protocol repository for encryption
Messaging methods
sendMessage
Send a message to a chat.
sendMessage(
jid: string,
content: AnyMessageContent,
options?: MiscMessageGenerationOptions
): Promise<WAMessage>
JID of the recipient (user or group)
content
AnyMessageContent
required
Message content (text, media, etc.)
options
MiscMessageGenerationOptions
Additional options (quoted message, ephemeral, etc.)
Example:
// Send text message
await sock.sendMessage('[email protected]', {
text: 'Hello!'
})
// Send image with caption
await sock.sendMessage('[email protected]', {
image: { url: './photo.jpg' },
caption: 'Check this out!'
})
// Reply to a message
await sock.sendMessage('[email protected]',
{ text: 'Thanks!' },
{ quoted: messageObj }
)
relayMessage
Relay a pre-constructed message.
relayMessage(
jid: string,
message: proto.IMessage,
options: MessageRelayOptions
): Promise<string>
Lower-level method for sending already-constructed messages. Returns the message ID.
sendReceipt
Send a receipt for a message.
sendReceipt(
jid: string,
participant: string | undefined,
messageIds: string[],
type: MessageReceiptType
): Promise<void>
readMessages
Mark messages as read.
readMessages(keys: WAMessageKey[]): Promise<void>
Example:
await sock.readMessages([message.key])
Group management methods
groupCreate
Create a new group.
groupCreate(
subject: string,
participants: string[]
): Promise<GroupMetadata>
Array of participant JIDs
Example:
Get group metadata.
groupMetadata(jid: string): Promise<GroupMetadata>
Example:
const metadata = await sock.groupMetadata('[email protected]')
console.log('Group subject:', metadata.subject)
console.log('Participants:', metadata.participants.length)
groupUpdateSubject
Update group name.
groupUpdateSubject(jid: string, subject: string): Promise<void>
groupUpdateDescription
Update group description.
groupUpdateDescription(
jid: string,
description?: string
): Promise<void>
groupParticipantsUpdate
Add, remove, promote, or demote participants.
groupParticipantsUpdate(
jid: string,
participants: string[],
action: ParticipantAction
): Promise<Array<{ status: string; jid: string }>>
action
ParticipantAction
required
'add', 'remove', 'promote', 'demote'
Example:
groupSettingUpdate
Update group settings.
groupSettingUpdate(
jid: string,
setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked'
): Promise<void>
announcement: Only admins can send messages
locked: Only admins can edit group info
groupLeave
Leave a group.
groupLeave(id: string): Promise<void>
groupInviteCode
Get group invite code.
groupInviteCode(jid: string): Promise<string>
groupRevokeInvite
Revoke and generate new invite code.
groupRevokeInvite(jid: string): Promise<string>
groupAcceptInvite
Join group using invite code.
groupAcceptInvite(code: string): Promise<string>
Returns the group JID.
groupGetInviteInfo
Get group info from invite code (without joining).
groupGetInviteInfo(code: string): Promise<GroupMetadata>
groupToggleEphemeral
Enable/disable disappearing messages.
groupToggleEphemeral(
jid: string,
ephemeralExpiration: number
): Promise<void>
Duration in seconds. 0 to disable.
groupFetchAllParticipating
Fetch all groups you’re in.
groupFetchAllParticipating(): Promise<{ [jid: string]: GroupMetadata }>
groupRequestParticipantsList
Get pending join requests.
groupRequestParticipantsList(jid: string): Promise<any[]>
groupRequestParticipantsUpdate
Approve or reject join requests.
groupRequestParticipantsUpdate(
jid: string,
participants: string[],
action: 'approve' | 'reject'
): Promise<Array<{ status: string; jid: string }>>
groupMemberAddMode
Set who can add members.
groupMemberAddMode(
jid: string,
mode: 'admin_add' | 'all_member_add'
): Promise<void>
groupJoinApprovalMode
Enable/disable join approval.
groupJoinApprovalMode(
jid: string,
mode: 'on' | 'off'
): Promise<void>
Create a community.
communityCreate(
subject: string,
body: string
): Promise<GroupMetadata | null>
Get community metadata.
communityMetadata(jid: string): Promise<GroupMetadata>
Get all groups linked to a community.
communityFetchLinkedGroups(jid: string): Promise<{
communityJid: string
isCommunity: boolean
linkedGroups: Array<{
id?: string
subject: string
creation?: number
owner?: string
size?: number
}>
}>
Link a group to a community.
communityLinkGroup(
groupJid: string,
parentCommunityJid: string
): Promise<void>
Unlink a group from a community.
communityUnlinkGroup(
groupJid: string,
parentCommunityJid: string
): Promise<void>
Join a community using invite code.
communityAcceptInvite(code: string): Promise<string>
Get community invite code.
communityInviteCode(jid: string): Promise<string>
Newsletter methods
newsletterCreate
Create a newsletter channel.
newsletterCreate(
name: string,
description?: string
): Promise<NewsletterMetadata>
Get newsletter metadata.
newsletterMetadata(
type: 'invite' | 'jid',
key: string
): Promise<NewsletterMetadata | null>
newsletterFollow
Follow a newsletter.
newsletterFollow(jid: string): Promise<any>
newsletterUnfollow
Unfollow a newsletter.
newsletterUnfollow(jid: string): Promise<any>
newsletterUpdateName
Update newsletter name.
newsletterUpdateName(jid: string, name: string): Promise<any>
newsletterUpdateDescription
Update newsletter description.
newsletterUpdateDescription(
jid: string,
description: string
): Promise<any>
newsletterUpdatePicture
Update newsletter picture.
newsletterUpdatePicture(
jid: string,
content: WAMediaUpload
): Promise<any>
newsletterReactMessage
React to a newsletter message.
newsletterReactMessage(
jid: string,
serverId: string,
reaction?: string
): Promise<void>
newsletterFetchMessages
Fetch newsletter messages.
newsletterFetchMessages(
jid: string,
count: number,
since: number,
after: number
): Promise<BinaryNode>
Profile methods
updateProfilePicture
Update your profile picture.
updateProfilePicture(
jid: string,
content: WAMediaUpload
): Promise<void>
removeProfilePicture
Remove profile picture.
removeProfilePicture(jid: string): Promise<void>
updateProfileName
Update your profile name.
updateProfileName(name: string): Promise<void>
updateProfileStatus
Update your status/about.
updateProfileStatus(status: string): Promise<void>
profilePictureUrl
Get profile picture URL.
profilePictureUrl(
jid: string,
type?: 'image' | 'preview'
): Promise<string | undefined>
fetchStatus
Get user’s status/about.
fetchStatus(jid: string): Promise<{ status: string; setAt: Date }>
Privacy settings methods
updateLastSeenPrivacy
Set last seen privacy.
updateLastSeenPrivacy(
value: WAPrivacyValue
): Promise<void>
'all', 'contacts', 'contact_blacklist', 'none'
updateOnlinePrivacy
Set online presence privacy.
updateOnlinePrivacy(
value: WAPrivacyOnlineValue
): Promise<void>
updateProfilePicturePrivacy
Set profile picture privacy.
updateProfilePicturePrivacy(
value: WAPrivacyValue
): Promise<void>
updateStatusPrivacy
Set status privacy.
updateStatusPrivacy(
value: WAPrivacyValue
): Promise<void>
updateReadReceiptsPrivacy
Set read receipts privacy.
updateReadReceiptsPrivacy(
value: WAReadReceiptsValue
): Promise<void>
updateGroupsAddPrivacy
Set who can add you to groups.
updateGroupsAddPrivacy(
value: WAPrivacyGroupAddValue
): Promise<void>
'all', 'contacts', 'contact_blacklist'
fetchPrivacySettings
Get current privacy settings.
fetchPrivacySettings(
force?: boolean
): Promise<{ [_: string]: string }>
Business methods
getCatalog
Get business catalog.
getCatalog(options: GetCatalogOptions): Promise<{
products: Product[]
nextCursor?: string
}>
productCreate
Create a catalog product.
productCreate(product: ProductCreate): Promise<Product>
productUpdate
Update a catalog product.
productUpdate(
productId: string,
update: ProductUpdate
): Promise<Product>
productDelete
Delete a catalog product.
productDelete(productIds: string[]): Promise<void>
updateBussinesProfile
Update business profile.
updateBussinesProfile(
args: UpdateBussinesProfileProps
): Promise<BinaryNode>
Utility methods
getPrivacyTokens
Get privacy tokens for JIDs.
getPrivacyTokens(jids: string[]): Promise<BinaryNode>
assertSessions
Ensure Signal sessions exist for JIDs.
assertSessions(
jids: string[],
force?: boolean
): Promise<boolean>
Refresh media connection credentials.
refreshMediaConn(forceGet?: boolean): Promise<MediaConnInfo>
waUploadToServer
Upload media to WhatsApp servers.
waUploadToServer: WAMediaUploadFunction
query
Send a custom IQ query.
query(node: BinaryNode): Promise<BinaryNode>
sendNode
Send a custom binary node.
sendNode(node: BinaryNode): Promise<void>
logout
Logout and delete credentials.
end
Close the connection.
Presence methods
sendPresenceUpdate
Update your presence.
sendPresenceUpdate(
type: WAPresence,
toJid?: string
): Promise<void>
'available', 'unavailable', 'composing', 'recording', 'paused'
Specific chat to update presence in
Example:
// Set online
await sock.sendPresenceUpdate('available')
// Show typing in a chat
await sock.sendPresenceUpdate('composing', '[email protected]')
// Stop typing
await sock.sendPresenceUpdate('paused', '[email protected]')
presenceSubscribe
Subscribe to a user’s presence.
presenceSubscribe(jid: string): Promise<void>
Blocklist methods
updateBlockStatus
Block or unblock a user.
updateBlockStatus(
jid: string,
action: 'block' | 'unblock'
): Promise<void>
fetchBlocklist
Get your blocklist.
fetchBlocklist(): Promise<string[]>
App state sync methods
chatModify
Modify chat state (archive, pin, mute, etc.).
chatModify(
modification: ChatModification,
jid: string
): Promise<void>
Example:
// Archive chat
await sock.chatModify({ archive: true }, '[email protected]')
// Pin chat
await sock.chatModify({ pin: true }, '[email protected]')
// Mute chat for 8 hours
await sock.chatModify(
{ mute: Date.now() + 8 * 60 * 60 * 1000 },
'[email protected]'
)