vapi_client/apis/
chats_api.rs

1/*
2 * Vapi API
3 *
4 * Voice AI for developers.
5 *
6 * The version of the OpenAPI document: 1.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`chat_controller_create_chat`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ChatControllerCreateChatError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`chat_controller_create_open_ai_chat`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum ChatControllerCreateOpenAiChatError {
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`chat_controller_delete_chat`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ChatControllerDeleteChatError {
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`chat_controller_get_chat`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ChatControllerGetChatError {
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`chat_controller_list_chats`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum ChatControllerListChatsError {
48    UnknownValue(serde_json::Value),
49}
50
51/// Creates a new chat. Requires at least one of: assistantId/assistant, sessionId, or previousChatId. Note: sessionId and previousChatId are mutually exclusive.
52pub async fn chat_controller_create_chat(
53    configuration: &configuration::Configuration,
54    create_chat_dto: models::CreateChatDto,
55) -> Result<models::ChatControllerCreateChat200Response, Error<ChatControllerCreateChatError>> {
56    // add a prefix to parameters to efficiently prevent name collisions
57    let p_create_chat_dto = create_chat_dto;
58
59    let uri_str = format!("{}/chat", configuration.base_path);
60    let mut req_builder = configuration
61        .client
62        .request(reqwest::Method::POST, &uri_str);
63
64    if let Some(ref user_agent) = configuration.user_agent {
65        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
66    }
67    if let Some(ref token) = configuration.bearer_access_token {
68        req_builder = req_builder.bearer_auth(token.to_owned());
69    };
70    req_builder = req_builder.json(&p_create_chat_dto);
71
72    let req = req_builder.build()?;
73    let resp = configuration.client.execute(req).await?;
74
75    let status = resp.status();
76    let content_type = resp
77        .headers()
78        .get("content-type")
79        .and_then(|v| v.to_str().ok())
80        .unwrap_or("application/octet-stream");
81    let content_type = super::ContentType::from(content_type);
82
83    if !status.is_client_error() && !status.is_server_error() {
84        let content = resp.text().await?;
85        match content_type {
86            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
87            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChatControllerCreateChat200Response`"))),
88            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ChatControllerCreateChat200Response`")))),
89        }
90    } else {
91        let content = resp.text().await?;
92        let entity: Option<ChatControllerCreateChatError> = serde_json::from_str(&content).ok();
93        Err(Error::ResponseError(ResponseContent {
94            status,
95            content,
96            entity,
97        }))
98    }
99}
100
101pub async fn chat_controller_create_open_ai_chat(
102    configuration: &configuration::Configuration,
103    open_ai_responses_request: models::OpenAiResponsesRequest,
104) -> Result<
105    models::ChatControllerCreateOpenAiChat200Response,
106    Error<ChatControllerCreateOpenAiChatError>,
107> {
108    // add a prefix to parameters to efficiently prevent name collisions
109    let p_open_ai_responses_request = open_ai_responses_request;
110
111    let uri_str = format!("{}/chat/responses", configuration.base_path);
112    let mut req_builder = configuration
113        .client
114        .request(reqwest::Method::POST, &uri_str);
115
116    if let Some(ref user_agent) = configuration.user_agent {
117        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
118    }
119    if let Some(ref token) = configuration.bearer_access_token {
120        req_builder = req_builder.bearer_auth(token.to_owned());
121    };
122    req_builder = req_builder.json(&p_open_ai_responses_request);
123
124    let req = req_builder.build()?;
125    let resp = configuration.client.execute(req).await?;
126
127    let status = resp.status();
128    let content_type = resp
129        .headers()
130        .get("content-type")
131        .and_then(|v| v.to_str().ok())
132        .unwrap_or("application/octet-stream");
133    let content_type = super::ContentType::from(content_type);
134
135    if !status.is_client_error() && !status.is_server_error() {
136        let content = resp.text().await?;
137        match content_type {
138            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
139            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChatControllerCreateOpenAiChat200Response`"))),
140            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ChatControllerCreateOpenAiChat200Response`")))),
141        }
142    } else {
143        let content = resp.text().await?;
144        let entity: Option<ChatControllerCreateOpenAiChatError> =
145            serde_json::from_str(&content).ok();
146        Err(Error::ResponseError(ResponseContent {
147            status,
148            content,
149            entity,
150        }))
151    }
152}
153
154pub async fn chat_controller_delete_chat(
155    configuration: &configuration::Configuration,
156    id: &str,
157) -> Result<models::Chat, Error<ChatControllerDeleteChatError>> {
158    // add a prefix to parameters to efficiently prevent name collisions
159    let p_id = id;
160
161    let uri_str = format!(
162        "{}/chat/{id}",
163        configuration.base_path,
164        id = crate::apis::urlencode(p_id)
165    );
166    let mut req_builder = configuration
167        .client
168        .request(reqwest::Method::DELETE, &uri_str);
169
170    if let Some(ref user_agent) = configuration.user_agent {
171        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
172    }
173    if let Some(ref token) = configuration.bearer_access_token {
174        req_builder = req_builder.bearer_auth(token.to_owned());
175    };
176
177    let req = req_builder.build()?;
178    let resp = configuration.client.execute(req).await?;
179
180    let status = resp.status();
181    let content_type = resp
182        .headers()
183        .get("content-type")
184        .and_then(|v| v.to_str().ok())
185        .unwrap_or("application/octet-stream");
186    let content_type = super::ContentType::from(content_type);
187
188    if !status.is_client_error() && !status.is_server_error() {
189        let content = resp.text().await?;
190        match content_type {
191            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
192            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Chat`"))),
193            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Chat`")))),
194        }
195    } else {
196        let content = resp.text().await?;
197        let entity: Option<ChatControllerDeleteChatError> = serde_json::from_str(&content).ok();
198        Err(Error::ResponseError(ResponseContent {
199            status,
200            content,
201            entity,
202        }))
203    }
204}
205
206pub async fn chat_controller_get_chat(
207    configuration: &configuration::Configuration,
208    id: &str,
209) -> Result<models::Chat, Error<ChatControllerGetChatError>> {
210    // add a prefix to parameters to efficiently prevent name collisions
211    let p_id = id;
212
213    let uri_str = format!(
214        "{}/chat/{id}",
215        configuration.base_path,
216        id = crate::apis::urlencode(p_id)
217    );
218    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
219
220    if let Some(ref user_agent) = configuration.user_agent {
221        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
222    }
223    if let Some(ref token) = configuration.bearer_access_token {
224        req_builder = req_builder.bearer_auth(token.to_owned());
225    };
226
227    let req = req_builder.build()?;
228    let resp = configuration.client.execute(req).await?;
229
230    let status = resp.status();
231    let content_type = resp
232        .headers()
233        .get("content-type")
234        .and_then(|v| v.to_str().ok())
235        .unwrap_or("application/octet-stream");
236    let content_type = super::ContentType::from(content_type);
237
238    if !status.is_client_error() && !status.is_server_error() {
239        let content = resp.text().await?;
240        match content_type {
241            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
242            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Chat`"))),
243            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::Chat`")))),
244        }
245    } else {
246        let content = resp.text().await?;
247        let entity: Option<ChatControllerGetChatError> = serde_json::from_str(&content).ok();
248        Err(Error::ResponseError(ResponseContent {
249            status,
250            content,
251            entity,
252        }))
253    }
254}
255
256pub async fn chat_controller_list_chats(
257    configuration: &configuration::Configuration,
258    assistant_id: Option<&str>,
259    workflow_id: Option<&str>,
260    session_id: Option<&str>,
261    page: Option<f64>,
262    sort_order: Option<&str>,
263    limit: Option<f64>,
264    created_at_gt: Option<String>,
265    created_at_lt: Option<String>,
266    created_at_ge: Option<String>,
267    created_at_le: Option<String>,
268    updated_at_gt: Option<String>,
269    updated_at_lt: Option<String>,
270    updated_at_ge: Option<String>,
271    updated_at_le: Option<String>,
272) -> Result<models::ChatPaginatedResponse, Error<ChatControllerListChatsError>> {
273    // add a prefix to parameters to efficiently prevent name collisions
274    let p_assistant_id = assistant_id;
275    let p_workflow_id = workflow_id;
276    let p_session_id = session_id;
277    let p_page = page;
278    let p_sort_order = sort_order;
279    let p_limit = limit;
280    let p_created_at_gt = created_at_gt;
281    let p_created_at_lt = created_at_lt;
282    let p_created_at_ge = created_at_ge;
283    let p_created_at_le = created_at_le;
284    let p_updated_at_gt = updated_at_gt;
285    let p_updated_at_lt = updated_at_lt;
286    let p_updated_at_ge = updated_at_ge;
287    let p_updated_at_le = updated_at_le;
288
289    let uri_str = format!("{}/chat", configuration.base_path);
290    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
291
292    if let Some(ref param_value) = p_assistant_id {
293        req_builder = req_builder.query(&[("assistantId", &param_value.to_string())]);
294    }
295    if let Some(ref param_value) = p_workflow_id {
296        req_builder = req_builder.query(&[("workflowId", &param_value.to_string())]);
297    }
298    if let Some(ref param_value) = p_session_id {
299        req_builder = req_builder.query(&[("sessionId", &param_value.to_string())]);
300    }
301    if let Some(ref param_value) = p_page {
302        req_builder = req_builder.query(&[("page", &param_value.to_string())]);
303    }
304    if let Some(ref param_value) = p_sort_order {
305        req_builder = req_builder.query(&[("sortOrder", &param_value.to_string())]);
306    }
307    if let Some(ref param_value) = p_limit {
308        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
309    }
310    if let Some(ref param_value) = p_created_at_gt {
311        req_builder = req_builder.query(&[("createdAtGt", &param_value.to_string())]);
312    }
313    if let Some(ref param_value) = p_created_at_lt {
314        req_builder = req_builder.query(&[("createdAtLt", &param_value.to_string())]);
315    }
316    if let Some(ref param_value) = p_created_at_ge {
317        req_builder = req_builder.query(&[("createdAtGe", &param_value.to_string())]);
318    }
319    if let Some(ref param_value) = p_created_at_le {
320        req_builder = req_builder.query(&[("createdAtLe", &param_value.to_string())]);
321    }
322    if let Some(ref param_value) = p_updated_at_gt {
323        req_builder = req_builder.query(&[("updatedAtGt", &param_value.to_string())]);
324    }
325    if let Some(ref param_value) = p_updated_at_lt {
326        req_builder = req_builder.query(&[("updatedAtLt", &param_value.to_string())]);
327    }
328    if let Some(ref param_value) = p_updated_at_ge {
329        req_builder = req_builder.query(&[("updatedAtGe", &param_value.to_string())]);
330    }
331    if let Some(ref param_value) = p_updated_at_le {
332        req_builder = req_builder.query(&[("updatedAtLe", &param_value.to_string())]);
333    }
334    if let Some(ref user_agent) = configuration.user_agent {
335        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
336    }
337    if let Some(ref token) = configuration.bearer_access_token {
338        req_builder = req_builder.bearer_auth(token.to_owned());
339    };
340
341    let req = req_builder.build()?;
342    let resp = configuration.client.execute(req).await?;
343
344    let status = resp.status();
345    let content_type = resp
346        .headers()
347        .get("content-type")
348        .and_then(|v| v.to_str().ok())
349        .unwrap_or("application/octet-stream");
350    let content_type = super::ContentType::from(content_type);
351
352    if !status.is_client_error() && !status.is_server_error() {
353        let content = resp.text().await?;
354        match content_type {
355            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
356            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ChatPaginatedResponse`"))),
357            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ChatPaginatedResponse`")))),
358        }
359    } else {
360        let content = resp.text().await?;
361        let entity: Option<ChatControllerListChatsError> = serde_json::from_str(&content).ok();
362        Err(Error::ResponseError(ResponseContent {
363            status,
364            content,
365            entity,
366        }))
367    }
368}