pub struct BeeperClient { /* private fields */ }Expand description
Main Beeper API client
Stores the bearer token and base URL for API requests. All requests to the API will include the token in the Authorization header.
Implementationsยง
Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub async fn list_chats(
&self,
cursor: Option<&str>,
direction: Option<&str>,
) -> Result<ListChatsOutput>
pub async fn list_chats( &self, cursor: Option<&str>, direction: Option<&str>, ) -> Result<ListChatsOutput>
Lists all chats sorted by last activity
Combines all accounts into a single paginated list.
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_chats");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats
25 println!("๐ Fetching chats from Beeper...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 // Extract chat names into a vector using the display_name method
29 let chat_names: Vec<String> = chats_response
30 .items
31 .iter()
32 .map(|chat| chat.display_name())
33 .collect();
34
35 // Display results
36 println!("โ
Successfully retrieved {} chats:", chat_names.len());
37 println!();
38
39 if chat_names.is_empty() {
40 println!("No chats found.");
41 } else {
42 for (index, name) in chat_names.iter().enumerate() {
43 println!(" {}. {}", index + 1, name);
44 }
45 }
46
47 println!();
48 println!("Chat names as array:");
49 println!("{:#?}", chat_names);
50
51 Ok(())
52}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 send_message");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first non-group chat
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Find the first single (non-group) chat
34 let single_chat = chats_response
35 .items
36 .iter()
37 .find(|chat| chat.chat_type == "single");
38
39 if let Some(chat) = single_chat {
40 let chat_id = &chat.id;
41 let chat_title = &chat.title;
42
43 println!("โ
Found {} chats", chats_response.items.len());
44 println!();
45 println!("๐ฌ Sending message to first single chat: '{}'", chat_title);
46 println!(" Chat ID: {}", chat_id);
47 println!();
48
49 // Create the message input
50 let message_input = SendMessageInput {
51 text: "Hello".to_string(),
52 reply_to_id: None,
53 };
54
55 // Send the message
56 let response = client.send_message(chat_id, message_input).await?;
57
58 println!("โ
Message sent successfully!");
59 println!();
60 println!("Message Details:");
61 println!(" Chat ID: {}", response.chat_id);
62 println!(" Pending Message ID: {}", response.pending_message_id);
63 println!();
64 println!("Full response (JSON):");
65 println!("{:#?}", response);
66 } else {
67 println!("โ No single (non-group) chats found!");
68 println!();
69 println!("Available chats:");
70 for (index, chat) in chats_response.items.iter().enumerate() {
71 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
72 }
73 }
74
75 Ok(())
76}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_messages");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first one
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Get the first chat
34 let first_chat = &chats_response.items[0];
35 let chat_id = &first_chat.id;
36 let chat_title = &first_chat.title;
37
38 println!("โ
Found {} chats", chats_response.items.len());
39 println!();
40 println!("๐ฌ Fetching messages from first chat: '{}'", chat_title);
41 println!(" Chat ID: {}", chat_id);
42 println!();
43
44 // Fetch messages from the first chat
45 let messages_response = client.list_messages(chat_id, None, None).await?;
46
47 println!("โ
Successfully retrieved {} messages:", messages_response.items.len());
48 println!();
49
50 if messages_response.items.is_empty() {
51 println!("No messages found in this chat.");
52 } else {
53 // Display messages with formatting
54 for (index, message) in messages_response.items.iter().enumerate() {
55 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
56 let text = message.text.as_deref().unwrap_or("[No text content]");
57 let timestamp = &message.timestamp;
58
59 // Show attachments count if any
60 let attachment_info = if let Some(attachments) = &message.attachments {
61 format!(" [+{} attachment(s)]", attachments.len())
62 } else {
63 String::new()
64 };
65
66 // Show reactions count if any
67 let reaction_info = if let Some(reactions) = &message.reactions {
68 format!(" [+{} reaction(s)]", reactions.len())
69 } else {
70 String::new()
71 };
72
73 // Show reply indicator if replying to another message
74 let reply_info = if message.reply_to_id.is_some() {
75 " [โฉ๏ธ Reply]".to_string()
76 } else {
77 String::new()
78 };
79
80 println!(" {}. [{}] {}: {}{}{}{}",
81 index + 1,
82 timestamp,
83 sender,
84 text,
85 attachment_info,
86 reaction_info,
87 reply_info
88 );
89 }
90 }
91
92 println!();
93 println!("Message details (JSON):");
94 println!("{:#?}", messages_response.items);
95
96 // Show pagination info if available
97 if messages_response.has_more {
98 println!();
99 println!("โน๏ธ More messages available. Use pagination to fetch older/newer messages.");
100 }
101
102 Ok(())
103}Sourcepub async fn get_chat(&self, chat_id: &str) -> Result<Chat>
pub async fn get_chat(&self, chat_id: &str) -> Result<Chat>
Retrieves details for a specific chat
Returns chat metadata, participants, and latest message
Sourcepub async fn create_chat(
&self,
input: CreateChatInput,
) -> Result<CreateChatOutput>
pub async fn create_chat( &self, input: CreateChatInput, ) -> Result<CreateChatOutput>
Creates a new chat
Creates a single or group chat on a specific account using participant IDs
Sourcepub async fn archive_chat(&self, chat_id: &str, archived: bool) -> Result<Chat>
pub async fn archive_chat(&self, chat_id: &str, archived: bool) -> Result<Chat>
Archives or unarchives a chat
Sourcepub async fn set_chat_reminder(
&self,
chat_id: &str,
timestamp: &str,
) -> Result<Chat>
pub async fn set_chat_reminder( &self, chat_id: &str, timestamp: &str, ) -> Result<Chat>
Sets a reminder for a chat
Sourcepub async fn clear_chat_reminder(&self, chat_id: &str) -> Result<Chat>
pub async fn clear_chat_reminder(&self, chat_id: &str) -> Result<Chat>
Clears a reminder from a chat
Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub async fn list_messages(
&self,
chat_id: &str,
cursor: Option<&str>,
direction: Option<&str>,
) -> Result<ListMessagesOutput>
pub async fn list_messages( &self, chat_id: &str, cursor: Option<&str>, direction: Option<&str>, ) -> Result<ListMessagesOutput>
Lists all messages in a chat
Paginated message list sorted by timestamp.
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_messages");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first one
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Get the first chat
34 let first_chat = &chats_response.items[0];
35 let chat_id = &first_chat.id;
36 let chat_title = &first_chat.title;
37
38 println!("โ
Found {} chats", chats_response.items.len());
39 println!();
40 println!("๐ฌ Fetching messages from first chat: '{}'", chat_title);
41 println!(" Chat ID: {}", chat_id);
42 println!();
43
44 // Fetch messages from the first chat
45 let messages_response = client.list_messages(chat_id, None, None).await?;
46
47 println!("โ
Successfully retrieved {} messages:", messages_response.items.len());
48 println!();
49
50 if messages_response.items.is_empty() {
51 println!("No messages found in this chat.");
52 } else {
53 // Display messages with formatting
54 for (index, message) in messages_response.items.iter().enumerate() {
55 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
56 let text = message.text.as_deref().unwrap_or("[No text content]");
57 let timestamp = &message.timestamp;
58
59 // Show attachments count if any
60 let attachment_info = if let Some(attachments) = &message.attachments {
61 format!(" [+{} attachment(s)]", attachments.len())
62 } else {
63 String::new()
64 };
65
66 // Show reactions count if any
67 let reaction_info = if let Some(reactions) = &message.reactions {
68 format!(" [+{} reaction(s)]", reactions.len())
69 } else {
70 String::new()
71 };
72
73 // Show reply indicator if replying to another message
74 let reply_info = if message.reply_to_id.is_some() {
75 " [โฉ๏ธ Reply]".to_string()
76 } else {
77 String::new()
78 };
79
80 println!(" {}. [{}] {}: {}{}{}{}",
81 index + 1,
82 timestamp,
83 sender,
84 text,
85 attachment_info,
86 reaction_info,
87 reply_info
88 );
89 }
90 }
91
92 println!();
93 println!("Message details (JSON):");
94 println!("{:#?}", messages_response.items);
95
96 // Show pagination info if available
97 if messages_response.has_more {
98 println!();
99 println!("โน๏ธ More messages available. Use pagination to fetch older/newer messages.");
100 }
101
102 Ok(())
103}Sourcepub async fn send_message(
&self,
chat_id: &str,
input: SendMessageInput,
) -> Result<SendMessageOutput>
pub async fn send_message( &self, chat_id: &str, input: SendMessageInput, ) -> Result<SendMessageOutput>
Sends a message to a chat
Sends a text message to a specific chat. Supports replying to existing messages. Returns the sent message ID.
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 send_message");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first non-group chat
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Find the first single (non-group) chat
34 let single_chat = chats_response
35 .items
36 .iter()
37 .find(|chat| chat.chat_type == "single");
38
39 if let Some(chat) = single_chat {
40 let chat_id = &chat.id;
41 let chat_title = &chat.title;
42
43 println!("โ
Found {} chats", chats_response.items.len());
44 println!();
45 println!("๐ฌ Sending message to first single chat: '{}'", chat_title);
46 println!(" Chat ID: {}", chat_id);
47 println!();
48
49 // Create the message input
50 let message_input = SendMessageInput {
51 text: "Hello".to_string(),
52 reply_to_id: None,
53 };
54
55 // Send the message
56 let response = client.send_message(chat_id, message_input).await?;
57
58 println!("โ
Message sent successfully!");
59 println!();
60 println!("Message Details:");
61 println!(" Chat ID: {}", response.chat_id);
62 println!(" Pending Message ID: {}", response.pending_message_id);
63 println!();
64 println!("Full response (JSON):");
65 println!("{:#?}", response);
66 } else {
67 println!("โ No single (non-group) chats found!");
68 println!();
69 println!("Available chats:");
70 for (index, chat) in chats_response.items.iter().enumerate() {
71 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
72 }
73 }
74
75 Ok(())
76}Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub async fn get_accounts(&self) -> Result<GetAccountsOutput>
pub async fn get_accounts(&self) -> Result<GetAccountsOutput>
Lists all connected messaging accounts
Lists chat accounts across networks (WhatsApp, Telegram, Twitter/X, etc.) actively connected to this Beeper Desktop instance
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_accounts");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all accounts
25 println!("๐ค Fetching connected accounts...");
26 let accounts = client.get_accounts().await?;
27
28 println!("โ
Successfully retrieved {} account(s):", accounts.len());
29 println!();
30
31 if accounts.is_empty() {
32 println!("No accounts connected.");
33 } else {
34 // Display accounts with formatting
35 for (index, account) in accounts.iter().enumerate() {
36 let account_id = &account.account_id;
37 let network = &account.network;
38 let user = &account.user;
39
40 // Build user identifier
41 let user_identifier = if let Some(full_name) = &user.full_name {
42 full_name.clone()
43 } else if let Some(username) = &user.username {
44 format!("@{}", username)
45 } else if let Some(phone) = &user.phone_number {
46 phone.clone()
47 } else {
48 user.id.clone()
49 };
50
51 println!(" {}. {} Account", index + 1, network);
52 println!(" โโ User: {}", user_identifier);
53 println!(" โโ Account ID: {}", account_id);
54 println!(" โโ User ID: {}", user.id);
55
56 // Show additional user info if available
57 if let Some(username) = &user.username {
58 println!(" โโ Username: @{}", username);
59 }
60 if let Some(phone) = &user.phone_number {
61 println!(" โโ Phone: {}", phone);
62 }
63 if let Some(email) = &user.email {
64 println!(" โโ Email: {}", email);
65 }
66 if let Some(cannot_message) = user.cannot_message {
67 if cannot_message {
68 println!(" โโ โ ๏ธ Cannot initiate messages to this user");
69 }
70 }
71
72 println!();
73 }
74 }
75
76 println!("Account details (JSON):");
77 println!("{:#?}", accounts);
78
79 Ok(())
80}Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub async fn search_messages(
&self,
query: &str,
cursor: Option<&str>,
direction: Option<&str>,
) -> Result<SearchMessagesOutput>
pub async fn search_messages( &self, query: &str, cursor: Option<&str>, direction: Option<&str>, ) -> Result<SearchMessagesOutput>
Searches messages across chats
Uses Beeperโs message index for full-text search.
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 search");
11 std::process::exit(1);
12 });
13
14 // Get search query from command line arguments or use default
15 let search_query = env::args()
16 .nth(1)
17 .unwrap_or_else(|| "hello".to_string());
18
19 // Get API base URL from environment variable or use default
20 let base_url = env::var("BEEPER_API_URL")
21 .unwrap_or_else(|_| "http://localhost:23373".to_string());
22
23 println!("Connecting to Beeper Desktop API at: {}", base_url);
24 println!("Searching for: \"{}\"", search_query);
25 println!();
26
27 // Create a client with the provided token
28 let client = BeeperClient::new(&token, &base_url);
29
30 // Search for chats
31 println!("๐ Searching chats...");
32 let chats_search = client.search_chats(&search_query, None, None).await?;
33
34 println!("โ
Found {} matching chat(s):", chats_search.items.len());
35 println!();
36
37 if chats_search.items.is_empty() {
38 println!("No chats found matching \"{}\"", search_query);
39 } else {
40 for (index, chat) in chats_search.items.iter().enumerate() {
41 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
42 println!(" โโ Network: {}", chat.network);
43 println!(" โโ Participants: {}", chat.participants.total);
44 println!(" โโ Unread: {}", chat.unread_count);
45 if let Some(last_activity) = &chat.last_activity {
46 println!(" โโ Last Activity: {}", last_activity);
47 }
48 println!();
49 }
50 }
51
52 // Search for messages
53 println!("๐จ Searching messages...");
54 let messages_search = client.search_messages(&search_query, None, None).await?;
55
56 println!("โ
Found {} matching message(s):", messages_search.items.len());
57 println!();
58
59 if messages_search.items.is_empty() {
60 println!("No messages found matching \"{}\"", search_query);
61 } else {
62 // Group messages by chat for better display
63 let mut chats_in_results = std::collections::HashMap::new();
64
65 for message in &messages_search.items {
66 chats_in_results
67 .entry(message.chat_id.clone())
68 .or_insert_with(Vec::new)
69 .push(message);
70 }
71
72 for (chat_id, messages) in &chats_in_results {
73 // Get chat title from search results if available
74 let chat_title = if let Some(chat) = messages_search.chats.as_ref()
75 .and_then(|chats| chats.get(chat_id))
76 {
77 chat.title.clone()
78 } else {
79 chat_id.clone()
80 };
81
82 println!(" Chat: {}", chat_title);
83 println!(" โโ {} message(s) found:", messages.len());
84
85 for (msg_index, message) in messages.iter().enumerate() {
86 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
87 let text = message.text.as_deref().unwrap_or("[No text content]");
88
89 // Truncate long messages
90 let display_text = if text.len() > 60 {
91 format!("{}...", &text[..60])
92 } else {
93 text.to_string()
94 };
95
96 println!(" {}. [{}] {}: {}",
97 msg_index + 1,
98 message.timestamp,
99 sender,
100 display_text
101 );
102 }
103 println!();
104 }
105 }
106
107 // Show pagination info if available
108 if messages_search.has_more {
109 println!("โน๏ธ More results available. Use pagination with:");
110 println!(" - oldestCursor: {:?}", messages_search.oldest_cursor);
111 println!(" - newestCursor: {:?}", messages_search.newest_cursor);
112 }
113
114 // Display search summary
115 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
116 println!("๐ Search Summary for \"{}\":", search_query);
117 println!(" โข Chats: {}", chats_search.items.len());
118 println!(" โข Messages: {}", messages_search.items.len());
119 println!(" โข Total Results: {}", chats_search.items.len() + messages_search.items.len());
120 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
121
122 Ok(())
123}Sourcepub async fn search_chats(
&self,
query: &str,
cursor: Option<&str>,
direction: Option<&str>,
) -> Result<SearchChatsOutput>
pub async fn search_chats( &self, query: &str, cursor: Option<&str>, direction: Option<&str>, ) -> Result<SearchChatsOutput>
Searches chats by title, network, or participants
Uses Beeper Desktopโs renderer algorithm.
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 search");
11 std::process::exit(1);
12 });
13
14 // Get search query from command line arguments or use default
15 let search_query = env::args()
16 .nth(1)
17 .unwrap_or_else(|| "hello".to_string());
18
19 // Get API base URL from environment variable or use default
20 let base_url = env::var("BEEPER_API_URL")
21 .unwrap_or_else(|_| "http://localhost:23373".to_string());
22
23 println!("Connecting to Beeper Desktop API at: {}", base_url);
24 println!("Searching for: \"{}\"", search_query);
25 println!();
26
27 // Create a client with the provided token
28 let client = BeeperClient::new(&token, &base_url);
29
30 // Search for chats
31 println!("๐ Searching chats...");
32 let chats_search = client.search_chats(&search_query, None, None).await?;
33
34 println!("โ
Found {} matching chat(s):", chats_search.items.len());
35 println!();
36
37 if chats_search.items.is_empty() {
38 println!("No chats found matching \"{}\"", search_query);
39 } else {
40 for (index, chat) in chats_search.items.iter().enumerate() {
41 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
42 println!(" โโ Network: {}", chat.network);
43 println!(" โโ Participants: {}", chat.participants.total);
44 println!(" โโ Unread: {}", chat.unread_count);
45 if let Some(last_activity) = &chat.last_activity {
46 println!(" โโ Last Activity: {}", last_activity);
47 }
48 println!();
49 }
50 }
51
52 // Search for messages
53 println!("๐จ Searching messages...");
54 let messages_search = client.search_messages(&search_query, None, None).await?;
55
56 println!("โ
Found {} matching message(s):", messages_search.items.len());
57 println!();
58
59 if messages_search.items.is_empty() {
60 println!("No messages found matching \"{}\"", search_query);
61 } else {
62 // Group messages by chat for better display
63 let mut chats_in_results = std::collections::HashMap::new();
64
65 for message in &messages_search.items {
66 chats_in_results
67 .entry(message.chat_id.clone())
68 .or_insert_with(Vec::new)
69 .push(message);
70 }
71
72 for (chat_id, messages) in &chats_in_results {
73 // Get chat title from search results if available
74 let chat_title = if let Some(chat) = messages_search.chats.as_ref()
75 .and_then(|chats| chats.get(chat_id))
76 {
77 chat.title.clone()
78 } else {
79 chat_id.clone()
80 };
81
82 println!(" Chat: {}", chat_title);
83 println!(" โโ {} message(s) found:", messages.len());
84
85 for (msg_index, message) in messages.iter().enumerate() {
86 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
87 let text = message.text.as_deref().unwrap_or("[No text content]");
88
89 // Truncate long messages
90 let display_text = if text.len() > 60 {
91 format!("{}...", &text[..60])
92 } else {
93 text.to_string()
94 };
95
96 println!(" {}. [{}] {}: {}",
97 msg_index + 1,
98 message.timestamp,
99 sender,
100 display_text
101 );
102 }
103 println!();
104 }
105 }
106
107 // Show pagination info if available
108 if messages_search.has_more {
109 println!("โน๏ธ More results available. Use pagination with:");
110 println!(" - oldestCursor: {:?}", messages_search.oldest_cursor);
111 println!(" - newestCursor: {:?}", messages_search.newest_cursor);
112 }
113
114 // Display search summary
115 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
116 println!("๐ Search Summary for \"{}\":", search_query);
117 println!(" โข Chats: {}", chats_search.items.len());
118 println!(" โข Messages: {}", messages_search.items.len());
119 println!(" โข Total Results: {}", chats_search.items.len() + messages_search.items.len());
120 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
121
122 Ok(())
123}Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub async fn focus_app(
&self,
input: Option<FocusAppInput>,
) -> Result<FocusAppOutput>
pub async fn focus_app( &self, input: Option<FocusAppInput>, ) -> Result<FocusAppOutput>
Focuses Beeper Desktop and optionally navigates to a specific location
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Get optional arguments
25 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 // Create focus input based on arguments
31 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 // Determine what we're doing
42 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 // Focus the app
60 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}Sourcepub async fn download_asset(&self, url: &str) -> Result<DownloadAssetOutput>
pub async fn download_asset(&self, url: &str) -> Result<DownloadAssetOutput>
Downloads an asset from a URL
Downloads a Matrix asset using its mxc:// or localmxc:// URL to the device running Beeper Desktop and returns the local file URL.
Sourceยงimpl BeeperClient
impl BeeperClient
Sourcepub fn new(token: impl Into<String>, base_url: impl Into<String>) -> Self
pub fn new(token: impl Into<String>, base_url: impl Into<String>) -> Self
Creates a new Beeper API client
ยงArguments
token- Bearer token for authenticationbase_url- Base URL of the Beeper Desktop API server
Examples found in repository?
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_chats");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats
25 println!("๐ Fetching chats from Beeper...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 // Extract chat names into a vector using the display_name method
29 let chat_names: Vec<String> = chats_response
30 .items
31 .iter()
32 .map(|chat| chat.display_name())
33 .collect();
34
35 // Display results
36 println!("โ
Successfully retrieved {} chats:", chat_names.len());
37 println!();
38
39 if chat_names.is_empty() {
40 println!("No chats found.");
41 } else {
42 for (index, name) in chat_names.iter().enumerate() {
43 println!(" {}. {}", index + 1, name);
44 }
45 }
46
47 println!();
48 println!("Chat names as array:");
49 println!("{:#?}", chat_names);
50
51 Ok(())
52}More examples
5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 send_message");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first non-group chat
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Find the first single (non-group) chat
34 let single_chat = chats_response
35 .items
36 .iter()
37 .find(|chat| chat.chat_type == "single");
38
39 if let Some(chat) = single_chat {
40 let chat_id = &chat.id;
41 let chat_title = &chat.title;
42
43 println!("โ
Found {} chats", chats_response.items.len());
44 println!();
45 println!("๐ฌ Sending message to first single chat: '{}'", chat_title);
46 println!(" Chat ID: {}", chat_id);
47 println!();
48
49 // Create the message input
50 let message_input = SendMessageInput {
51 text: "Hello".to_string(),
52 reply_to_id: None,
53 };
54
55 // Send the message
56 let response = client.send_message(chat_id, message_input).await?;
57
58 println!("โ
Message sent successfully!");
59 println!();
60 println!("Message Details:");
61 println!(" Chat ID: {}", response.chat_id);
62 println!(" Pending Message ID: {}", response.pending_message_id);
63 println!();
64 println!("Full response (JSON):");
65 println!("{:#?}", response);
66 } else {
67 println!("โ No single (non-group) chats found!");
68 println!();
69 println!("Available chats:");
70 for (index, chat) in chats_response.items.iter().enumerate() {
71 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
72 }
73 }
74
75 Ok(())
76}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_accounts");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all accounts
25 println!("๐ค Fetching connected accounts...");
26 let accounts = client.get_accounts().await?;
27
28 println!("โ
Successfully retrieved {} account(s):", accounts.len());
29 println!();
30
31 if accounts.is_empty() {
32 println!("No accounts connected.");
33 } else {
34 // Display accounts with formatting
35 for (index, account) in accounts.iter().enumerate() {
36 let account_id = &account.account_id;
37 let network = &account.network;
38 let user = &account.user;
39
40 // Build user identifier
41 let user_identifier = if let Some(full_name) = &user.full_name {
42 full_name.clone()
43 } else if let Some(username) = &user.username {
44 format!("@{}", username)
45 } else if let Some(phone) = &user.phone_number {
46 phone.clone()
47 } else {
48 user.id.clone()
49 };
50
51 println!(" {}. {} Account", index + 1, network);
52 println!(" โโ User: {}", user_identifier);
53 println!(" โโ Account ID: {}", account_id);
54 println!(" โโ User ID: {}", user.id);
55
56 // Show additional user info if available
57 if let Some(username) = &user.username {
58 println!(" โโ Username: @{}", username);
59 }
60 if let Some(phone) = &user.phone_number {
61 println!(" โโ Phone: {}", phone);
62 }
63 if let Some(email) = &user.email {
64 println!(" โโ Email: {}", email);
65 }
66 if let Some(cannot_message) = user.cannot_message {
67 if cannot_message {
68 println!(" โโ โ ๏ธ Cannot initiate messages to this user");
69 }
70 }
71
72 println!();
73 }
74 }
75
76 println!("Account details (JSON):");
77 println!("{:#?}", accounts);
78
79 Ok(())
80}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Get optional arguments
25 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 // Create focus input based on arguments
31 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 // Determine what we're doing
42 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 // Focus the app
60 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}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 fetch_messages");
11 std::process::exit(1);
12 });
13
14 // Get API base URL from environment variable or use default
15 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 // Create a client with the provided token
22 let client = BeeperClient::new(&token, &base_url);
23
24 // Fetch all chats to find the first one
25 println!("๐ Fetching chats...");
26 let chats_response = client.list_chats(None, None).await?;
27
28 if chats_response.items.is_empty() {
29 println!("โ No chats found!");
30 return Ok(());
31 }
32
33 // Get the first chat
34 let first_chat = &chats_response.items[0];
35 let chat_id = &first_chat.id;
36 let chat_title = &first_chat.title;
37
38 println!("โ
Found {} chats", chats_response.items.len());
39 println!();
40 println!("๐ฌ Fetching messages from first chat: '{}'", chat_title);
41 println!(" Chat ID: {}", chat_id);
42 println!();
43
44 // Fetch messages from the first chat
45 let messages_response = client.list_messages(chat_id, None, None).await?;
46
47 println!("โ
Successfully retrieved {} messages:", messages_response.items.len());
48 println!();
49
50 if messages_response.items.is_empty() {
51 println!("No messages found in this chat.");
52 } else {
53 // Display messages with formatting
54 for (index, message) in messages_response.items.iter().enumerate() {
55 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
56 let text = message.text.as_deref().unwrap_or("[No text content]");
57 let timestamp = &message.timestamp;
58
59 // Show attachments count if any
60 let attachment_info = if let Some(attachments) = &message.attachments {
61 format!(" [+{} attachment(s)]", attachments.len())
62 } else {
63 String::new()
64 };
65
66 // Show reactions count if any
67 let reaction_info = if let Some(reactions) = &message.reactions {
68 format!(" [+{} reaction(s)]", reactions.len())
69 } else {
70 String::new()
71 };
72
73 // Show reply indicator if replying to another message
74 let reply_info = if message.reply_to_id.is_some() {
75 " [โฉ๏ธ Reply]".to_string()
76 } else {
77 String::new()
78 };
79
80 println!(" {}. [{}] {}: {}{}{}{}",
81 index + 1,
82 timestamp,
83 sender,
84 text,
85 attachment_info,
86 reaction_info,
87 reply_info
88 );
89 }
90 }
91
92 println!();
93 println!("Message details (JSON):");
94 println!("{:#?}", messages_response.items);
95
96 // Show pagination info if available
97 if messages_response.has_more {
98 println!();
99 println!("โน๏ธ More messages available. Use pagination to fetch older/newer messages.");
100 }
101
102 Ok(())
103}5async fn main() -> Result<(), Box<dyn std::error::Error>> {
6 // Get authentication token from environment variable
7 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 search");
11 std::process::exit(1);
12 });
13
14 // Get search query from command line arguments or use default
15 let search_query = env::args()
16 .nth(1)
17 .unwrap_or_else(|| "hello".to_string());
18
19 // Get API base URL from environment variable or use default
20 let base_url = env::var("BEEPER_API_URL")
21 .unwrap_or_else(|_| "http://localhost:23373".to_string());
22
23 println!("Connecting to Beeper Desktop API at: {}", base_url);
24 println!("Searching for: \"{}\"", search_query);
25 println!();
26
27 // Create a client with the provided token
28 let client = BeeperClient::new(&token, &base_url);
29
30 // Search for chats
31 println!("๐ Searching chats...");
32 let chats_search = client.search_chats(&search_query, None, None).await?;
33
34 println!("โ
Found {} matching chat(s):", chats_search.items.len());
35 println!();
36
37 if chats_search.items.is_empty() {
38 println!("No chats found matching \"{}\"", search_query);
39 } else {
40 for (index, chat) in chats_search.items.iter().enumerate() {
41 println!(" {}. {} ({})", index + 1, chat.title, chat.chat_type);
42 println!(" โโ Network: {}", chat.network);
43 println!(" โโ Participants: {}", chat.participants.total);
44 println!(" โโ Unread: {}", chat.unread_count);
45 if let Some(last_activity) = &chat.last_activity {
46 println!(" โโ Last Activity: {}", last_activity);
47 }
48 println!();
49 }
50 }
51
52 // Search for messages
53 println!("๐จ Searching messages...");
54 let messages_search = client.search_messages(&search_query, None, None).await?;
55
56 println!("โ
Found {} matching message(s):", messages_search.items.len());
57 println!();
58
59 if messages_search.items.is_empty() {
60 println!("No messages found matching \"{}\"", search_query);
61 } else {
62 // Group messages by chat for better display
63 let mut chats_in_results = std::collections::HashMap::new();
64
65 for message in &messages_search.items {
66 chats_in_results
67 .entry(message.chat_id.clone())
68 .or_insert_with(Vec::new)
69 .push(message);
70 }
71
72 for (chat_id, messages) in &chats_in_results {
73 // Get chat title from search results if available
74 let chat_title = if let Some(chat) = messages_search.chats.as_ref()
75 .and_then(|chats| chats.get(chat_id))
76 {
77 chat.title.clone()
78 } else {
79 chat_id.clone()
80 };
81
82 println!(" Chat: {}", chat_title);
83 println!(" โโ {} message(s) found:", messages.len());
84
85 for (msg_index, message) in messages.iter().enumerate() {
86 let sender = message.sender_name.as_deref().unwrap_or("Unknown");
87 let text = message.text.as_deref().unwrap_or("[No text content]");
88
89 // Truncate long messages
90 let display_text = if text.len() > 60 {
91 format!("{}...", &text[..60])
92 } else {
93 text.to_string()
94 };
95
96 println!(" {}. [{}] {}: {}",
97 msg_index + 1,
98 message.timestamp,
99 sender,
100 display_text
101 );
102 }
103 println!();
104 }
105 }
106
107 // Show pagination info if available
108 if messages_search.has_more {
109 println!("โน๏ธ More results available. Use pagination with:");
110 println!(" - oldestCursor: {:?}", messages_search.oldest_cursor);
111 println!(" - newestCursor: {:?}", messages_search.newest_cursor);
112 }
113
114 // Display search summary
115 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
116 println!("๐ Search Summary for \"{}\":", search_query);
117 println!(" โข Chats: {}", chats_search.items.len());
118 println!(" โข Messages: {}", messages_search.items.len());
119 println!(" โข Total Results: {}", chats_search.items.len() + messages_search.items.len());
120 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
121
122 Ok(())
123}Sourcepub fn with_token(token: impl Into<String>) -> Self
pub fn with_token(token: impl Into<String>) -> Self
Creates a new Beeper API client with default base URL
ยงArguments
token- Bearer token for authentication
Sourcepub fn set_base_url(&mut self, base_url: impl Into<String>)
pub fn set_base_url(&mut self, base_url: impl Into<String>)
Updates the base URL
Trait Implementationsยง
Sourceยงimpl Clone for BeeperClient
impl Clone for BeeperClient
Sourceยงfn clone(&self) -> BeeperClient
fn clone(&self) -> BeeperClient
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more