Skip to main content

Send presence update

Update your presence status or send typing indicators.
// Mark yourself as available/online
await sock.sendPresenceUpdate('available')

// Mark yourself as unavailable/offline
await sock.sendPresenceUpdate('unavailable')

// Show typing indicator in a chat
await sock.sendPresenceUpdate('composing', jid)

// Show recording audio indicator
await sock.sendPresenceUpdate('recording', jid)

// Stop typing/recording indicator
await sock.sendPresenceUpdate('paused', jid)
type
WAPresence
required
The type of presence to send:
  • available - Mark yourself as online
  • unavailable - Mark yourself as offline
  • composing - Show typing indicator
  • recording - Show recording audio indicator
  • paused - Stop typing/recording indicator
toJid
string
The JID of the chat where the presence update should be sent. Required for typing/recording indicators, optional for available/unavailable.
When sending available or unavailable, the presence is broadcast globally. For typing indicators (composing, recording, paused), you must specify the target chat JID.

Subscribe to presence updates

Request to receive presence updates for a specific user or chat.
// The presence update is fetched and called here
sock.ev.on('presence.update', console.log)

// Request updates for a chat
await sock.presenceSubscribe(jid)
toJid
string
required
The JID of the user or chat to subscribe to for presence updates

Handle presence updates

Listen for incoming presence updates from other users.
sock.ev.on('presence.update', (update) => {
    console.log('Presence update:', update)
    // update contains:
    // - id: JID of the user
    // - presences: object with presence data
})
You must call presenceSubscribe() for a user before you can receive their presence updates. The presence.update event will fire whenever the subscribed user’s presence changes.

Presence types

  • available - User is online/active
  • unavailable - User is offline
  • composing - User is typing a message
  • recording - User is recording audio
  • paused - User stopped typing/recording

Example: Show typing indicator

// Start typing
await sock.sendPresenceUpdate('composing', jid)

// Simulate typing for 3 seconds
await new Promise(resolve => setTimeout(resolve, 3000))

// Stop typing
await sock.sendPresenceUpdate('paused', jid)

// Send the actual message
await sock.sendMessage(jid, { text: 'Hello!' })
Typing indicators are temporary and will automatically expire. You should stop the indicator by sending a paused presence update when done typing.

Build docs developers (and LLMs) love