API Reference

Socket Configuration

makeWASocket(config)

Creates a WhatsApp socket instance with the given configuration.

Parameters

Property Type Default Description
auth AuthenticationState - Authentication state object for session persistence
logger Logger pino() Pino logger instance
printQRInTerminal boolean false Print QR code to terminal
browser [string, string, string] ['Chrome', 'Windows', ''] Browser description
version [number, number, number] [2, 3000, 1027934701] WhatsApp Web version
connectTimeoutMs number 60000 Connection timeout in milliseconds
keepAliveIntervalMs number 30000 Keep-alive ping interval
markOnlineOnConnect boolean true Mark client as online on connect
syncFullHistory boolean false Sync full message history
getMessage Function - Callback to fetch message for retry

Connection Methods

sock.requestPairingCode(phoneNumber)

Request a pairing code for authentication.

Parameters

Parameter Type Description
phoneNumber string Phone number with country code (e.g., '6281234567890')

Returns

Promise<string> - 8-character pairing code

sock.logout()

Logout from WhatsApp and clear session.

Returns

Promise<void>

sock.end(error?)

End the socket connection.

Parameters

Parameter Type Description
error Error Optional error object

sock.onWhatsApp(...jids)

Check if phone numbers are registered on WhatsApp.

Returns

Promise<Array<{exists: boolean, jid: string}>>

Messages

sock.sendMessage(jid, content, options?)

Send a message to a chat.

Parameters

Parameter Type Description
jid string Recipient JID (user@s.whatsapp.net or group@g.us)
content AnyMessageContent Message content object
options MiscMessageGenerationOptions Optional message options

Content Types

// Text
await sock.sendMessage(jid, { text: 'Hello!' });

// Image
await sock.sendMessage(jid, { 
    image: { url: './image.jpg' },
    caption: 'Image caption'
});

// Video
await sock.sendMessage(jid, { 
    video: { url: './video.mp4' },
    caption: 'Video caption'
});

// Audio
await sock.sendMessage(jid, { 
    audio: { url: './audio.mp3' },
    mimetype: 'audio/mp4'
});

// Document
await sock.sendMessage(jid, { 
    document: { url: './file.pdf' },
    mimetype: 'application/pdf',
    fileName: 'document.pdf'
});

// Sticker
await sock.sendMessage(jid, { 
    sticker: fs.readFileSync('./sticker.webp')
});

// Location
await sock.sendMessage(jid, { 
    location: { 
        degreesLatitude: -6.200000,
        degreesLongitude: 106.816666,
        name: 'Jakarta'
    }
});

// Contact
await sock.sendMessage(jid, { 
    contacts: { 
        displayName: 'Contact',
        contacts: [{ vcard: 'BEGIN:VCARD...' }]
    }
});

// Reaction
await sock.sendMessage(jid, { 
    react: { 
        key: message.key,
        text: '👍'
    }
});

// Reply
await sock.sendMessage(jid, { 
    text: 'Reply message'
}, { quoted: message });

sock.readMessages(keys)

Mark messages as read.

Parameters

Parameter Type Description
keys IMessageKey[] Array of message keys to mark as read

sock.sendPresenceUpdate(type, toJid?)

Send presence update (typing, recording, etc.).

Parameters

Parameter Type Description
type WAPresence 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
toJid string Optional target JID

Groups

sock.groupMetadata(jid)

Get group metadata.

Returns

Promise<GroupMetadata>

sock.groupCreate(subject, participants)

Create a new group.

Parameters

Parameter Type Description
subject string Group name
participants string[] Array of participant JIDs

Returns

Promise<GroupMetadata>

sock.groupParticipantsUpdate(jid, participants, action)

Update group participants.

Parameters

Parameter Type Description
jid string Group JID
participants string[] Array of participant JIDs
action string 'add' | 'remove' | 'promote' | 'demote'

sock.groupUpdateSubject(jid, subject)

Update group subject/name.

sock.groupUpdateDescription(jid, description)

Update group description.

sock.groupInviteCode(jid)

Get group invite code.

Returns

Promise<string>

sock.groupRevokeInvite(jid)

Revoke group invite code and generate new one.

sock.groupAcceptInvite(code)

Join a group via invite code.

Returns

Promise<string> - Group JID

sock.groupLeave(jid)

Leave a group.

sock.groupSettingUpdate(jid, setting)

Update group settings.

Parameters

Parameter Type Description
setting string 'announcement' | 'not_announcement' | 'locked' | 'unlocked'

Newsletter

sock.newsletterCreate(name, description, reaction_codes)

Create a new newsletter.

Returns

Promise<NewsletterMetadata>

sock.newsletterMetadata(type, key, role?)

Get newsletter metadata.

Parameters

Parameter Type Description
type string 'invite' | 'jid'
key string Invite code or JID

sock.newsletterFollow(jid)

Follow a newsletter.

sock.newsletterUnfollow(jid)

Unfollow a newsletter.

sock.newsletterUpdateName(jid, name)

Update newsletter name.

sock.newsletterUpdateDescription(jid, description)

Update newsletter description.

sock.newsletterUpdatePicture(jid, content)

Update newsletter picture.

sock.newsletterRemovePicture(jid)

Remove newsletter picture.

sock.newsletterReactMessage(jid, serverId, code?)

React to a newsletter message.

sock.newsletterFetchMessages(type, key, count, after?)

Fetch newsletter messages.

sock.newsletterDelete(jid)

Delete a newsletter.

Profile

sock.updateProfileName(name)

Update profile name.

sock.updateProfileStatus(status)

Update profile about/status.

sock.updateProfilePicture(jid, content)

Update profile picture.

sock.removeProfilePicture(jid)

Remove profile picture.

sock.profilePictureUrl(jid, type?, timeoutMs?)

Get profile picture URL.

Returns

Promise<string>

sock.fetchStatus(jid)

Get user's about/status.

sock.updateBlockStatus(jid, action)

Block or unblock a contact.

Parameters

Parameter Type Description
action string 'block' | 'unblock'

sock.fetchBlocklist()

Get list of blocked contacts.

Returns

Promise<string[]>

Chat Management

sock.chatModify(modification, jid)

Modify chat (archive, pin, mute, etc.).

// Archive chat
await sock.chatModify({ archive: true }, jid);

// Pin chat
await sock.chatModify({ pin: true }, jid);

// Mute chat (8 hours)
await sock.chatModify({ mute: 8 * 60 * 60 }, jid);

// Unmute chat
await sock.chatModify({ mute: null }, jid);

// Clear messages
await sock.chatModify({ clear: true }, jid);

// Delete chat
await sock.chatModify({ delete: true }, jid);

sock.star(jid, messages, star)

Star or unstar messages.

Media

downloadMediaMessage(message, type, options)

Download media from a message.

const { downloadMediaMessage } = require('socketon');

const buffer = await downloadMediaMessage(message, 'buffer', {});
fs.writeFileSync('./download.jpg', buffer);

Events

All events are listened via sock.ev.on(event, callback)

connection.update

Fired when connection state changes.

sock.ev.on('connection.update', (update) => {
    const { connection, lastDisconnect, qr, pairingCode } = update;
    
    if (qr) {
        // Show QR code
    }
    
    if (pairingCode) {
        // Show pairing code
    }
    
    if (connection === 'close') {
        // Handle disconnect
    } else if (connection === 'open') {
        // Connected
    }
});

messages.upsert

Fired when messages are received or sent.

sock.ev.on('messages.upsert', ({ messages, type }) => {
    // type: 'notify' (new message) | 'append' | 'prepend'
    console.log('New message:', messages[0]);
});

presence.update

Fired when contact presence changes.

sock.ev.on('presence.update', ({ id, presences }) => {
    // id: chat JID
    // presences: { participantJid: { lastKnownPresence, lastSeen } }
});

creds.update

Fired when credentials are updated (save your auth state).

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

Types

DisconnectReason

Reason Code Description
connectionClosed 428 Connection closed
connectionLost 408 Connection lost
connectionReplaced 440 Logged in from another device
loggedOut 401 Session logged out
restartRequired 515 Restart required
timedOut 408 Connection timed out