Skip to main content

highlevel_api/apis/conversations/
client.rs

1use std::sync::Arc;
2use crate::{error::Result, http::HttpClient};
3use super::types::*;
4
5pub struct ConversationsApi {
6    http: Arc<HttpClient>,
7}
8
9impl ConversationsApi {
10    pub fn new(http: Arc<HttpClient>) -> Self {
11        Self { http }
12    }
13
14    pub async fn search(
15        &self,
16        params: &SearchConversationsParams,
17    ) -> Result<SearchConversationsResponse> {
18        self.http.get_with_query("/conversations/search", params).await
19    }
20
21    pub async fn get(&self, conversation_id: &str) -> Result<GetConversationResponse> {
22        self.http.get(&format!("/conversations/{conversation_id}")).await
23    }
24
25    pub async fn create(
26        &self,
27        params: &CreateConversationParams,
28    ) -> Result<GetConversationResponse> {
29        self.http.post("/conversations", params).await
30    }
31
32    pub async fn update(
33        &self,
34        conversation_id: &str,
35        params: &UpdateConversationParams,
36    ) -> Result<GetConversationResponse> {
37        self.http.put(&format!("/conversations/{conversation_id}"), params).await
38    }
39
40    pub async fn delete(&self, conversation_id: &str) -> Result<DeleteConversationResponse> {
41        self.http.delete(&format!("/conversations/{conversation_id}")).await
42    }
43
44    pub async fn get_messages(&self, conversation_id: &str) -> Result<GetMessagesResponse> {
45        self.http
46            .get(&format!("/conversations/{conversation_id}/messages"))
47            .await
48    }
49
50    pub async fn send_message(&self, params: &SendMessageParams) -> Result<SendMessageResponse> {
51        self.http.post("/conversations/messages", params).await
52    }
53
54    pub async fn add_inbound_message(
55        &self,
56        params: &SendMessageParams,
57    ) -> Result<SendMessageResponse> {
58        self.http.post("/conversations/messages/inbound", params).await
59    }
60}