roark_rs/apis/
integrations_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateRetellCallError {
22 Status400(models::ErrorResponse),
23 Status401(models::ErrorResponse),
24 Status403(models::ErrorResponse),
25 Status429(models::ErrorResponse),
26 Status500(models::ErrorResponse),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum CreateVapiCallError {
34 Status400(models::ErrorResponse),
35 Status401(models::ErrorResponse),
36 Status403(models::ErrorResponse),
37 Status429(models::ErrorResponse),
38 Status500(models::ErrorResponse),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn create_retell_call(configuration: &configuration::Configuration, retell_call_upload_request: models::RetellCallUploadRequest) -> Result<models::CreateVapiCall201Response, Error<CreateRetellCallError>> {
45 let p_retell_call_upload_request = retell_call_upload_request;
47
48 let uri_str = format!("{}/v1/retell/call", configuration.base_path);
49 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54 if let Some(ref token) = configuration.bearer_access_token {
55 req_builder = req_builder.bearer_auth(token.to_owned());
56 };
57 req_builder = req_builder.json(&p_retell_call_upload_request);
58
59 let req = req_builder.build()?;
60 let resp = configuration.client.execute(req).await?;
61
62 let status = resp.status();
63 let content_type = resp
64 .headers()
65 .get("content-type")
66 .and_then(|v| v.to_str().ok())
67 .unwrap_or("application/octet-stream");
68 let content_type = super::ContentType::from(content_type);
69
70 if !status.is_client_error() && !status.is_server_error() {
71 let content = resp.text().await?;
72 match content_type {
73 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
74 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateVapiCall201Response`"))),
75 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::CreateVapiCall201Response`")))),
76 }
77 } else {
78 let content = resp.text().await?;
79 let entity: Option<CreateRetellCallError> = serde_json::from_str(&content).ok();
80 Err(Error::ResponseError(ResponseContent { status, content, entity }))
81 }
82}
83
84pub async fn create_vapi_call(configuration: &configuration::Configuration, vapi_call_upload_request: models::VapiCallUploadRequest) -> Result<models::CreateVapiCall201Response, Error<CreateVapiCallError>> {
86 let p_vapi_call_upload_request = vapi_call_upload_request;
88
89 let uri_str = format!("{}/v1/vapi/call", configuration.base_path);
90 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
91
92 if let Some(ref user_agent) = configuration.user_agent {
93 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94 }
95 if let Some(ref token) = configuration.bearer_access_token {
96 req_builder = req_builder.bearer_auth(token.to_owned());
97 };
98 req_builder = req_builder.json(&p_vapi_call_upload_request);
99
100 let req = req_builder.build()?;
101 let resp = configuration.client.execute(req).await?;
102
103 let status = resp.status();
104 let content_type = resp
105 .headers()
106 .get("content-type")
107 .and_then(|v| v.to_str().ok())
108 .unwrap_or("application/octet-stream");
109 let content_type = super::ContentType::from(content_type);
110
111 if !status.is_client_error() && !status.is_server_error() {
112 let content = resp.text().await?;
113 match content_type {
114 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
115 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateVapiCall201Response`"))),
116 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::CreateVapiCall201Response`")))),
117 }
118 } else {
119 let content = resp.text().await?;
120 let entity: Option<CreateVapiCallError> = serde_json::from_str(&content).ok();
121 Err(Error::ResponseError(ResponseContent { status, content, entity }))
122 }
123}
124