Skip to main content

text_send_request

Function text_send_request 

Source
pub fn text_send_request(
    destination: &str,
    content: &str,
    created_at: u32,
    client_id: u32,
) -> Result<Vec<u8>>
Examples found in repository?
examples/send_text.rs (line 20)
8async fn main() -> anyhow::Result<()> {
9    let args: Vec<_> = std::env::args().skip(1).collect();
10    if args.iter().any(|arg| arg == "--help") {
11        println!("send_text RECIPIENT TASK_ID TEXT\nUses a fresh test-account QR login and submits once.");
12        return Ok(());
13    }
14    ensure!(args.len() == 3, "Usage: send_text RECIPIENT TASK_ID TEXT");
15    let (recipient, task_id, text) = (&args[0], &args[1], &args[2]);
16    let client_id = wire::client_message_id(task_id.as_bytes());
17    ensure!(client_id != 0, "Choose another nonempty task ID");
18    // Validate arguments before requesting any login. A real application records
19    // this operation and timestamp before submitting it, and retains its result.
20    wire::text_send_request(recipient, text, wire::unix_time()?, client_id)?;
21    let client = tokio::task::spawn_blocking(support::login).await??;
22    let created_at = wire::unix_time()?;
23    let receipt = client
24        .send_text(
25            recipient,
26            text,
27            TextSendOptions {
28                created_at,
29                client_message_id: client_id,
30                source: None,
31            },
32        )
33        .await
34        .context(
35            "Send outcome may be uncertain. Investigate before submitting this operation again",
36        )?;
37    println!("{}", serde_json::to_string_pretty(&receipt)?);
38    ensure!(receipt.accepted, "The server rejected this text send");
39    ensure!(
40        receipt.returned_destination_matches && receipt.returned_client_id_matches,
41        "Receipt identity mismatch; investigate before submitting again"
42    );
43    client.shutdown().await?;
44    Ok(())
45}