twilio_rust_openapi/apis/
api20100401_call_api.rs

1/*
2 * Twilio - Api
3 *
4 * This is the public Twilio REST API.
5 *
6 * The version of the OpenAPI document: 1.0.0
7 * Contact: support@twilio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`create_call`]
18#[derive(Clone, Debug)]
19pub struct CreateCallParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
21    pub account_sid: String,
22    /// The phone number, SIP address, or client identifier to call.
23    pub to: String,
24    /// The phone number or client identifier to use as the caller id. If using a phone number, it must be a Twilio number or a Verified [outgoing caller id](https://www.twilio.com/docs/voice/api/outgoing-caller-ids) for your account. If the `to` parameter is a phone number, `From` must also be a phone number.
25    pub from: String,
26    /// The HTTP method we should use when calling the `url` parameter's value. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
27    pub method: Option<String>,
28    /// The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored.
29    pub fallback_url: Option<String>,
30    /// The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
31    pub fallback_method: Option<String>,
32    /// The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted).
33    pub status_callback: Option<String>,
34    /// The call progress events that we will send to the `status_callback` URL. Can be: `initiated`, `ringing`, `answered`, and `completed`. If no event is specified, we send the `completed` status. If you want to receive multiple events, specify each one in a separate `status_callback_event` parameter. See the code sample for [monitoring call progress](https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-create-a-call-resource-and-specify-a-statuscallbackevent&code-sdk-version=json). If an `application_sid` is present, this parameter is ignored.
35    pub status_callback_event: Option<Vec<String>>,
36    /// The HTTP method we should use when calling the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
37    pub status_callback_method: Option<String>,
38    /// A string of keys to dial after connecting to the number, maximum of 32 digits. Valid digits in the string include: any digit (`0`-`9`), '`#`', '`*`' and '`w`', to insert a half second pause. For example, if you connected to a company phone number and wanted to pause for one second, and then dial extension 1234 followed by the pound key, the value of this parameter would be `ww1234#`. Remember to URL-encode this string, since the '`#`' character has special meaning in a URL. If both `SendDigits` and `MachineDetection` parameters are provided, then `MachineDetection` will be ignored.
39    pub send_digits: Option<String>,
40    /// The integer number of seconds that we should allow the phone to ring before assuming there is no answer. The default is `60` seconds and the maximum is `600` seconds. For some call flows, we will add a 5-second buffer to the timeout value you provide. For this reason, a timeout value of 10 seconds could result in an actual timeout closer to 15 seconds. You can set this to a short time, such as `15` seconds, to hang up before reaching an answering machine or voicemail.
41    pub timeout: Option<i32>,
42    /// Whether to record the call. Can be `true` to record the phone call, or `false` to not. The default is `false`. The `recording_url` is sent to the `status_callback` URL.
43    pub record: Option<bool>,
44    /// The number of channels in the final recording. Can be: `mono` or `dual`. The default is `mono`. `mono` records both legs of the call in a single channel of the recording file. `dual` records each leg to a separate channel of the recording file. The first channel of a dual-channel recording contains the parent call and the second channel contains the child call.
45    pub recording_channels: Option<String>,
46    /// The URL that we call when the recording is available to be accessed.
47    pub recording_status_callback: Option<String>,
48    /// The HTTP method we should use when calling the `recording_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`.
49    pub recording_status_callback_method: Option<String>,
50    /// The username used to authenticate the caller making a SIP call.
51    pub sip_auth_username: Option<String>,
52    /// The password required to authenticate the user account specified in `sip_auth_username`.
53    pub sip_auth_password: Option<String>,
54    /// Whether to detect if a human, answering machine, or fax has picked up the call. Can be: `Enable` or `DetectMessageEnd`. Use `Enable` if you would like us to return `AnsweredBy` as soon as the called party is identified. Use `DetectMessageEnd`, if you would like to leave a message on an answering machine. If `send_digits` is provided, this parameter is ignored. For more information, see [Answering Machine Detection](https://www.twilio.com/docs/voice/answering-machine-detection).
55    pub machine_detection: Option<String>,
56    /// The number of seconds that we should attempt to detect an answering machine before timing out and sending a voice request with `AnsweredBy` of `unknown`. The default timeout is 30 seconds.
57    pub machine_detection_timeout: Option<i32>,
58    /// The recording status events that will trigger calls to the URL specified in `recording_status_callback`. Can be: `in-progress`, `completed` and `absent`. Defaults to `completed`. Separate  multiple values with a space.
59    pub recording_status_callback_event: Option<Vec<String>>,
60    /// Whether to trim any leading and trailing silence from the recording. Can be: `trim-silence` or `do-not-trim` and the default is `trim-silence`.
61    pub trim: Option<String>,
62    /// The phone number, SIP address, or Client identifier that made this call. Phone numbers are in [E.164 format](https://wwnw.twilio.com/docs/glossary/what-e164) (e.g., +16175551212). SIP addresses are formatted as `name@company.com`.
63    pub caller_id: Option<String>,
64    /// The number of milliseconds that is used as the measuring stick for the length of the speech activity, where durations lower than this value will be interpreted as a human and longer than this value as a machine. Possible Values: 1000-6000. Default: 2400.
65    pub machine_detection_speech_threshold: Option<i32>,
66    /// The number of milliseconds of silence after speech activity at which point the speech activity is considered complete. Possible Values: 500-5000. Default: 1200.
67    pub machine_detection_speech_end_threshold: Option<i32>,
68    /// The number of milliseconds of initial silence after which an `unknown` AnsweredBy result will be returned. Possible Values: 2000-10000. Default: 5000.
69    pub machine_detection_silence_timeout: Option<i32>,
70    /// Select whether to perform answering machine detection in the background. Default, blocks the execution of the call until Answering Machine Detection is completed. Can be: `true` or `false`.
71    pub async_amd: Option<String>,
72    /// The URL that we should call using the `async_amd_status_callback_method` to notify customer application whether the call was answered by human, machine or fax.
73    pub async_amd_status_callback: Option<String>,
74    /// The HTTP method we should use when calling the `async_amd_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`.
75    pub async_amd_status_callback_method: Option<String>,
76    /// The SID of a BYOC (Bring Your Own Carrier) trunk to route this call with. Note that `byoc` is only meaningful when `to` is a phone number; it will otherwise be ignored. (Beta)
77    pub byoc: Option<String>,
78    /// The Reason for the outgoing call. Use it to specify the purpose of the call that is presented on the called party's phone. (Branded Calls Beta)
79    pub call_reason: Option<String>,
80    /// A token string needed to invoke a forwarded call. A call_token is generated when an incoming call is received on a Twilio number. Pass an incoming call's call_token value to a forwarded call via the call_token parameter when creating a new call. A forwarded call should bear the same CallerID of the original incoming call.
81    pub call_token: Option<String>,
82    /// The audio track to record for the call. Can be: `inbound`, `outbound` or `both`. The default is `both`. `inbound` records the audio that is received by Twilio. `outbound` records the audio that is generated from Twilio. `both` records the audio that is received and generated by Twilio.
83    pub recording_track: Option<String>,
84    /// The maximum duration of the call in seconds. Constraints depend on account and configuration.
85    pub time_limit: Option<i32>,
86    /// The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls).
87    pub url: Option<String>,
88    /// TwiML instructions for the call Twilio will use without fetching Twiml from url parameter. If both `twiml` and `url` are provided then `twiml` parameter will be ignored. Max 4000 characters.
89    pub twiml: Option<String>,
90    /// The SID of the Application resource that will handle the call, if the call will be handled by an application.
91    pub application_sid: Option<String>
92}
93
94/// struct for passing parameters to the method [`delete_call`]
95#[derive(Clone, Debug)]
96pub struct DeleteCallParams {
97    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to delete.
98    pub account_sid: String,
99    /// The Twilio-provided Call SID that uniquely identifies the Call resource to delete
100    pub sid: String
101}
102
103/// struct for passing parameters to the method [`fetch_call`]
104#[derive(Clone, Debug)]
105pub struct FetchCallParams {
106    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to fetch.
107    pub account_sid: String,
108    /// The SID of the Call resource to fetch.
109    pub sid: String
110}
111
112/// struct for passing parameters to the method [`list_call`]
113#[derive(Clone, Debug)]
114pub struct ListCallParams {
115    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to read.
116    pub account_sid: String,
117    /// Only show calls made to this phone number, SIP address, Client identifier or SIM SID.
118    pub to: Option<String>,
119    /// Only include calls from this phone number, SIP address, Client identifier or SIM SID.
120    pub from: Option<String>,
121    /// Only include calls spawned by calls with this SID.
122    pub parent_call_sid: Option<String>,
123    /// The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`.
124    pub status: Option<String>,
125    /// Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date.
126    pub start_time: Option<String>,
127    /// Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date.
128    pub start_time_less_than: Option<String>,
129    /// Only include calls that started on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that started on this date. You can also specify an inequality, such as `StartTime<=YYYY-MM-DD`, to read calls that started on or before midnight of this date, and `StartTime>=YYYY-MM-DD` to read calls that started on or after midnight of this date.
130    pub start_time_greater_than: Option<String>,
131    /// Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date.
132    pub end_time: Option<String>,
133    /// Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date.
134    pub end_time_less_than: Option<String>,
135    /// Only include calls that ended on this date. Specify a date as `YYYY-MM-DD` in UTC, for example: `2009-07-06`, to read only calls that ended on this date. You can also specify an inequality, such as `EndTime<=YYYY-MM-DD`, to read calls that ended on or before midnight of this date, and `EndTime>=YYYY-MM-DD` to read calls that ended on or after midnight of this date.
136    pub end_time_greater_than: Option<String>,
137    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
138    pub page_size: Option<i32>,
139    /// The page index. This value is simply for client state.
140    pub page: Option<i32>,
141    /// The page token. This is provided by the API.
142    pub page_token: Option<String>
143}
144
145/// struct for passing parameters to the method [`update_call`]
146#[derive(Clone, Debug)]
147pub struct UpdateCallParams {
148    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to update.
149    pub account_sid: String,
150    /// The Twilio-provided string that uniquely identifies the Call resource to update
151    pub sid: String,
152    /// The absolute URL that returns the TwiML instructions for the call. We will call this URL using the `method` when the call connects. For more information, see the [Url Parameter](https://www.twilio.com/docs/voice/make-calls#specify-a-url-parameter) section in [Making Calls](https://www.twilio.com/docs/voice/make-calls).
153    pub url: Option<String>,
154    /// The HTTP method we should use when calling the `url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
155    pub method: Option<String>,
156    pub status: Option<String>,
157    /// The URL that we call using the `fallback_method` if an error occurs when requesting or executing the TwiML at `url`. If an `application_sid` parameter is present, this parameter is ignored.
158    pub fallback_url: Option<String>,
159    /// The HTTP method that we should use to request the `fallback_url`. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
160    pub fallback_method: Option<String>,
161    /// The URL we should call using the `status_callback_method` to send status information to your application. If no `status_callback_event` is specified, we will send the `completed` status. If an `application_sid` parameter is present, this parameter is ignored. URLs must contain a valid hostname (underscores are not permitted).
162    pub status_callback: Option<String>,
163    /// The HTTP method we should use when requesting the `status_callback` URL. Can be: `GET` or `POST` and the default is `POST`. If an `application_sid` parameter is present, this parameter is ignored.
164    pub status_callback_method: Option<String>,
165    /// TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive
166    pub twiml: Option<String>,
167    /// The maximum duration of the call in seconds. Constraints depend on account and configuration.
168    pub time_limit: Option<i32>
169}
170
171
172/// struct for typed errors of method [`create_call`]
173#[derive(Debug, Clone, Serialize, Deserialize)]
174#[serde(untagged)]
175pub enum CreateCallError {
176    UnknownValue(serde_json::Value),
177}
178
179/// struct for typed errors of method [`delete_call`]
180#[derive(Debug, Clone, Serialize, Deserialize)]
181#[serde(untagged)]
182pub enum DeleteCallError {
183    UnknownValue(serde_json::Value),
184}
185
186/// struct for typed errors of method [`fetch_call`]
187#[derive(Debug, Clone, Serialize, Deserialize)]
188#[serde(untagged)]
189pub enum FetchCallError {
190    UnknownValue(serde_json::Value),
191}
192
193/// struct for typed errors of method [`list_call`]
194#[derive(Debug, Clone, Serialize, Deserialize)]
195#[serde(untagged)]
196pub enum ListCallError {
197    UnknownValue(serde_json::Value),
198}
199
200/// struct for typed errors of method [`update_call`]
201#[derive(Debug, Clone, Serialize, Deserialize)]
202#[serde(untagged)]
203pub enum UpdateCallError {
204    UnknownValue(serde_json::Value),
205}
206
207
208/// Create a new outgoing call to phones, SIP-enabled endpoints or Twilio Client connections
209pub async fn create_call(configuration: &configuration::Configuration, params: CreateCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<CreateCallError>> {
210    let local_var_configuration = configuration;
211
212    // unbox the parameters
213    let account_sid = params.account_sid;
214    let to = params.to;
215    let from = params.from;
216    let method = params.method;
217    let fallback_url = params.fallback_url;
218    let fallback_method = params.fallback_method;
219    let status_callback = params.status_callback;
220    let status_callback_event = params.status_callback_event;
221    let status_callback_method = params.status_callback_method;
222    let send_digits = params.send_digits;
223    let timeout = params.timeout;
224    let record = params.record;
225    let recording_channels = params.recording_channels;
226    let recording_status_callback = params.recording_status_callback;
227    let recording_status_callback_method = params.recording_status_callback_method;
228    let sip_auth_username = params.sip_auth_username;
229    let sip_auth_password = params.sip_auth_password;
230    let machine_detection = params.machine_detection;
231    let machine_detection_timeout = params.machine_detection_timeout;
232    let recording_status_callback_event = params.recording_status_callback_event;
233    let trim = params.trim;
234    let caller_id = params.caller_id;
235    let machine_detection_speech_threshold = params.machine_detection_speech_threshold;
236    let machine_detection_speech_end_threshold = params.machine_detection_speech_end_threshold;
237    let machine_detection_silence_timeout = params.machine_detection_silence_timeout;
238    let async_amd = params.async_amd;
239    let async_amd_status_callback = params.async_amd_status_callback;
240    let async_amd_status_callback_method = params.async_amd_status_callback_method;
241    let byoc = params.byoc;
242    let call_reason = params.call_reason;
243    let call_token = params.call_token;
244    let recording_track = params.recording_track;
245    let time_limit = params.time_limit;
246    let url = params.url;
247    let twiml = params.twiml;
248    let application_sid = params.application_sid;
249
250
251    let local_var_client = &local_var_configuration.client;
252
253    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
254    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
255
256    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
257        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
258    }
259    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
260        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
261    };
262    let mut local_var_form_params = std::collections::HashMap::new();
263    local_var_form_params.insert("To", to.to_string());
264    local_var_form_params.insert("From", from.to_string());
265    if let Some(local_var_param_value) = method {
266        local_var_form_params.insert("Method", local_var_param_value.to_string());
267    }
268    if let Some(local_var_param_value) = fallback_url {
269        local_var_form_params.insert("FallbackUrl", local_var_param_value.to_string());
270    }
271    if let Some(local_var_param_value) = fallback_method {
272        local_var_form_params.insert("FallbackMethod", local_var_param_value.to_string());
273    }
274    if let Some(local_var_param_value) = status_callback {
275        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
276    }
277    if let Some(local_var_param_value) = status_callback_event {
278        local_var_form_params.insert("StatusCallbackEvent", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
279    }
280    if let Some(local_var_param_value) = status_callback_method {
281        local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
282    }
283    if let Some(local_var_param_value) = send_digits {
284        local_var_form_params.insert("SendDigits", local_var_param_value.to_string());
285    }
286    if let Some(local_var_param_value) = timeout {
287        local_var_form_params.insert("Timeout", local_var_param_value.to_string());
288    }
289    if let Some(local_var_param_value) = record {
290        local_var_form_params.insert("Record", local_var_param_value.to_string());
291    }
292    if let Some(local_var_param_value) = recording_channels {
293        local_var_form_params.insert("RecordingChannels", local_var_param_value.to_string());
294    }
295    if let Some(local_var_param_value) = recording_status_callback {
296        local_var_form_params.insert("RecordingStatusCallback", local_var_param_value.to_string());
297    }
298    if let Some(local_var_param_value) = recording_status_callback_method {
299        local_var_form_params.insert("RecordingStatusCallbackMethod", local_var_param_value.to_string());
300    }
301    if let Some(local_var_param_value) = sip_auth_username {
302        local_var_form_params.insert("SipAuthUsername", local_var_param_value.to_string());
303    }
304    if let Some(local_var_param_value) = sip_auth_password {
305        local_var_form_params.insert("SipAuthPassword", local_var_param_value.to_string());
306    }
307    if let Some(local_var_param_value) = machine_detection {
308        local_var_form_params.insert("MachineDetection", local_var_param_value.to_string());
309    }
310    if let Some(local_var_param_value) = machine_detection_timeout {
311        local_var_form_params.insert("MachineDetectionTimeout", local_var_param_value.to_string());
312    }
313    if let Some(local_var_param_value) = recording_status_callback_event {
314        local_var_form_params.insert("RecordingStatusCallbackEvent", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
315    }
316    if let Some(local_var_param_value) = trim {
317        local_var_form_params.insert("Trim", local_var_param_value.to_string());
318    }
319    if let Some(local_var_param_value) = caller_id {
320        local_var_form_params.insert("CallerId", local_var_param_value.to_string());
321    }
322    if let Some(local_var_param_value) = machine_detection_speech_threshold {
323        local_var_form_params.insert("MachineDetectionSpeechThreshold", local_var_param_value.to_string());
324    }
325    if let Some(local_var_param_value) = machine_detection_speech_end_threshold {
326        local_var_form_params.insert("MachineDetectionSpeechEndThreshold", local_var_param_value.to_string());
327    }
328    if let Some(local_var_param_value) = machine_detection_silence_timeout {
329        local_var_form_params.insert("MachineDetectionSilenceTimeout", local_var_param_value.to_string());
330    }
331    if let Some(local_var_param_value) = async_amd {
332        local_var_form_params.insert("AsyncAmd", local_var_param_value.to_string());
333    }
334    if let Some(local_var_param_value) = async_amd_status_callback {
335        local_var_form_params.insert("AsyncAmdStatusCallback", local_var_param_value.to_string());
336    }
337    if let Some(local_var_param_value) = async_amd_status_callback_method {
338        local_var_form_params.insert("AsyncAmdStatusCallbackMethod", local_var_param_value.to_string());
339    }
340    if let Some(local_var_param_value) = byoc {
341        local_var_form_params.insert("Byoc", local_var_param_value.to_string());
342    }
343    if let Some(local_var_param_value) = call_reason {
344        local_var_form_params.insert("CallReason", local_var_param_value.to_string());
345    }
346    if let Some(local_var_param_value) = call_token {
347        local_var_form_params.insert("CallToken", local_var_param_value.to_string());
348    }
349    if let Some(local_var_param_value) = recording_track {
350        local_var_form_params.insert("RecordingTrack", local_var_param_value.to_string());
351    }
352    if let Some(local_var_param_value) = time_limit {
353        local_var_form_params.insert("TimeLimit", local_var_param_value.to_string());
354    }
355    if let Some(local_var_param_value) = url {
356        local_var_form_params.insert("Url", local_var_param_value.to_string());
357    }
358    if let Some(local_var_param_value) = twiml {
359        local_var_form_params.insert("Twiml", local_var_param_value.to_string());
360    }
361    if let Some(local_var_param_value) = application_sid {
362        local_var_form_params.insert("ApplicationSid", local_var_param_value.to_string());
363    }
364    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
365
366    let local_var_req = local_var_req_builder.build()?;
367    let local_var_resp = local_var_client.execute(local_var_req).await?;
368
369    let local_var_status = local_var_resp.status();
370    let local_var_content = local_var_resp.text().await?;
371
372    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
373        serde_json::from_str(&local_var_content).map_err(Error::from)
374    } else {
375        let local_var_entity: Option<CreateCallError> = serde_json::from_str(&local_var_content).ok();
376        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
377        Err(Error::ResponseError(local_var_error))
378    }
379}
380
381/// Delete a Call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs.
382pub async fn delete_call(configuration: &configuration::Configuration, params: DeleteCallParams) -> Result<(), Error<DeleteCallError>> {
383    let local_var_configuration = configuration;
384
385    // unbox the parameters
386    let account_sid = params.account_sid;
387    let sid = params.sid;
388
389
390    let local_var_client = &local_var_configuration.client;
391
392    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
393    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
394
395    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
396        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
397    }
398    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
399        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
400    };
401
402    let local_var_req = local_var_req_builder.build()?;
403    let local_var_resp = local_var_client.execute(local_var_req).await?;
404
405    let local_var_status = local_var_resp.status();
406    let local_var_content = local_var_resp.text().await?;
407
408    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
409        Ok(())
410    } else {
411        let local_var_entity: Option<DeleteCallError> = serde_json::from_str(&local_var_content).ok();
412        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
413        Err(Error::ResponseError(local_var_error))
414    }
415}
416
417/// Fetch the call specified by the provided Call SID
418pub async fn fetch_call(configuration: &configuration::Configuration, params: FetchCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<FetchCallError>> {
419    let local_var_configuration = configuration;
420
421    // unbox the parameters
422    let account_sid = params.account_sid;
423    let sid = params.sid;
424
425
426    let local_var_client = &local_var_configuration.client;
427
428    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
429    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
430
431    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
432        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
433    }
434    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
435        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
436    };
437
438    let local_var_req = local_var_req_builder.build()?;
439    let local_var_resp = local_var_client.execute(local_var_req).await?;
440
441    let local_var_status = local_var_resp.status();
442    let local_var_content = local_var_resp.text().await?;
443
444    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
445        serde_json::from_str(&local_var_content).map_err(Error::from)
446    } else {
447        let local_var_entity: Option<FetchCallError> = serde_json::from_str(&local_var_content).ok();
448        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
449        Err(Error::ResponseError(local_var_error))
450    }
451}
452
453/// Retrieves a collection of calls made to and from your account
454pub async fn list_call(configuration: &configuration::Configuration, params: ListCallParams) -> Result<models::ListCallResponse, Error<ListCallError>> {
455    let local_var_configuration = configuration;
456
457    // unbox the parameters
458    let account_sid = params.account_sid;
459    let to = params.to;
460    let from = params.from;
461    let parent_call_sid = params.parent_call_sid;
462    let status = params.status;
463    let start_time = params.start_time;
464    let start_time_less_than = params.start_time_less_than;
465    let start_time_greater_than = params.start_time_greater_than;
466    let end_time = params.end_time;
467    let end_time_less_than = params.end_time_less_than;
468    let end_time_greater_than = params.end_time_greater_than;
469    let page_size = params.page_size;
470    let page = params.page;
471    let page_token = params.page_token;
472
473
474    let local_var_client = &local_var_configuration.client;
475
476    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
477    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
478
479    if let Some(ref local_var_str) = to {
480        local_var_req_builder = local_var_req_builder.query(&[("To", &local_var_str.to_string())]);
481    }
482    if let Some(ref local_var_str) = from {
483        local_var_req_builder = local_var_req_builder.query(&[("From", &local_var_str.to_string())]);
484    }
485    if let Some(ref local_var_str) = parent_call_sid {
486        local_var_req_builder = local_var_req_builder.query(&[("ParentCallSid", &local_var_str.to_string())]);
487    }
488    if let Some(ref local_var_str) = status {
489        local_var_req_builder = local_var_req_builder.query(&[("Status", &local_var_str.to_string())]);
490    }
491    if let Some(ref local_var_str) = start_time {
492        local_var_req_builder = local_var_req_builder.query(&[("StartTime", &local_var_str.to_string())]);
493    }
494    if let Some(ref local_var_str) = start_time_less_than {
495        local_var_req_builder = local_var_req_builder.query(&[("StartTime<", &local_var_str.to_string())]);
496    }
497    if let Some(ref local_var_str) = start_time_greater_than {
498        local_var_req_builder = local_var_req_builder.query(&[("StartTime>", &local_var_str.to_string())]);
499    }
500    if let Some(ref local_var_str) = end_time {
501        local_var_req_builder = local_var_req_builder.query(&[("EndTime", &local_var_str.to_string())]);
502    }
503    if let Some(ref local_var_str) = end_time_less_than {
504        local_var_req_builder = local_var_req_builder.query(&[("EndTime<", &local_var_str.to_string())]);
505    }
506    if let Some(ref local_var_str) = end_time_greater_than {
507        local_var_req_builder = local_var_req_builder.query(&[("EndTime>", &local_var_str.to_string())]);
508    }
509    if let Some(ref local_var_str) = page_size {
510        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
511    }
512    if let Some(ref local_var_str) = page {
513        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
514    }
515    if let Some(ref local_var_str) = page_token {
516        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
517    }
518    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
519        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
520    }
521    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
522        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
523    };
524
525    let local_var_req = local_var_req_builder.build()?;
526    let local_var_resp = local_var_client.execute(local_var_req).await?;
527
528    let local_var_status = local_var_resp.status();
529    let local_var_content = local_var_resp.text().await?;
530
531    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
532        serde_json::from_str(&local_var_content).map_err(Error::from)
533    } else {
534        let local_var_entity: Option<ListCallError> = serde_json::from_str(&local_var_content).ok();
535        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
536        Err(Error::ResponseError(local_var_error))
537    }
538}
539
540/// Initiates a call redirect or terminates a call
541pub async fn update_call(configuration: &configuration::Configuration, params: UpdateCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<UpdateCallError>> {
542    let local_var_configuration = configuration;
543
544    // unbox the parameters
545    let account_sid = params.account_sid;
546    let sid = params.sid;
547    let url = params.url;
548    let method = params.method;
549    let status = params.status;
550    let fallback_url = params.fallback_url;
551    let fallback_method = params.fallback_method;
552    let status_callback = params.status_callback;
553    let status_callback_method = params.status_callback_method;
554    let twiml = params.twiml;
555    let time_limit = params.time_limit;
556
557
558    let local_var_client = &local_var_configuration.client;
559
560    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
561    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
562
563    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
564        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
565    }
566    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
567        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
568    };
569    let mut local_var_form_params = std::collections::HashMap::new();
570    if let Some(local_var_param_value) = url {
571        local_var_form_params.insert("Url", local_var_param_value.to_string());
572    }
573    if let Some(local_var_param_value) = method {
574        local_var_form_params.insert("Method", local_var_param_value.to_string());
575    }
576    if let Some(local_var_param_value) = status {
577        local_var_form_params.insert("Status", local_var_param_value.to_string());
578    }
579    if let Some(local_var_param_value) = fallback_url {
580        local_var_form_params.insert("FallbackUrl", local_var_param_value.to_string());
581    }
582    if let Some(local_var_param_value) = fallback_method {
583        local_var_form_params.insert("FallbackMethod", local_var_param_value.to_string());
584    }
585    if let Some(local_var_param_value) = status_callback {
586        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
587    }
588    if let Some(local_var_param_value) = status_callback_method {
589        local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
590    }
591    if let Some(local_var_param_value) = twiml {
592        local_var_form_params.insert("Twiml", local_var_param_value.to_string());
593    }
594    if let Some(local_var_param_value) = time_limit {
595        local_var_form_params.insert("TimeLimit", local_var_param_value.to_string());
596    }
597    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
598
599    let local_var_req = local_var_req_builder.build()?;
600    let local_var_resp = local_var_client.execute(local_var_req).await?;
601
602    let local_var_status = local_var_resp.status();
603    let local_var_content = local_var_resp.text().await?;
604
605    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
606        serde_json::from_str(&local_var_content).map_err(Error::from)
607    } else {
608        let local_var_entity: Option<UpdateCallError> = serde_json::from_str(&local_var_content).ok();
609        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
610        Err(Error::ResponseError(local_var_error))
611    }
612}
613