Communities & Newsletters
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Communities and Newsletters are specialized group-like structures within the Baileys project designed for large-scale communication and broadcasting. Communities act as umbrella structures for sub-groups, providing administrative tools to manage membership and hierarchical communication. Newsletters provide a broadcast-oriented platform allowing for one-to-many communication with features like subscriber counts, view counts, and emoji reactions.
These modules extend the core socket functionality to handle specific Binary Node protocols (w:g2 for communities and newsletter or w:mex for newsletters). They facilitate metadata extraction, participation management, and interaction handling (like reacting to broadcasted messages) through structured IQ queries.
Sources: lib/Socket/community.js:10-25, lib/Socket/newsletter.js:12-40
Newsletters
Newsletters in Baileys are managed via the makeNewsletterSocket function. Unlike standard chats, newsletters utilize the WhatsApp MEX (Meta Experience) query system for metadata and administrative actions.
Architecture and Data Flow
Newsletter interactions primarily flow through two query types: newsletterQuery for standard IQ stanzas and newsletterWMexQuery for GraphQL-like MEX queries. MEX queries use specific queryId values to perform mutations like updating pictures or changing owner roles.
The diagram shows the dual-path communication used for Newsletter operations, distinguishing between standard binary stanzas and MEX mutations.
Sources: lib/Socket/newsletter.js:14-50
Key Newsletter Functions
| Function | Purpose | Source |
|---|---|---|
newsletterMetadata | Fetches metadata like name, description, and subscriber count. | lib/Socket/newsletter.js:80-92 |
newsletterCreate | Creates a new newsletter with name, description, and optional picture. | lib/Socket/newsletter.js:143-176 |
newsletterReactMessage | Adds or removes an emoji reaction to a specific message server ID. | lib/Socket/newsletter.js:215-224 |
newsletterFetchMessages | Retrieves message history using a JID or invite key. | lib/Socket/newsletter.js:225-234 |
Metadata Schema
Newsletter metadata is extracted from binary nodes and parsed into a structured object.
| Field | Type | Description |
|---|---|---|
id | String | Unique JID for the Newsletter. |
subscribers | Number | Total count of current subscribers. |
reaction_codes | String | Allowed reaction modes (e.g., 'ALL'). |
viewer_metadata | Object | Role-specific data for the user requesting metadata. |
verification | String | Verification status of the newsletter. |
Sources: lib/Socket/newsletter.js:246-267, lib/Socket/newsletter.d.ts:7-30
Communities
Communities are managed through makeCommunitiesSocket, which wraps business socket functionality to handle group-of-groups logic. They use the w:g2 XML namespace for node communication.
Community Lifecycle Management
Communities support complex membership approval flows. Admins can manage a list of pending participants who wish to join the community.
This sequence illustrates the flow for an administrator fetching and approving pending membership requests within a community.
Sources: lib/Socket/community.js:132-166
Community Features and Logic
Communities introduce specific addressing modes, notably supporting both standard JIDs and LIDs (Linked Identifiers).
- Creation: When creating a community via
communityCreate, the system automatically generates a general chat and sets the default membership approval torequest_required. - Linking: Communities can have a
linkedParentproperty, indicating their position in a hierarchy. - Dirty Bits: The socket listens for
CB:ib,,dirtynodes with a type ofcommunitiesto trigger a re-sync of participating communities.
Sources: lib/Socket/community.js:86-121, lib/Socket/community.js:235-265
Message Composition for Broadcasts
Messaging in Communities and Newsletters requires specific encoding and metadata handling to ensure delivery across the broadcast infrastructure.
Newsletter Message Encoding
Newsletter messages are encoded differently from standard WAMessages. The encodeNewsletterMessage utility skips the random padding often applied to standard messages.
const encodeNewsletterMessage = (message) => {
return WAProto_1.proto.Message.encode(message).finish()
}
Sources: lib/Utils/generics.js:192-194
Media Preparation
When preparing media for Newsletters, the prepareWAMessageMedia function identifies the destination JID. If the JID is a newsletter, it uses getRawMediaUploadData instead of encrypted streams typical for end-to-end encrypted chats.
Sources: lib/Utils/messages.js:84-110
Technical Summary
The implementation of Communities and Newsletters separates broadcast logic from standard group messaging. Communities focus on membership management and hierarchical group structures using w:g2, while Newsletters utilize the MEX framework for public broadcasting, metadata tracking (views/subscribers), and lightweight interactions (reactions). Both systems leverage the specialized BinaryNode utilities for protocol-level communication.
Sources: lib/Socket/community.js:10, lib/Socket/newsletter.js:12, lib/WABinary/generic-utils.js:5-30