Chatstate struct provides methods for sending typing indicators and recording notifications to recipients.
Access
Access chatstate operations through the client:Methods
send
Send a chat state update to a recipient.to- Recipient JID (user or group)state: ChatStateType- Type of chat state to send
Result<(), ChatStateError>—Ok(())on success; aChatStateErrorif the client is disconnected or the JID is invalid
send_composing
Convenience method to send typing indicator.send_recording
Convenience method to send audio recording indicator.send_paused
Convenience method to send paused/stopped typing indicator.Receiving chat state events
ChatStateEvent
Incoming chatstate stanzas (typing indicators from other users) are dispatched asChatStateEvent values. Register a handler with register_chatstate_handler to receive them.
Jid
The chat where the event occurred. For direct messages this is the sender’s JID; for groups this is the group JID.
Option<Jid>
For group chats, the participant who triggered the event.
None for 1:1 chats.ReceivedChatState
The parsed chat state — see
ReceivedChatState below.ReceivedChatState
The state values for incoming chatstate events, aligned with WhatsApp Web’sWAChatState constants.
ReceivedChatState is #[non_exhaustive], so match statements should include a wildcard arm.
Wire format mapping:
Sending chat state updates
ChatStateType Enum
ChatStateType is #[non_exhaustive], so match statements should include a wildcard arm to handle future variants.
Methods:
as_str()- Returns"composing","recording", or"paused"
Wire Format
Composing (Typing)
Recording (Voice)
<composing media="audio"> rather than a separate tag.
Paused (Stopped)
Usage Patterns
Typing indicator lifecycle
Recording Audio
Throttling
To avoid spamming chat state updates:Group Chats
Chat state indicators work in group chats as well:Error Handling
All methods returnResult<(), ChatStateError>. You’ll encounter these most often:
- Not connected — you are not connected to WhatsApp
- Invalid JID — the recipient JID is malformed
- Network errors — connection dropped mid-send
Best Practices
- Throttle updates: Don’t send chat state updates more than once every 2-3 seconds
- Clear on send: Send
Pausedbefore sending the actual message - Auto-timeout: Consider auto-clearing typing indicators after 10-15 seconds of inactivity
- Don’t spam: Only send when state actually changes
- Groups: Be mindful that all group members will see the indicator