Skip to main content
The Community feature provides methods for managing WhatsApp communities, including creation, subgroup linking/unlinking, and metadata queries. Community mutations use IQ stanzas (w:g2 namespace) while metadata queries use MEX (GraphQL).

Access

Access community operations through the client:
let community = client.community();

Methods

create

Create a new community.
pub async fn create(
    &self,
    options: CreateCommunityOptions,
) -> Result<CreateCommunityResult, anyhow::Error>
Parameters: Returns:
  • CreateCommunityResult — Contains the gid (JID) of the created community
Example:
use whatsapp_rust::features::community::CreateCommunityOptions;

let mut options = CreateCommunityOptions::new("My Community");
options.description = Some("A great community".to_string());
options.closed = true;

let result = client.community().create(options).await?;
println!("Created community: {}", result.gid);
If a description is provided, it is set via a follow-up IQ after creation — the group create stanza does not support inline descriptions for communities.

deactivate

Deactivate (delete) a community. Subgroups are unlinked but not deleted.
pub async fn deactivate(&self, community_jid: &Jid) -> Result<(), anyhow::Error>
Parameters:
  • community_jid — JID of the community to deactivate
Example:
client.community().deactivate(&community_jid).await?;
Link existing groups as subgroups of a community.
pub async fn link_subgroups(
    &self,
    community_jid: &Jid,
    subgroup_jids: &[Jid],
) -> Result<LinkSubgroupsResult, anyhow::Error>
Parameters:
  • community_jid — JID of the parent community
  • subgroup_jids — Array of group JIDs to link
Returns:
  • LinkSubgroupsResult — Contains linked_jids (successfully linked) and failed_groups (JID + error code pairs)
Example:
let subgroup_jids = vec![
    "120363001111111@g.us".parse()?,
    "120363002222222@g.us".parse()?,
];

let result = client.community()
    .link_subgroups(&community_jid, &subgroup_jids)
    .await?;

println!("Linked: {:?}", result.linked_jids);
for (jid, error_code) in &result.failed_groups {
    eprintln!("Failed: {} (error {})", jid, error_code);
}
Unlink subgroups from a community.
pub async fn unlink_subgroups(
    &self,
    community_jid: &Jid,
    subgroup_jids: &[Jid],
    remove_orphan_members: bool,
) -> Result<UnlinkSubgroupsResult, anyhow::Error>
Parameters:
  • community_jid — JID of the parent community
  • subgroup_jids — Array of subgroup JIDs to unlink
  • remove_orphan_members — Whether to remove members who are only in the community through the unlinked subgroups
Returns:
  • UnlinkSubgroupsResult — Contains unlinked_jids (successfully unlinked) and failed_groups (JID + error code pairs)
Example:
let result = client.community()
    .unlink_subgroups(&community_jid, &subgroup_jids, true)
    .await?;

println!("Unlinked: {:?}", result.unlinked_jids);

get_subgroups

Fetch all subgroups of a community via MEX (GraphQL).
pub async fn get_subgroups(
    &self,
    community_jid: &Jid,
) -> Result<Vec<CommunitySubgroup>, MexError>
Parameters:
  • community_jid — JID of the community
Returns:
  • Vec<CommunitySubgroup> — List of subgroups with metadata
Example:
let subgroups = client.community()
    .get_subgroups(&community_jid)
    .await?;

for sg in &subgroups {
    println!("{}: {} (default: {}, general: {})",
        sg.id, sg.subject, sg.is_default_sub_group, sg.is_general_chat);
}

get_subgroup_participant_counts

Fetch participant counts per subgroup via MEX (GraphQL).
pub async fn get_subgroup_participant_counts(
    &self,
    community_jid: &Jid,
) -> Result<Vec<(Jid, u32)>, MexError>
Parameters:
  • community_jid — JID of the community
Returns:
  • Vec<(Jid, u32)> — Pairs of subgroup JID and participant count
Example:
let counts = client.community()
    .get_subgroup_participant_counts(&community_jid)
    .await?;

for (jid, count) in &counts {
    println!("{}: {} participants", jid, count);
}

query_linked_group

Query a linked subgroup’s metadata from the parent community.
pub async fn query_linked_group(
    &self,
    community_jid: &Jid,
    subgroup_jid: &Jid,
) -> Result<GroupMetadata, anyhow::Error>
Parameters:
  • community_jid — JID of the parent community
  • subgroup_jid — JID of the subgroup to query
Returns:
  • GroupMetadata — Full group metadata (see Groups API)
Example:
let metadata = client.community()
    .query_linked_group(&community_jid, &subgroup_jid)
    .await?;

println!("Subject: {}", metadata.subject);

join_subgroup

Join a linked subgroup via the parent community.
pub async fn join_subgroup(
    &self,
    community_jid: &Jid,
    subgroup_jid: &Jid,
) -> Result<GroupMetadata, anyhow::Error>
Parameters:
  • community_jid — JID of the parent community
  • subgroup_jid — JID of the subgroup to join
Returns:
  • GroupMetadata — Metadata of the joined subgroup
Example:
let metadata = client.community()
    .join_subgroup(&community_jid, &subgroup_jid)
    .await?;

println!("Joined: {}", metadata.subject);

get_linked_groups_participants

Get all participants across all linked groups of a community.
pub async fn get_linked_groups_participants(
    &self,
    community_jid: &Jid,
) -> Result<Vec<GroupParticipant>, anyhow::Error>
Parameters:
  • community_jid — JID of the community
Returns:
  • Vec<GroupParticipant> — List of participants across all subgroups
Example:
let participants = client.community()
    .get_linked_groups_participants(&community_jid)
    .await?;

for p in &participants {
    println!("{} (admin: {})", p.jid, p.is_admin);
}

Types

CreateCommunityOptions

Options for creating a new community.
pub struct CreateCommunityOptions {
    pub name: String,
    pub description: Option<String>,
    pub closed: bool,
    pub allow_non_admin_sub_group_creation: bool,
    pub create_general_chat: bool,
}
Fields:
  • name — Community name
  • description — Optional description (set via follow-up IQ)
  • closed — Whether the community requires approval to join (default: false)
  • allow_non_admin_sub_group_creation — Whether non-admin members can create subgroups (default: false)
  • create_general_chat — Whether to create a general chat subgroup (default: true)
Constructor:
let options = CreateCommunityOptions::new("My Community");

CreateCommunityResult

Result of creating a community.
pub struct CreateCommunityResult {
    pub gid: Jid,
}

CommunitySubgroup

A subgroup within a community.
pub struct CommunitySubgroup {
    pub id: Jid,
    pub subject: String,
    pub participant_count: Option<u32>,
    pub is_default_sub_group: bool,
    pub is_general_chat: bool,
}
Fields:
  • id — Subgroup JID
  • subject — Subgroup name
  • participant_count — Number of participants (if available)
  • is_default_sub_group — Whether this is the default announcement subgroup
  • is_general_chat — Whether this is the general chat subgroup

LinkSubgroupsResult

Result of linking subgroups to a community.
pub struct LinkSubgroupsResult {
    pub linked_jids: Vec<Jid>,
    pub failed_groups: Vec<(Jid, u32)>,
}

UnlinkSubgroupsResult

Result of unlinking subgroups from a community.
pub struct UnlinkSubgroupsResult {
    pub unlinked_jids: Vec<Jid>,
    pub failed_groups: Vec<(Jid, u32)>,
}

GroupType

Classification of a group within the community hierarchy.
pub enum GroupType {
    Default,
    Community,
    LinkedSubgroup,
    LinkedAnnouncementGroup,
    LinkedGeneralGroup,
}
Variants:
  • Default — Regular standalone group
  • Community — Community parent group
  • LinkedSubgroup — A subgroup linked to a community
  • LinkedAnnouncementGroup — The default announcement subgroup of a community
  • LinkedGeneralGroup — The general chat subgroup of a community
Use the group_type() function to classify a group:
use whatsapp_rust::features::community::{group_type, GroupType};

let metadata = client.groups().get_metadata(&group_jid).await?;
let gtype = group_type(&metadata);

Error handling

Mutation methods (create, deactivate, link_subgroups, unlink_subgroups, query_linked_group, join_subgroup, get_linked_groups_participants) return anyhow::Error. MEX-based query methods (get_subgroups, get_subgroup_participant_counts) return MexError:
use whatsapp_rust::features::mex::MexError;

match client.community().get_subgroups(&community_jid).await {
    Ok(subgroups) => println!("Found {} subgroups", subgroups.len()),
    Err(MexError::PayloadParsing(msg)) => {
        eprintln!("Parse error: {}", msg);
    }
    Err(e) => eprintln!("Error: {}", e),
}