Skip to main content
Chat types represent WhatsApp conversations with their metadata and state.

Chat

Extends proto.IConversation with additional Baileys-specific fields.
id
string
Chat JID (identifier)Examples:
  • "1234567890@s.whatsapp.net" (individual chat)
  • "123456789@g.us" (group chat)
  • "status@broadcast" (status broadcasts)
conversationTimestamp
number | Long
Timestamp of the conversation
lastMessageRecvTimestamp
number
Unix timestamp of when the last message was received in the chat (Baileys extension)
unreadCount
number
Number of unread messages
archived
boolean
Whether the chat is archived
pinned
number
Pin position (0 = not pinned, higher = pinned earlier)
muteEndTime
number | Long
Unix timestamp when mute expires (0 = not muted)
name
string
Chat name (for groups, business accounts, or saved contacts)
notSpam
boolean
Whether the chat is marked as not spam
ephemeralExpiration
number
Disappearing messages expiration time in secondsCommon values:
  • 0 - disabled
  • 86400 - 24 hours
  • 604800 - 7 days
  • 7776000 - 90 days
ephemeralSettingTimestamp
number | Long
When disappearing messages setting was last changed

ChatUpdate

Partial update to a chat’s properties.
conditional
function
Optional condition to check before applying the update
(bufferedData: BufferedEventData) => boolean | undefined
Returns:
  • true - apply the update
  • false - discard the update
  • undefined - condition not yet fulfilled, buffer the update
timestamp
number
Unix timestamp of when the update occurred
All other fields are from Partial<Chat>.

ChatModification

Union type for modifying chat properties. Each modification has a specific structure:
{
  archive: boolean
  lastMessages: LastMessageList
}
archive
boolean
required
true to archive, false to unarchive
lastMessages
LastMessageList
required
Last messages in the chat for sync purposes
{
  pin: boolean
}
pin
boolean
required
true to pin, false to unpin
{
  mute: number | null
}
mute
number | null
required
  • null - unmute
  • Unix timestamp - mute until this time
  • Duration in seconds - mute for this long from now
{
  markRead: boolean
  lastMessages: LastMessageList
}
markRead
boolean
required
true to mark as read, false to mark as unread
lastMessages
LastMessageList
required
Last messages to mark
{
  clear: boolean
  lastMessages: LastMessageList
}
clear
boolean
required
Must be true
lastMessages
LastMessageList
required
Messages to clear
{
  delete: true
  lastMessages: LastMessageList
}
delete
true
required
Must be true
lastMessages
LastMessageList
required
Last messages in chat
{
  deleteForMe: {
    deleteMedia: boolean
    key: WAMessageKey
    timestamp: number
  }
}
{
  star: {
    messages: { id: string; fromMe?: boolean }[]
    star: boolean
  }
}
{
  pushNameSetting: string
}
{
  contact: proto.SyncActionValue.IContactAction | null
}
{ addLabel: LabelActionBody }
{ addChatLabel: ChatLabelAssociationActionBody }
{ removeChatLabel: ChatLabelAssociationActionBody }
{ addMessageLabel: MessageLabelAssociationActionBody }
{ removeMessageLabel: MessageLabelAssociationActionBody }
{
  quick Reply: QuickReplyAction
}

Supporting Types

LastMessageList

type LastMessageList = 
  | MinimalMessage[] 
  | proto.SyncActionValue.ISyncActionMessageRange
List of messages sorted reverse-chronologically (latest first). For MD modifications, the last message in the array must be the last message received in the chat.

PresenceData

lastKnownPresence
WAPresence
required
Last known presence statusValues: 'unavailable', 'available', 'composing', 'recording', 'paused'
lastSeen
number
Unix timestamp of when user was last seen

WAPresence

type WAPresence = 
  | 'unavailable' 
  | 'available' 
  | 'composing' 
  | 'recording' 
  | 'paused'

Privacy Settings Types

WAPrivacyValue

type WAPrivacyValue = 
  | 'all' 
  | 'contacts' 
  | 'contact_blacklist' 
  | 'none'

WAPrivacyOnlineValue

type WAPrivacyOnlineValue = 'all' | 'match_last_seen'

WAPrivacyGroupAddValue

type WAPrivacyGroupAddValue = 
  | 'all' 
  | 'contacts' 
  | 'contact_blacklist'

WAReadReceiptsValue

type WAReadReceiptsValue = 'all' | 'none'

WAPrivacyCallValue

type WAPrivacyCallValue = 'all' | 'known'

WAPrivacyMessagesValue

type WAPrivacyMessagesValue = 'all' | 'contacts'

Usage Examples

Handling Chat Events

import { Chat, ChatUpdate } from '@whiskeysockets/baileys'

// New chats
sock.ev.on('chats.upsert', (chats: Chat[]) => {
  for (const chat of chats) {
    console.log('New chat:', chat.id)
    console.log('Unread count:', chat.unreadCount)
    console.log('Archived:', chat.archived)
  }
})

// Chat updates
sock.ev.on('chats.update', (updates: ChatUpdate[]) => {
  for (const update of updates) {
    if (update.unreadCount !== undefined) {
      console.log(`${update.id}: ${update.unreadCount} unread`)
    }
    if (update.archived !== undefined) {
      console.log(`${update.id} ${update.archived ? 'archived' : 'unarchived'}`)
    }
  }
})

// Deleted chats
sock.ev.on('chats.delete', (deletedChats: string[]) => {
  console.log('Deleted chats:', deletedChats)
})

Modifying Chats

// Archive a chat
await sock.chatModify(
  {
    archive: true,
    lastMessages: [lastMessage]
  },
  chatJid
)

// Pin a chat
await sock.chatModify({ pin: true }, chatJid)

// Mute for 8 hours
await sock.chatModify(
  { mute: 8 * 60 * 60 * 1000 },
  chatJid
)

// Unmute
await sock.chatModify({ mute: null }, chatJid)

// Mark as read
await sock.chatModify(
  {
    markRead: true,
    lastMessages: [lastMessage]
  },
  chatJid
)

// Delete chat
await sock.chatModify(
  {
    delete: true,
    lastMessages: [lastMessage]
  },
  chatJid
)

Working with Presence

// Subscribe to presence updates
await sock.presenceSubscribe(chatJid)

// Send presence
await sock.sendPresenceUpdate('composing', chatJid)
await sock.sendPresenceUpdate('paused', chatJid)

// Handle presence updates
sock.ev.on('presence.update', ({ id, presences }) => {
  for (const [jid, presence] of Object.entries(presences)) {
    console.log(`${jid} is ${presence.lastKnownPresence}`)
    
    if (presence.lastSeen) {
      const date = new Date(presence.lastSeen * 1000)
      console.log(`Last seen: ${date.toLocaleString()}`)
    }
  }
})

Checking Chat State

function getChatState(chat: Chat) {
  const state = {
    isPinned: (chat.pinned || 0) > 0,
    isArchived: chat.archived || false,
    isMuted: (chat.muteEndTime || 0) > Date.now() / 1000,
    hasUnread: (chat.unreadCount || 0) > 0,
    hasDisappearingMessages: (chat.ephemeralExpiration || 0) > 0
  }
  
  return state
}

const chat: Chat = { /* ... */ }
const state = getChatState(chat)

if (state.isMuted) {
  console.log('Chat is muted')
}
if (state.hasDisappearingMessages) {
  console.log(`Messages disappear after ${chat.ephemeralExpiration}s`)
}

Chat Sorting

function sortChats(chats: Chat[]): Chat[] {
  return chats.sort((a, b) => {
    // Pinned chats first (higher pin number = pinned earlier)
    const aPinned = a.pinned || 0
    const bPinned = b.pinned || 0
    if (aPinned !== bPinned) return bPinned - aPinned
    
    // Then by last message timestamp
    const aTime = a.lastMessageRecvTimestamp || a.conversationTimestamp || 0
    const bTime = b.lastMessageRecvTimestamp || b.conversationTimestamp || 0
    return Number(bTime) - Number(aTime)
  })
}
  • Contact - Contact information
  • Message - Message types
  • Events - Event types including chat events
  • Groups - Group metadata and information