Chat types represent WhatsApp conversations with their metadata and state.
Chat
Extends proto.IConversation with additional Baileys-specific fields.
Chat JID (identifier) Examples:
"1234567890@s.whatsapp.net" (individual chat)
"123456789@g.us" (group chat)
"status@broadcast" (status broadcasts)
Timestamp of the conversation
Unix timestamp of when the last message was received in the chat (Baileys extension)
Number of unread messages
Whether the chat is archived
Pin position (0 = not pinned, higher = pinned earlier)
Unix timestamp when mute expires (0 = not muted)
Chat name (for groups, business accounts, or saved contacts)
Whether the chat is marked as not spam
Disappearing messages expiration time in seconds Common values:
0 - disabled
86400 - 24 hours
604800 - 7 days
7776000 - 90 days
ephemeralSettingTimestamp
When disappearing messages setting was last changed
ChatUpdate
Partial update to a chat’s properties.
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
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
}
true to archive, false to unarchive
Last messages in the chat for sync purposes
true to pin, false to unpin
null - unmute
Unix timestamp - mute until this time
Duration in seconds - mute for this long from now
{
markRead : boolean
lastMessages : LastMessageList
}
true to mark as read, false to mark as unread
{
clear : boolean
lastMessages : LastMessageList
}
{
delete : true
lastMessages : LastMessageList
}
{
deleteForMe : {
deleteMedia : boolean
key : WAMessageKey
timestamp : number
}
}
{
star : {
messages : { id : string ; fromMe ?: boolean }[]
star : boolean
}
}
{
pushNameSetting : string
}
{
disableLinkPreviews : proto . SyncActionValue . IPrivacySettingDisableLinkPreviewsAction
}
{ 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
Last known presence status Values: 'unavailable', 'available', 'composing', 'recording', 'paused'
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