whatsapp_rust/handlers/traits.rs
1use crate::client::Client;
2use async_trait::async_trait;
3use std::sync::Arc;
4use wacore_binary::node::Node;
5
6/// Trait for handling specific types of XML stanzas received from the WhatsApp server.
7///
8/// Each handler is responsible for processing a specific top-level XML tag (e.g., "message", "iq", "receipt").
9/// This pattern allows for better separation of concerns and makes it easier to add new stanza types
10/// without modifying the core client dispatch logic.
11#[async_trait]
12pub trait StanzaHandler: Send + Sync {
13 /// Returns the XML tag this handler is responsible for (e.g., "message", "iq").
14 fn tag(&self) -> &'static str;
15
16 /// Asynchronously handle the incoming node.
17 ///
18 /// # Arguments
19 /// * `client` - Arc reference to the client instance
20 /// * `node` - The XML node to process
21 /// * `cancelled` - If set to `true`, prevents the deferred ack from being sent
22 ///
23 /// # Returns
24 /// Returns `true` if the node was successfully handled, `false` if it should be
25 /// processed by other handlers or logged as unhandled.
26 async fn handle(&self, client: Arc<Client>, node: &Node, cancelled: &mut bool) -> bool;
27}