Overview
WhatsApp-Rust uses an event-driven architecture where the client emits events for all WhatsApp protocol interactions. Your application subscribes to these events to handle messages, connection changes, and notifications.Event System Architecture
CoreEventBus
Location:wacore/src/types/events.rs
- Thread-safe event dispatching
- Multiple handlers supported
- Clone-cheap with
Arc
EventHandler Trait
Event Enum
Location:wacore/src/types/events.rs:292-351
Connection Events
Connected
Emitted: After successful connection and authenticationDisconnected
Emitted: When connection is lostConnectFailure
Emitted: When connection fails with a specific reasonTemporaryBan
Emitted: When account is temporarily bannedStreamReplaced
Emitted: When another device connects with the same credentialsPairing Events
PairingQrCode
Emitted: For each QR code in rotationPairingCode
Emitted: When pair code is generatedPairSuccess
Emitted: When pairing completes successfullyPairError
Emitted: When pairing failsMessage Events
Message
Emitted: For all incoming messages (text, media, etc.)Receipt
Emitted: For delivery/read/played receiptsUndecryptableMessage
Emitted: When a message cannot be decryptedPresence Events
ChatPresence
Emitted: For typing indicators and recording statesPresence
Emitted: For online/offline status and last seenUser Update Events
PictureUpdate
Emitted: When a user changes their profile pictureUserAboutUpdate
Emitted: When a user changes their status/aboutPushNameUpdate
Emitted: When a contact changes their display nameSelfPushNameUpdated
Emitted: When your own push name is updatedGroup Events
JoinedGroup
Emitted: When added to a groupGroupInfoUpdate
Emitted: When group metadata changes (subject, participants, etc.)Chat State Events
PinUpdate
Emitted: When a chat is pinned/unpinnedMuteUpdate
Emitted: When a chat is muted/unmutedArchiveUpdate
Emitted: When a chat is archived/unarchivedMarkChatAsReadUpdate
Emitted: When a chat is marked as readHistory Sync Events
HistorySync
Emitted: For chat history synchronizationOfflineSyncPreview
Emitted: Preview of pending offline sync dataOfflineSyncCompleted
Emitted: When offline sync completesDevice Events
DeviceListUpdate
Emitted: When a user’s device list changesBusinessStatusUpdate
Emitted: When a business account status changesEvent Handler Patterns
Bot Builder Pattern
Multiple Handlers
Async Event Handlers
Performance Optimization
LazyConversation
Purpose: Avoid parsing large protobuf messages unless neededSharedData
Purpose: Cheap cloning of large event dataBest Practices
Event Filtering
Error Handling
Spawning Tasks
Related Sections
Architecture
Understand the event bus system
Authentication
Learn about pairing events
Sending messages
Sending and receiving messages
Client API
Complete client API reference