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
impl Client
pub async fn new( persistence_manager: Arc<PersistenceManager>, ) -> (Arc<Self>, Receiver<MajorSyncTask>)
pub async fn run(self: &Arc<Self>)
pub async fn connect(self: &Arc<Self>) -> Result<(), Error>
pub async fn disconnect(&self)
pub async fn set_passive(&self, passive: bool) -> Result<(), IqError>
pub fn is_connected(&self) -> bool
pub fn is_logged_in(&self) -> bool
Sourcepub fn persistence_manager(&self) -> Arc<PersistenceManager>
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.
pub async fn edit_message( &self, to: Jid, original_id: String, new_content: Message, ) -> Result<String, Error>
pub async fn send_node(&self, node: Node) -> Result<(), ClientError>
pub async fn get_push_name(&self) -> String
pub async fn get_pn(&self) -> Option<Jid>
pub async fn get_lid(&self) -> Option<Jid>
Source§impl Client
impl Client
pub async fn download(&self, downloadable: &dyn Downloadable) -> Result<Vec<u8>>
pub async fn download_to_file<W: Write + Seek + Send + Unpin>( &self, downloadable: &dyn Downloadable, writer: W, ) -> Result<()>
Source§impl Client
impl Client
Sourcepub async fn generate_message_id(&self) -> String
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.
Sourcepub async fn send_iq(&self, query: InfoQuery<'_>) -> Result<Node, IqError>
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 serverErr(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?;Trait Implementations§
Source§impl SendContextResolver for Client
impl SendContextResolver for Client
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,
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,
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,
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
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
&self to an expression for Diesel’s query builder. Read more