A better Rust ATProto crate
at main 1.5 kB view raw
1use clap::Parser; 2use jacquard::CowStr; 3use jacquard::api::app_bsky::feed::post::Post; 4use jacquard::client::{Agent, AgentSessionExt, FileAuthStore}; 5use jacquard::oauth::client::OAuthClient; 6use jacquard::oauth::loopback::LoopbackConfig; 7use jacquard::types::string::Datetime; 8 9#[derive(Parser, Debug)] 10#[command(author, version, about = "Create a simple post")] 11struct Args { 12 /// Handle (e.g., alice.bsky.social), DID, or PDS URL 13 input: CowStr<'static>, 14 15 /// Post text 16 #[arg(short, long)] 17 text: String, 18 19 /// Path to auth store file (will be created if missing) 20 #[arg(long, default_value = "/tmp/jacquard-oauth-session.json")] 21 store: String, 22} 23 24#[tokio::main] 25async fn main() -> miette::Result<()> { 26 let args = Args::parse(); 27 28 let oauth = OAuthClient::with_default_config(FileAuthStore::new(&args.store)); 29 let session = oauth 30 .login_with_local_server(args.input, Default::default(), LoopbackConfig::default()) 31 .await?; 32 33 let agent: Agent<_> = Agent::from(session); 34 35 // Create a simple text post using the Agent convenience method 36 let post = Post { 37 text: CowStr::from(args.text), 38 created_at: Datetime::now(), 39 embed: None, 40 entities: None, 41 facets: None, 42 labels: None, 43 langs: None, 44 reply: None, 45 tags: None, 46 extra_data: Default::default(), 47 }; 48 49 let output = agent.create_record(post, None).await?; 50 println!("✓ Created post: {}", output.uri); 51 52 Ok(()) 53}