beeper_desktop_api/client/
messages.rs1use crate::models::{ListMessagesOutput, SendMessageInput, SendMessageOutput};
4use crate::error::Result;
5use super::{BeeperClient, handle_response};
6
7impl BeeperClient {
8 pub async fn list_messages(
12 &self,
13 chat_id: &str,
14 cursor: Option<&str>,
15 direction: Option<&str>,
16 ) -> Result<ListMessagesOutput> {
17 let mut url = format!(
18 "{}/v1/chats/{}/messages",
19 self.get_base_url(),
20 urlencoding::encode(chat_id)
21 );
22
23 if let Some(c) = cursor {
24 url.push_str(&format!("?cursor={}", urlencoding::encode(c)));
25 if direction.is_some() {
26 url.push('&');
27 }
28 } else if direction.is_some() {
29 url.push('?');
30 }
31
32 if let Some(d) = direction {
33 url.push_str(&format!("direction={}", d));
34 }
35
36 let response = self
37 .get_http_client()
38 .get(&url)
39 .header("Authorization", self.get_auth_header())
40 .send()
41 .await?;
42
43 handle_response(response).await
44 }
45
46 pub async fn send_message(&self, chat_id: &str, input: SendMessageInput) -> Result<SendMessageOutput> {
51 let url = format!(
52 "{}/v1/chats/{}/messages",
53 self.get_base_url(),
54 urlencoding::encode(chat_id)
55 );
56
57 let response = self
58 .get_http_client()
59 .post(&url)
60 .header("Authorization", self.get_auth_header())
61 .json(&input)
62 .send()
63 .await?;
64
65 handle_response(response).await
66 }
67}