Skip to main content

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; it is secret, mutable state, not an API access token.
6//!
7//! | Task | Start here |
8//! | --- | --- |
9//! | QR login | [`NativeClient::start_qr_login`], [`NativeClient::poll_login`], [`NativeClient::complete_login`] |
10//! | Receive a sync page | [`NativeClient::sync`], [`wire::decode_add_message`] |
11//! | Send text | [`NativeClient::send_text`], [`TextSendResult`] |
12//! | Contacts and rooms | [`NativeClient::lookup_contacts`], [`NativeClient::lookup_room`] |
13//! | Attachments | [`media`], [`media_send`], [`NativeClient::send_file`] |
14//! | Low-level encoding | [`wire`], [`protobuf`] |
15//!
16//! # Send one text message
17//!
18//! After an approved login, call the client method with the recipient's exact
19//! WeChat username. Persist the task ID, timestamp and intended operation in your
20//! application's recovery record before submission. A client ID is not a server
21//! guarantee against duplicate sends.
22//!
23//! ```no_run
24//! use wechat_protocol::{wire, AccountState, NativeClient, TextSendResult};
25//!
26//! fn send_once(
27//!     client: &NativeClient,
28//!     state: &mut AccountState,
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(state, recipient, text, created_at, client_id)
37//! }
38//! ```
39//!
40//! The source package includes runnable `qr_login`, `send_text` and `sync_once`
41//! examples. They keep credentials in memory and perform no profile writes.
42//!
43//! # Application responsibilities
44//!
45//! The crate implements supported wire operations, transport authentication and
46//! response decoding. The embedding application owns credential storage, send
47//! intents, uncertainty handling, sync recovery and official-profile writeback.
48//! An accepted receipt establishes server acceptance, not recipient playback or
49//! completed local history. An error after submission must not cause a blind resend.
50//!
51//! This library does not launch or load the official client. Peer responses pass
52//! pinned MMTLS signature and record authentication before business decode.
53//! Network methods block; async applications must use a blocking worker.
54pub mod business;
55
56pub mod calls;
57mod client;
58mod lan_login;
59pub use lan_login::login_lan_error_reason;
60pub mod contact_sync;
61pub mod crypto;
62pub mod file_upload;
63pub mod media;
64pub mod media_send;
65pub mod mmtls;
66mod notice;
67pub mod protobuf;
68pub mod push;
69pub mod quote_send;
70pub mod silk;
71pub mod wire;
72pub use client::*;
73
74pub const MAX_MESSAGE_BYTES: usize = 16 * 1024 * 1024;