1use beeper_desktop_api::{BeeperClient, FocusAppInput};
2use std::env;
3
4#[tokio::main]
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 let token = env::var("BEEPER_TOKEN")
8 .unwrap_or_else(|_| {
9 eprintln!("Error: BEEPER_TOKEN environment variable not set");
10 eprintln!("Usage: BEEPER_TOKEN=your_token cargo run --example focus_app [chat_id] [message_id] [draft_text]");
11 std::process::exit(1);
12 });
13
14 let base_url = env::var("BEEPER_API_URL")
16 .unwrap_or_else(|_| "http://localhost:23373".to_string());
17
18 println!("Connecting to Beeper Desktop API at: {}", base_url);
19 println!();
20
21 let client = BeeperClient::new(&token, &base_url);
23
24 let args: Vec<String> = env::args().collect();
26 let chat_id = args.get(1).cloned();
27 let message_id = args.get(2).cloned();
28 let draft_text = args.get(3).cloned();
29
30 let focus_input = if chat_id.is_some() || message_id.is_some() || draft_text.is_some() {
32 Some(FocusAppInput {
33 chat_id: chat_id.clone(),
34 message_id: message_id.clone(),
35 draft: draft_text.clone(),
36 })
37 } else {
38 None
39 };
40
41 if let Some(ref input) = focus_input {
43 println!("🔍 Focusing Beeper with parameters:");
44 if let Some(ref cid) = input.chat_id {
45 println!(" Chat ID: {}", cid);
46 }
47 if let Some(ref mid) = input.message_id {
48 println!(" Message ID: {}", mid);
49 }
50 if let Some(ref draft) = input.draft {
51 println!(" Draft: {}", draft);
52 }
53 println!();
54 } else {
55 println!("🎯 Focusing Beeper Desktop (no parameters)");
56 println!();
57 }
58
59 match client.focus_app(focus_input).await {
61 Ok(response) => {
62 if response.success {
63 println!("✅ Successfully focused Beeper Desktop!");
64 println!();
65 if draft_text.is_some() {
66 println!("💬 Draft text has been pre-filled in the chat");
67 }
68 if chat_id.is_some() {
69 println!("📍 Navigated to the specified chat");
70 }
71 if message_id.is_some() {
72 println!("💭 Navigated to the specified message");
73 }
74 } else {
75 println!("⚠️ Focus operation completed but returned success: false");
76 }
77 println!();
78 println!("Response:");
79 println!("{:#?}", response);
80 }
81 Err(e) => {
82 eprintln!("Error: {}", e);
83 std::process::exit(1);
84 }
85 }
86
87 Ok(())
88}