1mod support;
3
4use anyhow::{ensure, Context};
5use wechat_protocol::wire;
6
7fn main() -> anyhow::Result<()> {
8 let args: Vec<_> = std::env::args().skip(1).collect();
9 if args.iter().any(|arg| arg == "--help") {
10 println!("send_text RECIPIENT TASK_ID TEXT\nUses a fresh test-account QR login and submits once.");
11 return Ok(());
12 }
13 ensure!(args.len() == 3, "Usage: send_text RECIPIENT TASK_ID TEXT");
14 let (recipient, task_id, text) = (&args[0], &args[1], &args[2]);
15 let client_id = wire::client_message_id(task_id.as_bytes());
16 ensure!(client_id != 0, "Choose another nonempty task ID");
17 wire::text_send_request(recipient, text, wire::unix_time()?, client_id)?;
20 let (client, mut state) = support::login()?;
21 let created_at = wire::unix_time()?;
22 let receipt = client
23 .send_text(&mut state, recipient, text, created_at, client_id)
24 .context(
25 "Send outcome may be uncertain. Investigate before submitting this operation again",
26 )?;
27 println!("{}", serde_json::to_string_pretty(&receipt)?);
28 ensure!(receipt.accepted, "The server rejected this text send");
29 ensure!(
30 receipt.returned_destination_matches && receipt.returned_client_id_matches,
31 "Receipt identity mismatch; investigate before submitting again"
32 );
33 Ok(())
34}