WhatsApp Metrics (WAM)
Relevant source files
The following files were used as context for generating this wiki page:
WhatsApp Metrics (WAM) is a system within the project responsible for collecting, buffering, and transmitting telemetry and analytical data to WhatsApp servers. Its primary purpose is to track feature usage, performance statistics, and user interactions (such as bot engagement or call quality) to improve service reliability and user experience.
The WAM system operates by encapsulating metric events into binary buffers, which are then transmitted via specific Information Query (IQ) stanzas using the w:stats namespace. This allows the client to provide feedback on various subsystems, including AI bot interactions, media uploads, and connection stability.
Sources: lib/Socket/socket.js:589-605, WAProto/AICommon/AICommon.proto:52-53
Core Architecture and Data Flow
The WAM architecture revolves around the generation and transmission of binary buffers containing encoded metrics. These buffers are sent to the WhatsApp server using an IQ stanza with a set type.
Metric Transmission Flow
The following diagram illustrates the flow of a WAM buffer from the client socket to the WhatsApp servers.
A brief explanation showing how metrics are gathered and pushed to the server via the socket interface.
Sources: lib/Socket/socket.js:589-606, lib/Socket/socket.js:63-82
Key Components
| Component | Description |
|---|---|
sendWAMBuffer | The primary socket method used to wrap a WAM binary buffer into a w:stats IQ stanza and transmit it. |
BotMetricsMetadata | Protobuf message structure containing destination IDs and entry points for tracking AI bot interactions. |
w:stats | The XML namespace used in IQ stanzas specifically for metrics and statistics reporting. |
BotMetricsEntryPoint | An enumeration defining various entry points (e.g., Favicon, Chatlist, Notification) to track how users initiate bot sessions. |
Sources: lib/Socket/socket.js:589-605, WAProto/AICommon/AICommon.proto:441-445, WAProto/AICommon/AICommon.proto:456-490
WAM in AI and Bot Interactions
Metrics are heavily integrated into the AI and Bot subsystems. The BotMetadata and AICommon protobuf definitions include extensive fields for tracking bot performance and user feedback.
Bot Metrics Metadata
AI-specific metrics track the origin and destination of bot messages to analyze user behavior patterns.
This diagram represents the relationship between metadata containers and the specific entry point enumerations used for metric tracking.
Sources: WAProto/AICommon/AICommon.proto:441-445, WAProto/AICommon/AICommon.proto:447-454, WAProto/AICommon/AICommon.proto:456-490
Bot Feedback and Reporting
WAM also facilitates "Bot Feedback Messages," allowing users to provide qualitative data on bot responses.
- Feedback Kinds: Tracking whether a response was positive, generic negative, inaccurate, or refused.
- Survey Metadata: Captures data from side-by-side surveys, including response dwell time and selected request IDs.
- Analytics Data: Includes Tessa and Simon session identifiers for internal tracking of AI model performance.
Sources: WAProto/AICommon/AICommon.proto:81-125, WAProto/AICommon/AICommon.proto:136-160
Implementation Details
Socket-Level Buffer Submission
The socket implementation provides a direct method to send raw metric buffers.
// lib/Socket/socket.js:589-605
const sendWAMBuffer = (wamBuffer) => {
return query({
tag: 'iq',
attrs: {
to: S_WHATSAPP_NET,
id: generateMessageTag(),
xmlns: 'w:stats'
},
content: [
{
tag: 'add',
attrs: {},
content: wamBuffer
}
]
})
}
Sources: lib/Socket/socket.js:589-605
Application Example: Quota Tracking
Metrics are also used to track user quotas, particularly for reasoning-heavy AI features. The message-capping.update event provides real-time metrics on used versus total quota.
// assets/examples/example.js:80-82
sock.ev.on('message-capping.update', ({ used_quota, total_quota }) => {
console.log(`[message-capping.update] Message quota used: ${used_quota}/${total_quota}`);
});
Sources: assets/examples/example.js:80-82, WAProto/AICommon/AICommon.proto:349-358
Conclusion
WhatsApp Metrics (WAM) serves as the analytical backbone of the Baileys implementation. By utilizing binary buffers and specialized IQ stanzas, it ensures that high-fidelity telemetry regarding connection health, bot performance, and feature usage is reported efficiently. This data is critical for maintaining the complex interactions required by modern WhatsApp features like Meta AI and multi-device synchronization.