wechat_protocol/lib.rs
1//! Connect to WeChat, authenticate, synchronize and submit messages with [`NativeClient`].
2//!
3//! Most server operations are **methods on [`NativeClient`]**, rather than free
4//! functions in this crate's Functions list. [`AccountState`] holds accepted
5//! credentials; transfer it once into [`NativeClient::from_account`]. Account
6//! operations then share that owner. It is secret data, not an API access token.
7//!
8//! | Task | Start here |
9//! | --- | --- |
10//! | QR login | [`NativeClient::start_qr_login`], [`NativeClient::poll_login`], [`NativeClient::complete_login`] |
11//! | Receive a sync page | [`NativeClient::sync`], [`wire::decode_add_message`] |
12//! | Send text | [`NativeClient::send_text`], [`TextSendResult`] |
13//! | Contacts and rooms | [`NativeClient::lookup_contacts`], [`NativeClient::lookup_room`] |
14//! | Attachments | [`media`], [`media_send`], [`NativeClient::send_file`] |
15//! | Low-level encoding | [`wire`], [`protobuf`] |
16//!
17//! # Send one text message
18//!
19//! After an approved login, call the client method with the recipient's exact
20//! WeChat username. Persist the task ID, timestamp and intended operation in your
21//! application's recovery record before submission. A client ID is not a server
22//! guarantee against duplicate sends.
23//!
24//! ```no_run
25//! use wechat_protocol::{wire, NativeClient, TextSendOptions, TextSendResult};
26//!
27//! async fn send_once(
28//! client: &NativeClient,
29//! recipient: &str,
30//! text: &str,
31//! task_id: &str,
32//! created_at: u32,
33//! ) -> anyhow::Result<TextSendResult> {
34//! let client_id = wire::client_message_id(task_id.as_bytes());
35//! anyhow::ensure!(client_id != 0, "Choose another task ID");
36//! client.send_text(recipient, text, TextSendOptions {
37//! created_at,
38//! client_message_id: client_id,
39//! source: None,
40//! }).await
41//! }
42//! ```
43//!
44//! The source package includes runnable `qr_login`, `send_text` and `sync_once`
45//! examples. They keep credentials in memory and perform no profile writes.
46//!
47//! # Application responsibilities
48//!
49//! The crate implements supported wire operations, transport authentication and
50//! response decoding. The embedding application owns credential storage, send
51//! intents, uncertainty handling, sync recovery and official-profile writeback.
52//! An accepted receipt establishes server acceptance, not recipient playback or
53//! completed local history. An error after submission must not cause a blind resend.
54//!
55//! This library does not launch or load the official client. Peer responses pass
56//! pinned MMTLS signature and record authentication before business decode.
57//! Account-owned requests run blocking transport work on Tokio's blocking pool.
58//! Login bootstrap and remaining low-level operations
59//! are blocking and require a blocking worker in async applications.
60pub mod business;
61
62pub mod calls;
63mod client;
64mod lan_login;
65pub use lan_login::login_lan_error_reason;
66pub mod contact_sync;
67pub mod crypto;
68pub mod file_upload;
69pub mod media;
70pub mod media_send;
71pub mod mmtls;
72mod notice;
73pub mod protobuf;
74pub mod push;
75pub mod quote_send;
76pub mod silk;
77pub mod wire;
78pub use client::*;
79
80pub const MAX_MESSAGE_BYTES: usize = 16 * 1024 * 1024;