Skip to main content
The 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.
Parameters:
  • to - Recipient JID (user or group)
  • state: ChatStateType - Type of chat state to send
Returns:
  • Result<(), ChatStateError>Ok(()) on success; a ChatStateError if the client is disconnected or the JID is invalid
Example:

send_composing

Convenience method to send typing indicator.
Example:

send_recording

Convenience method to send audio recording indicator.
Example:

send_paused

Convenience method to send paused/stopped typing indicator.
Example:

Receiving chat state events

ChatStateEvent

Incoming chatstate stanzas (typing indicators from other users) are dispatched as ChatStateEvent 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.
Example:

ReceivedChatState

The state values for incoming chatstate events, aligned with WhatsApp Web’s WAChatState 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"
String conversion:

Wire Format

Composing (Typing)

Recording (Voice)

Note: Recording uses <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 return Result<(), 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

  1. Throttle updates: Don’t send chat state updates more than once every 2-3 seconds
  2. Clear on send: Send Paused before sending the actual message
  3. Auto-timeout: Consider auto-clearing typing indicators after 10-15 seconds of inactivity
  4. Don’t spam: Only send when state actually changes
  5. Groups: Be mindful that all group members will see the indicator

Complete Example