> ## Documentation Index
> Fetch the complete documentation index at: https://whatsapp-rust.jlucaso.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Labels

> Create, delete, and associate WhatsApp chat labels, and react to label changes from linked devices

The `Labels` feature manages WhatsApp chat labels (etiquetas) — the colored tags WhatsApp Business uses to organize chats. Outbound calls create, rename, recolor, or delete labels and add or remove a label on a chat. Inbound label changes made on a linked device (such as WhatsApp Web or the phone) are delivered as events.

Labels sync across all linked devices via WhatsApp's app state sync mechanism (the `regular` collection, action version 3).

## Access

Access label operations through the client:

```rust theme={null}
let labels = client.labels();
```

## Create or update a label

### create\_label

Create a new label or update an existing one. Because app state is an upsert keyed by `label_id`, calling this with an existing `label_id` renames or recolors that label.

```rust theme={null}
pub async fn create_label(
    &self,
    label_id: &str,
    name: &str,
    color: i32,
) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — Stable identifier for the label. Must be non-empty. Reuse the same `label_id` to update the label later.
* `name` — Display name shown in the WhatsApp UI. Must be non-empty.
* `color` — WhatsApp color index for the label swatch.

**Example:**

```rust theme={null}
// Create a new "Work" label
client.labels().create_label("5", "Work", 2).await?;

// Rename and recolor the same label later
client.labels().create_label("5", "Clients", 4).await?;
```

## Delete a label

### delete\_label

Delete a label. Existing chat associations are kept by the server; WhatsApp Web prunes them from its local database on receipt of the delete.

```rust theme={null}
pub async fn delete_label(&self, label_id: &str) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — The label to delete. Must be non-empty.

**Example:**

```rust theme={null}
client.labels().delete_label("5").await?;
```

## Associate a label with a chat

### add\_chat\_label

Tag a chat with a label.

```rust theme={null}
pub async fn add_chat_label(
    &self,
    label_id: &str,
    chat_jid: &Jid,
) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — The label to apply. Must be non-empty.
* `chat_jid` — The chat to label.

**Example:**

```rust theme={null}
use whatsapp_rust::wacore_binary::jid::Jid;

let chat: Jid = "15551234567@s.whatsapp.net".parse()?;
client.labels().add_chat_label("5", &chat).await?;
```

### remove\_chat\_label

Remove a label from a chat.

```rust theme={null}
pub async fn remove_chat_label(
    &self,
    label_id: &str,
    chat_jid: &Jid,
) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — The label to remove. Must be non-empty.
* `chat_jid` — The chat to untag.

**Example:**

```rust theme={null}
client.labels().remove_chat_label("5", &chat).await?;
```

## Associate a label with a message

Pass a `MessageId`, or project `target.chat()` and `target.id()` from a `MessageRef`. Label indices use only chat and content ID; participant and direction do not become extra protocol fields.

### add\_message\_label

Use this to associate a label with a single message. Unlike [`add_chat_label`](#add_chat_label) above, this association is keyed by the message as well as the chat, under the `label_message` action.

```rust theme={null}
pub async fn add_message_label(
    &self,
    label_id: &str,
    chat_jid: &Jid,
    message_id: &MessageId,
) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — The label to apply. Must be non-empty.
* `chat_jid` — The chat containing the message.
* `message_id`; The validated `MessageId` of the message to label.

**Example:**

```rust theme={null}
use whatsapp_rust::{Client, MessageRef, AppStateError};

async fn label_message(client: &Client, target: &MessageRef<'_>) -> Result<(), AppStateError> {
    client.labels().add_message_label("5", target.chat(), target.id()).await
}
```

### remove\_message\_label

Remove a label association from a single message.

```rust theme={null}
pub async fn remove_message_label(
    &self,
    label_id: &str,
    chat_jid: &Jid,
    message_id: &MessageId,
) -> Result<(), AppStateError>
```

**Parameters:**

* `label_id` — The label to remove. Must be non-empty.
* `chat_jid` — The chat containing the message.
* `message_id`; The validated `MessageId` of the message to unlabel.

**Example:**

```rust theme={null}
use whatsapp_rust::{Client, MessageRef, AppStateError};

async fn unlabel_message(client: &Client, target: &MessageRef<'_>) -> Result<(), AppStateError> {
    client.labels().remove_message_label("5", target.chat(), target.id()).await
}
```

Both calls send one mutation per message. There is no batch form on the wire, matching WhatsApp Web's own builder.

> [!NOTE]
>
> `label_message` is not in the generated app-state schema registry, because WhatsApp Web's current live action table no longer builds this mutation (only `label_edit` and `label_jid` remain there). It is still a first-class protocol action: the protobuf action registry declares it, and both whatsmeow and Baileys build the identical index. For that reason the schema is hand-maintained separately from the generated set. The wire index is `["label_message", labelId, chatJid, messageId, "0", "0"]` on the `regular` collection at action version 3. The trailing `"0", "0"` pair is the message-key `fromMe`/`participant` tail every message-scoped action carries, and no observed source shows it holding anything but its defaults.

## Inbound label events

Label edits, chat assignments, message assignments and sublist changes arrive through the event bus. The first three carry the underlying app-state action. `LabelSublistUpdate` instead carries a typed upsert/removal keyed by `(predefined_id, chat_jid)`; it does not assign the parent label.

The four-event example below targets [main snapshot `7e5c198e`](https://github.com/oxidezap/whatsapp-rust/tree/7e5c198e1a25ea405faa7a69a47bc727ea15484c). Use the [migration dependency pin](https://whatsapp-rust.jlucaso.com/guides/rust-api-migration.md#select-the-source-and-profile) for it. See [sublist semantics](https://whatsapp-rust.jlucaso.com/concepts/events.md#labelsublistupdate) for unknown numeric IDs, timestamps, replay and consumer storage.

```rust theme={null}
use whatsapp_rust::wacore::types::events::Event;

fn inspect_label_event(event: &Event) {
    match event {
        Event::LabelEditUpdate(update) => {
            if update.action.deleted == Some(true) {
                println!("Label {} deleted", update.label_id);
            } else {
                println!(
                    "Label {} = {:?} (color {:?})",
                    update.label_id,
                    update.action.name,
                    update.action.color,
                );
            }
        }
        Event::LabelAssociationUpdate(update) => {
            let attached = update.action.labeled == Some(true);
            println!(
                "Label {} {} chat {}",
                update.label_id,
                if attached { "added to" } else { "removed from" },
                update.chat_jid,
            );
        }
        Event::MessageLabelAssociationUpdate(update) => {
            let attached = update.action.labeled == Some(true);
            println!(
                "Label {} {} message {} in chat {}",
                update.label_id,
                if attached { "added to" } else { "removed from" },
                update.message_id,
                update.chat_jid,
            );
        }
        Event::LabelSublistUpdate(update) => {
            // Apply change in your store by (predefined_id, chat_jid).
            println!("Sublist {} in {}: {:?}",
                update.predefined_id, update.chat_jid, update.change);
        }
        _ => {}
    }
}
```

`from_full_sync` is `true` when the event came from an initial app state full sync, so you can suppress UI notifications during bootstrap.

## App state sync

| Action | Collection | Action version |
| - | - | - |
| Create / update / delete label | `regular` | 3 |
| Add / remove chat label association | `regular` | 3 |
| Add / remove message label association | `regular` | 3 |
| Observe sublist upsert / removal, inbound only | `regular` | 1 |

> [!NOTE]
>
> App state sync requires the relevant encryption keys, which arrive during initial sync after pairing. Outbound label calls may fail if invoked immediately after pairing before sync completes.

> [!NOTE]
>
> `create_label`, `delete_label`, `add_chat_label`, and `remove_chat_label` are thin wrappers over the same app-state send path as [chat actions](https://whatsapp-rust.jlucaso.com/api/chat-actions.md#app-state-sync). They share its conflict-retry behavior, added in PR [#1158](https://github.com/oxidezap/whatsapp-rust/pull/1158). A call that loses a version race with another linked device is no longer silently dropped. The client applies the winning patches, rebuilds the mutation, and resends. It retries up to 5 times before returning `Err`. See [Chat actions — App state sync](https://whatsapp-rust.jlucaso.com/api/chat-actions.md#app-state-sync) for the full explanation.

## Error handling

All methods return `Result<(), AppStateError>`. If you pass an empty `label_id` (or an empty `name` to `create_label`), the call fails immediately with `AppStateError::InvalidRequest` before any network work is done.

A call can also return `AppStateError::Internal` if no app state sync key is available yet, a network error occurred, or an app-state version conflict with another device could not be resolved after 5 rebuild-and-resend attempts (see [App state sync](#app-state-sync) above).

```rust theme={null}
use whatsapp_rust::AppStateError;

if let Err(AppStateError::InvalidRequest(msg)) = client.labels().create_label("", "Work", 0).await {
    eprintln!("Validation failed: {msg}"); // "label_id cannot be empty"
}
```

## Complete example

```rust theme={null}
use whatsapp_rust::Client;
use whatsapp_rust::wacore_binary::jid::Jid;
use std::sync::Arc;

async fn tag_vip_chats(client: &Arc<Client>) -> anyhow::Result<()> {
    let vip: Jid = "15551234567@s.whatsapp.net".parse()?;
    let lead: Jid = "15559876543@s.whatsapp.net".parse()?;

    // Create a "VIP" label (color index 3)
    client.labels().create_label("vip", "VIP", 3).await?;

    // Tag two chats
    client.labels().add_chat_label("vip", &vip).await?;
    client.labels().add_chat_label("vip", &lead).await?;

    // Later: drop one of the chats from the label
    client.labels().remove_chat_label("vip", &lead).await?;

    Ok(())
}
```

## See also

* [Events](https://whatsapp-rust.jlucaso.com/concepts/events.md) — Handle `LabelEditUpdate`, `LabelAssociationUpdate`, `MessageLabelAssociationUpdate`, and `LabelSublistUpdate`
* [Chat actions](https://whatsapp-rust.jlucaso.com/api/chat-actions.md) — Archive, pin, mute, star, and other app-state-synced chat operations
* [State management](https://whatsapp-rust.jlucaso.com/advanced/state-management.md) — How app state sync works under the hood


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.