use std::borrow::Cow; use docopt::Docopt; use threema_gateway::{ApiBuilder, Recipient}; const USAGE: &str = " Usage: send_simple [options] id ... send_simple [options] email ... send_simple [options] phone ... Options: -h, --help Show this help "; #[tokio::main(flavor = "current_thread")] async fn main() { let args = Docopt::new(USAGE) .and_then(|docopt| docopt.parse()) .unwrap_or_else(|e| e.exit()); // Command line arguments let from = args.get_str(""); let secret = args.get_str(""); let text = args.get_vec("").join(" "); // Determine recipient let recipient = if args.get_bool("id") { Recipient::Id(Cow::from(args.get_str(""))) } else if args.get_bool("email") { Recipient::Email(Cow::from(args.get_str(""))) } else if args.get_bool("phone") { Recipient::Phone(Cow::from(args.get_str(""))) } else { unreachable!(); }; // Send let api = ApiBuilder::new(from, secret).into_simple(); let msg_id = api.send(&recipient, &text).await; match msg_id { Ok(id) => println!("Sent. Message id is {}.", id), Err(e) => println!("Could not send message: {}", e), } }