ghl-sdk 0.5.1

Unofficial async Rust SDK for the GoHighLevel (HighLevel) API 2.0 — OAuth 2.0, Private Integration Tokens, rate-limit-aware retries, paginated streams
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
// @generated by xtask/generate_services.py — do not edit by hand.
//! `conversation-ai` — typed methods for all 12 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::conversation_ai`](crate::Ghl::conversation_ai).
//!
//! Request and response types come from [`ghl_models::v2::conversation_ai`](https://docs.rs/ghl-models/latest/ghl_models/v2/conversation_ai/); every endpoint is also documented in the
//! [`conversation-ai` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/conversation-ai.md).
//!
//! Enable with `features = ["conversation-ai"]`.

#![allow(clippy::too_many_arguments)]

use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::conversation_ai as models;

/// Typed access to the `conversation-ai` API v2 surface (12 operations). Obtained via
/// [`Ghl::conversation_ai`](crate::Ghl::conversation_ai).
#[derive(Debug, Clone)]
pub struct ConversationAiService {
    pub(crate) client: Ghl,
}

impl ConversationAiService {
    pub(crate) fn new(client: Ghl) -> Self {
        Self { client }
    }
}

/// Query parameters for [`ConversationAiService::search_agents`].
#[derive(Debug, Clone, Default)]
pub struct SearchAgentsParams {
    /// Start after is the agent id to start after, Serving as skip, send empty when first
    /// page
    pub start_after: Option<String>,
    /// Records per page
    pub limit: Option<f64>,
    /// query to search on agent name, must be provided in lowercase
    pub query: Option<String>,
}

impl SearchAgentsParams {
    /// Start from the parameters the API requires.
    pub fn new() -> Self {
        Self {
            ..Default::default()
        }
    }

    /// Start after is the agent id to start after, Serving as skip, send empty when first
    /// page
    pub fn start_after(mut self, v: impl Into<String>) -> Self {
        self.start_after = Some(v.into());
        self
    }

    /// Records per page
    pub fn limit(mut self, v: f64) -> Self {
        self.limit = Some(v);
        self
    }

    /// query to search on agent name, must be provided in lowercase
    pub fn query(mut self, v: impl Into<String>) -> Self {
        self.query = Some(v.into());
        self
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let mut q: Vec<(String, String)> = Vec::new();
        if let Some(v) = &self.start_after {
            q.push(("startAfter".into(), v.to_string()));
        }
        if let Some(v) = &self.limit {
            q.push(("limit".into(), v.to_string()));
        }
        if let Some(v) = &self.query {
            q.push(("query".into(), v.to_string()));
        }
        q
    }
}

/// Query parameters for [`ConversationAiService::get_the_generation_details`].
#[derive(Debug, Clone, Default)]
pub struct GetTheGenerationDetailsParams {
    /// Message Id
    /// Required by the API.
    pub message_id: String,
    /// `source` query parameter.
    /// Allowed values: `conversation`, `workflow`.
    /// Required by the API.
    pub source: String,
}

impl GetTheGenerationDetailsParams {
    /// Start from the parameters the API requires.
    pub fn new(message_id: impl Into<String>, source: impl Into<String>) -> Self {
        Self {
            message_id: message_id.into(),
            source: source.into(),
        }
    }

    fn to_query(&self) -> Vec<(String, String)> {
        let q: Vec<(String, String)> = vec![
            ("messageId".into(), self.message_id.clone()),
            ("source".into(), self.source.clone()),
        ];
        q
    }
}

impl ConversationAiService {
    /// Create an Agent
    ///
    /// Creates a new AI agent for the location. The agent will be created with the
    /// specified configuration including name, role, actions, and behavior settings.
    ///
    /// `POST /conversation-ai/agents`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn create_an_agent(
        &self,
        body: &models::CreateEmployeeDto,
    ) -> Result<models::EmployeeResponseDTO> {
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                "/conversation-ai/agents",
                &query,
                Some(body),
                Some("2021-04-15"),
            )
            .await
    }

    /// Search Agents
    ///
    /// Searches for AI agents based on various criteria including name, status, and
    /// configuration. Supports advanced filtering and full-text search capabilities.
    ///
    /// `GET /conversation-ai/agents/search`
    ///
    /// Requires scope: `conversation-ai.readonly`.
    pub async fn search_agents(
        &self,
        params: &SearchAgentsParams,
    ) -> Result<models::SearchEmployeeResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/conversation-ai/agents/search",
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Delete Agent
    ///
    /// Deletes an AI agent permanently. This action cannot be undone. All associated
    /// configurations and conversation history will be removed.
    ///
    /// `DELETE /conversation-ai/agents/{agentId}`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn delete_agent(&self, agent_id: &str) -> Result<models::DeleteEmployeeResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Get Agent
    ///
    /// Retrieves a specific AI agent by its ID. Returns the complete agent configuration
    /// including name, status, actions, and settings.
    ///
    /// `GET /conversation-ai/agents/{agentId}`
    ///
    /// Requires scope: `conversation-ai.readonly`.
    pub async fn get_agent(&self, agent_id: &str) -> Result<models::EmployeeResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Update Agent
    ///
    /// Updates an existing AI agent's configuration. All fields in the agent configuration
    /// can be updated including name, status, actions, and behavior settings.
    ///
    /// `PUT /conversation-ai/agents/{agentId}`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn update_agent(
        &self,
        agent_id: &str,
        body: &models::UpdateEmployeeDto,
    ) -> Result<models::EmployeeResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PUT,
                &path,
                &query,
                Some(body),
                Some("2021-04-15"),
            )
            .await
    }

    /// Attach Action to Agent
    ///
    /// Creates and attach a new action for an AI agent. Actions define specific tasks or
    /// behaviors that the agent can perform, such as booking appointments, sending
    /// follow-ups, or collecting information.
    ///
    /// `POST /conversation-ai/agents/{agentId}/actions`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn attach_action_to_agent(
        &self,
        agent_id: &str,
        body: &models::CreateActionDTO,
    ) -> Result<models::CreateActionResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/actions",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::POST,
                &path,
                &query,
                Some(body),
                Some("2021-04-15"),
            )
            .await
    }

    /// List Actions for an Agent
    ///
    /// List for actions for an agent
    ///
    /// `GET /conversation-ai/agents/{agentId}/actions/list`
    ///
    /// Requires scope: `conversation-ai.readonly`.
    pub async fn list_actions_for_an_agent(
        &self,
        agent_id: &str,
    ) -> Result<models::FetchActionsForEmployeeResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/actions/list",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Remove Action from Agent
    ///
    /// Permanently deletes an action. This will remove the action from all associated
    /// agents and cannot be undone.
    ///
    /// `DELETE /conversation-ai/agents/{agentId}/actions/{actionId}`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn remove_action_from_agent(
        &self,
        agent_id: &str,
        action_id: &str,
    ) -> Result<models::DeleteActionResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/actions/{}",
            crate::services::encode(agent_id),
            crate::services::encode(action_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::DELETE,
                &path,
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Get Action by ID
    ///
    /// Retrieves detailed information about a specific action using its unique identifier.
    /// Returns the action configuration, associated agents, and performance metrics.
    ///
    /// `GET /conversation-ai/agents/{agentId}/actions/{actionId}`
    ///
    /// Requires scope: `conversation-ai.readonly`.
    pub async fn get_action_by_id(
        &self,
        agent_id: &str,
        action_id: &str,
    ) -> Result<models::FetchActionDetailsResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/actions/{}",
            crate::services::encode(agent_id),
            crate::services::encode(action_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                &path,
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }

    /// Update Action
    ///
    /// Updates an existing action's configuration. This includes modifying the action name,
    /// description, trigger conditions, and behavior settings.
    ///
    /// `PUT /conversation-ai/agents/{agentId}/actions/{actionId}`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn update_action(
        &self,
        agent_id: &str,
        action_id: &str,
        body: &models::CreateActionDTO,
    ) -> Result<models::UpdateActionResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/actions/{}",
            crate::services::encode(agent_id),
            crate::services::encode(action_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PUT,
                &path,
                &query,
                Some(body),
                Some("2021-04-15"),
            )
            .await
    }

    /// Update Followup Settings
    ///
    /// Update the followup settings for an action
    ///
    /// `PATCH /conversation-ai/agents/{agentId}/followup-settings`
    ///
    /// Requires scope: `conversation-ai.write`.
    pub async fn update_followup_settings(
        &self,
        agent_id: &str,
        body: &models::UpdateFollowupSettingsDTO,
    ) -> Result<models::UpdateActionResponseDTO> {
        let path = format!(
            "/conversation-ai/agents/{}/followup-settings",
            crate::services::encode(agent_id)
        );
        let query = Vec::new();
        self.client
            .send_versioned(
                reqwest::Method::PATCH,
                &path,
                &query,
                Some(body),
                Some("2021-04-15"),
            )
            .await
    }

    /// Get the generation details
    ///
    /// Retrieves detailed information about AI responses including the System Prompt,
    /// Conversation history, Knowledge base, website, FAQ chunks, and Rich Text chunks.
    ///
    /// `GET /conversation-ai/generations`
    ///
    /// Requires scope: `conversation-ai.readonly`.
    pub async fn get_the_generation_details(
        &self,
        params: &GetTheGenerationDetailsParams,
    ) -> Result<models::FetchAIResponseDetailsResponseDTO> {
        let query = params.to_query();
        self.client
            .send_versioned(
                reqwest::Method::GET,
                "/conversation-ai/generations",
                &query,
                None::<&()>,
                Some("2021-04-15"),
            )
            .await
    }
}