Client

Struct Client 

Source
pub struct Client {
    pub group_cache: Arc<DashMap<Jid, GroupInfo>>,
    pub device_cache: Arc<DashMap<Jid, (Vec<Jid>, Instant)>>,
    pub enable_auto_reconnect: Arc<AtomicBool>,
    pub auto_reconnect_errors: Arc<AtomicU32>,
    pub last_successful_connect: Arc<Mutex<Option<DateTime<Utc>>>>,
    pub custom_enc_handlers: Arc<DashMap<String, Arc<dyn EncHandler>>>,
    /* private fields */
}

Fields§

§group_cache: Arc<DashMap<Jid, GroupInfo>>§device_cache: Arc<DashMap<Jid, (Vec<Jid>, Instant)>>§enable_auto_reconnect: Arc<AtomicBool>§auto_reconnect_errors: Arc<AtomicU32>§last_successful_connect: Arc<Mutex<Option<DateTime<Utc>>>>§custom_enc_handlers: Arc<DashMap<String, Arc<dyn EncHandler>>>

Custom handlers for encrypted message types

Implementations§

Source§

impl Client

Source

pub async fn new( persistence_manager: Arc<PersistenceManager>, ) -> (Arc<Self>, Receiver<MajorSyncTask>)

Source

pub async fn run(self: &Arc<Self>)

Source

pub async fn connect(self: &Arc<Self>) -> Result<(), Error>

Source

pub async fn disconnect(&self)

Source

pub async fn set_passive(&self, passive: bool) -> Result<(), IqError>

Source

pub fn is_connected(&self) -> bool

Source

pub fn is_logged_in(&self) -> bool

Source

pub fn persistence_manager(&self) -> Arc<PersistenceManager>

Get access to the PersistenceManager for this client. This is useful for multi-account scenarios to get the device ID.

Source

pub async fn edit_message( &self, to: Jid, original_id: String, new_content: Message, ) -> Result<String, Error>

Source

pub async fn send_node(&self, node: Node) -> Result<(), ClientError>

Source

pub async fn get_push_name(&self) -> String

Source

pub async fn get_pn(&self) -> Option<Jid>

Source

pub async fn get_lid(&self) -> Option<Jid>

Source§

impl Client

Source

pub async fn download(&self, downloadable: &dyn Downloadable) -> Result<Vec<u8>>

Source

pub async fn download_to_file<W: Write + Seek + Send + Unpin>( &self, downloadable: &dyn Downloadable, writer: W, ) -> Result<()>

Source§

impl Client

Source

pub async fn generate_message_id(&self) -> String

Generates a unique message ID that conforms to the WhatsApp protocol format.

This is an advanced function that allows library users to generate message IDs that are compatible with the WhatsApp protocol. The generated ID includes timestamp, user JID, and random components to ensure uniqueness.

§Advanced Use Case

This function is intended for advanced users who need to build custom protocol interactions or manage message IDs manually. Most users should use higher-level methods like send_message which handle ID generation automatically.

§Returns

A string containing the generated message ID in the format expected by WhatsApp.

Source

pub async fn send_iq(&self, query: InfoQuery<'_>) -> Result<Node, IqError>

Sends a custom IQ (Info/Query) stanza to the WhatsApp server.

This is an advanced function that allows library users to send custom IQ stanzas for protocol interactions that are not covered by higher-level methods. Common use cases include live location updates, custom presence management, or other advanced WhatsApp features.

§Advanced Use Case

This function bypasses some of the higher-level abstractions and safety checks provided by other client methods. Users should be familiar with the WhatsApp protocol and IQ stanza format before using this function.

§Arguments
  • query - The IQ query to send, containing the stanza type, namespace, content, and optional timeout
§Returns
  • Ok(Node) - The response node from the server
  • Err(IqError) - Various error conditions including timeout, connection issues, or server errors
§Example
use wacore::request::{InfoQuery, InfoQueryType};
use wacore_binary::builder::NodeBuilder;
use wacore_binary::node::NodeContent;
use wacore_binary::jid::Jid;

// This is a simplified example - real usage requires proper setup
let query_node = NodeBuilder::new("presence")
    .attr("type", "available")
    .build();

let server_jid = Jid::new("", "s.whatsapp.net");

let query = InfoQuery {
    query_type: InfoQueryType::Set,
    namespace: "presence",
    to: server_jid,
    target: None,
    content: Some(NodeContent::Nodes(vec![query_node])),
    id: None,
    timeout: None,
};

let response = client.send_iq(query).await?;
Source§

impl Client

Source

pub async fn send_message( &self, to: Jid, message: Message, ) -> Result<String, Error>

Source§

impl Client

Source

pub async fn upload( &self, data: Vec<u8>, media_type: MediaType, ) -> Result<UploadResponse>

Source§

impl Client

Source

pub async fn query_group_info(&self, jid: &Jid) -> Result<GroupInfo, Error>

Source§

impl Client

Source

pub async fn send_presence(&self, presence: Presence) -> Result<(), Error>

Trait Implementations§

Source§

impl SendContextResolver for Client

Source§

fn resolve_devices<'life0, 'life1, 'async_trait>( &'life0 self, jids: &'life1 [Jid], ) -> Pin<Box<dyn Future<Output = Result<Vec<Jid>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn fetch_prekeys<'life0, 'life1, 'async_trait>( &'life0 self, jids: &'life1 [Jid], ) -> Pin<Box<dyn Future<Output = Result<HashMap<Jid, PreKeyBundle>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn fetch_prekeys_for_identity_check<'life0, 'life1, 'async_trait>( &'life0 self, jids: &'life1 [Jid], ) -> Pin<Box<dyn Future<Output = Result<HashMap<Jid, PreKeyBundle>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source§

fn resolve_group_info<'life0, 'life1, 'async_trait>( &'life0 self, jid: &'life1 Jid, ) -> Pin<Box<dyn Future<Output = Result<GroupInfo, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more