/*
* Twilio - Api
*
* This is the public Twilio REST API.
*
* The version of the OpenAPI document: 1.0.0
* Contact: support@twilio.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for passing parameters to the method [`create_call`]
#[derive(Clone, Debug)]
pub struct CreateCallParams {
/// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
pub account_sid: String,
/// The phone number, SIP address, or client identifier to call.
pub to: String,
/// 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.
pub from: String,
/// 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.
pub method: Option<String>,
/// 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.
pub fallback_url: Option<String>,
/// 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.
pub fallback_method: Option<String>,
/// 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).
pub status_callback: Option<String>,
/// 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.
pub status_callback_event: Option<Vec<String>>,
/// 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.
pub status_callback_method: Option<String>,
/// 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.
pub send_digits: Option<String>,
/// 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.
pub timeout: Option<i32>,
/// 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.
pub record: Option<bool>,
/// 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.
pub recording_channels: Option<String>,
/// The URL that we call when the recording is available to be accessed.
pub recording_status_callback: Option<String>,
/// The HTTP method we should use when calling the `recording_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`.
pub recording_status_callback_method: Option<String>,
/// The username used to authenticate the caller making a SIP call.
pub sip_auth_username: Option<String>,
/// The password required to authenticate the user account specified in `sip_auth_username`.
pub sip_auth_password: Option<String>,
/// 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).
pub machine_detection: Option<String>,
/// 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.
pub machine_detection_timeout: Option<i32>,
/// 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.
pub recording_status_callback_event: Option<Vec<String>>,
/// 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`.
pub trim: Option<String>,
/// 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`.
pub caller_id: Option<String>,
/// 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.
pub machine_detection_speech_threshold: Option<i32>,
/// The number of milliseconds of silence after speech activity at which point the speech activity is considered complete. Possible Values: 500-5000. Default: 1200.
pub machine_detection_speech_end_threshold: Option<i32>,
/// The number of milliseconds of initial silence after which an `unknown` AnsweredBy result will be returned. Possible Values: 2000-10000. Default: 5000.
pub machine_detection_silence_timeout: Option<i32>,
/// 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`.
pub async_amd: Option<String>,
/// 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.
pub async_amd_status_callback: Option<String>,
/// The HTTP method we should use when calling the `async_amd_status_callback` URL. Can be: `GET` or `POST` and the default is `POST`.
pub async_amd_status_callback_method: Option<String>,
/// 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)
pub byoc: Option<String>,
/// 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)
pub call_reason: Option<String>,
/// 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.
pub call_token: Option<String>,
/// 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.
pub recording_track: Option<String>,
/// The maximum duration of the call in seconds. Constraints depend on account and configuration.
pub time_limit: Option<i32>,
/// 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).
pub url: Option<String>,
/// 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.
pub twiml: Option<String>,
/// The SID of the Application resource that will handle the call, if the call will be handled by an application.
pub application_sid: Option<String>
}
/// struct for passing parameters to the method [`delete_call`]
#[derive(Clone, Debug)]
pub struct DeleteCallParams {
/// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to delete.
pub account_sid: String,
/// The Twilio-provided Call SID that uniquely identifies the Call resource to delete
pub sid: String
}
/// struct for passing parameters to the method [`fetch_call`]
#[derive(Clone, Debug)]
pub struct FetchCallParams {
/// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to fetch.
pub account_sid: String,
/// The SID of the Call resource to fetch.
pub sid: String
}
/// struct for passing parameters to the method [`list_call`]
#[derive(Clone, Debug)]
pub struct ListCallParams {
/// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to read.
pub account_sid: String,
/// Only show calls made to this phone number, SIP address, Client identifier or SIM SID.
pub to: Option<String>,
/// Only include calls from this phone number, SIP address, Client identifier or SIM SID.
pub from: Option<String>,
/// Only include calls spawned by calls with this SID.
pub parent_call_sid: Option<String>,
/// The status of the calls to include. Can be: `queued`, `ringing`, `in-progress`, `canceled`, `completed`, `failed`, `busy`, or `no-answer`.
pub status: Option<String>,
/// 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.
pub start_time: Option<String>,
/// 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.
pub start_time_less_than: Option<String>,
/// 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.
pub start_time_greater_than: Option<String>,
/// 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.
pub end_time: Option<String>,
/// 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.
pub end_time_less_than: Option<String>,
/// 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.
pub end_time_greater_than: Option<String>,
/// How many resources to return in each list page. The default is 50, and the maximum is 1000.
pub page_size: Option<i32>,
/// The page index. This value is simply for client state.
pub page: Option<i32>,
/// The page token. This is provided by the API.
pub page_token: Option<String>
}
/// struct for passing parameters to the method [`update_call`]
#[derive(Clone, Debug)]
pub struct UpdateCallParams {
/// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Call resource(s) to update.
pub account_sid: String,
/// The Twilio-provided string that uniquely identifies the Call resource to update
pub sid: String,
/// 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).
pub url: Option<String>,
/// 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.
pub method: Option<String>,
pub status: Option<String>,
/// 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.
pub fallback_url: Option<String>,
/// 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.
pub fallback_method: Option<String>,
/// 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).
pub status_callback: Option<String>,
/// 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.
pub status_callback_method: Option<String>,
/// TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive
pub twiml: Option<String>,
/// The maximum duration of the call in seconds. Constraints depend on account and configuration.
pub time_limit: Option<i32>
}
/// struct for typed errors of method [`create_call`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateCallError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_call`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteCallError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`fetch_call`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FetchCallError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_call`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListCallError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_call`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateCallError {
UnknownValue(serde_json::Value),
}
/// Create a new outgoing call to phones, SIP-enabled endpoints or Twilio Client connections
pub async fn create_call(configuration: &configuration::Configuration, params: CreateCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<CreateCallError>> {
let local_var_configuration = configuration;
// unbox the parameters
let account_sid = params.account_sid;
let to = params.to;
let from = params.from;
let method = params.method;
let fallback_url = params.fallback_url;
let fallback_method = params.fallback_method;
let status_callback = params.status_callback;
let status_callback_event = params.status_callback_event;
let status_callback_method = params.status_callback_method;
let send_digits = params.send_digits;
let timeout = params.timeout;
let record = params.record;
let recording_channels = params.recording_channels;
let recording_status_callback = params.recording_status_callback;
let recording_status_callback_method = params.recording_status_callback_method;
let sip_auth_username = params.sip_auth_username;
let sip_auth_password = params.sip_auth_password;
let machine_detection = params.machine_detection;
let machine_detection_timeout = params.machine_detection_timeout;
let recording_status_callback_event = params.recording_status_callback_event;
let trim = params.trim;
let caller_id = params.caller_id;
let machine_detection_speech_threshold = params.machine_detection_speech_threshold;
let machine_detection_speech_end_threshold = params.machine_detection_speech_end_threshold;
let machine_detection_silence_timeout = params.machine_detection_silence_timeout;
let async_amd = params.async_amd;
let async_amd_status_callback = params.async_amd_status_callback;
let async_amd_status_callback_method = params.async_amd_status_callback_method;
let byoc = params.byoc;
let call_reason = params.call_reason;
let call_token = params.call_token;
let recording_track = params.recording_track;
let time_limit = params.time_limit;
let url = params.url;
let twiml = params.twiml;
let application_sid = params.application_sid;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
let mut local_var_form_params = std::collections::HashMap::new();
local_var_form_params.insert("To", to.to_string());
local_var_form_params.insert("From", from.to_string());
if let Some(local_var_param_value) = method {
local_var_form_params.insert("Method", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = fallback_url {
local_var_form_params.insert("FallbackUrl", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = fallback_method {
local_var_form_params.insert("FallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = status_callback {
local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = status_callback_event {
local_var_form_params.insert("StatusCallbackEvent", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
}
if let Some(local_var_param_value) = status_callback_method {
local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = send_digits {
local_var_form_params.insert("SendDigits", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = timeout {
local_var_form_params.insert("Timeout", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = record {
local_var_form_params.insert("Record", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = recording_channels {
local_var_form_params.insert("RecordingChannels", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = recording_status_callback {
local_var_form_params.insert("RecordingStatusCallback", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = recording_status_callback_method {
local_var_form_params.insert("RecordingStatusCallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = sip_auth_username {
local_var_form_params.insert("SipAuthUsername", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = sip_auth_password {
local_var_form_params.insert("SipAuthPassword", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = machine_detection {
local_var_form_params.insert("MachineDetection", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = machine_detection_timeout {
local_var_form_params.insert("MachineDetectionTimeout", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = recording_status_callback_event {
local_var_form_params.insert("RecordingStatusCallbackEvent", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
}
if let Some(local_var_param_value) = trim {
local_var_form_params.insert("Trim", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = caller_id {
local_var_form_params.insert("CallerId", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = machine_detection_speech_threshold {
local_var_form_params.insert("MachineDetectionSpeechThreshold", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = machine_detection_speech_end_threshold {
local_var_form_params.insert("MachineDetectionSpeechEndThreshold", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = machine_detection_silence_timeout {
local_var_form_params.insert("MachineDetectionSilenceTimeout", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = async_amd {
local_var_form_params.insert("AsyncAmd", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = async_amd_status_callback {
local_var_form_params.insert("AsyncAmdStatusCallback", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = async_amd_status_callback_method {
local_var_form_params.insert("AsyncAmdStatusCallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = byoc {
local_var_form_params.insert("Byoc", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = call_reason {
local_var_form_params.insert("CallReason", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = call_token {
local_var_form_params.insert("CallToken", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = recording_track {
local_var_form_params.insert("RecordingTrack", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = time_limit {
local_var_form_params.insert("TimeLimit", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = url {
local_var_form_params.insert("Url", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = twiml {
local_var_form_params.insert("Twiml", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = application_sid {
local_var_form_params.insert("ApplicationSid", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreateCallError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
/// Delete a Call record from your account. Once the record is deleted, it will no longer appear in the API and Account Portal logs.
pub async fn delete_call(configuration: &configuration::Configuration, params: DeleteCallParams) -> Result<(), Error<DeleteCallError>> {
let local_var_configuration = configuration;
// unbox the parameters
let account_sid = params.account_sid;
let sid = params.sid;
let local_var_client = &local_var_configuration.client;
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));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<DeleteCallError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
/// Fetch the call specified by the provided Call SID
pub async fn fetch_call(configuration: &configuration::Configuration, params: FetchCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<FetchCallError>> {
let local_var_configuration = configuration;
// unbox the parameters
let account_sid = params.account_sid;
let sid = params.sid;
let local_var_client = &local_var_configuration.client;
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));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FetchCallError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
/// Retrieves a collection of calls made to and from your account
pub async fn list_call(configuration: &configuration::Configuration, params: ListCallParams) -> Result<models::ListCallResponse, Error<ListCallError>> {
let local_var_configuration = configuration;
// unbox the parameters
let account_sid = params.account_sid;
let to = params.to;
let from = params.from;
let parent_call_sid = params.parent_call_sid;
let status = params.status;
let start_time = params.start_time;
let start_time_less_than = params.start_time_less_than;
let start_time_greater_than = params.start_time_greater_than;
let end_time = params.end_time;
let end_time_less_than = params.end_time_less_than;
let end_time_greater_than = params.end_time_greater_than;
let page_size = params.page_size;
let page = params.page;
let page_token = params.page_token;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Calls.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_str) = to {
local_var_req_builder = local_var_req_builder.query(&[("To", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = from {
local_var_req_builder = local_var_req_builder.query(&[("From", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = parent_call_sid {
local_var_req_builder = local_var_req_builder.query(&[("ParentCallSid", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = status {
local_var_req_builder = local_var_req_builder.query(&[("Status", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = start_time {
local_var_req_builder = local_var_req_builder.query(&[("StartTime", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = start_time_less_than {
local_var_req_builder = local_var_req_builder.query(&[("StartTime<", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = start_time_greater_than {
local_var_req_builder = local_var_req_builder.query(&[("StartTime>", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = end_time {
local_var_req_builder = local_var_req_builder.query(&[("EndTime", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = end_time_less_than {
local_var_req_builder = local_var_req_builder.query(&[("EndTime<", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = end_time_greater_than {
local_var_req_builder = local_var_req_builder.query(&[("EndTime>", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page_size {
local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page {
local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = page_token {
local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<ListCallError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
/// Initiates a call redirect or terminates a call
pub async fn update_call(configuration: &configuration::Configuration, params: UpdateCallParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodCall, Error<UpdateCallError>> {
let local_var_configuration = configuration;
// unbox the parameters
let account_sid = params.account_sid;
let sid = params.sid;
let url = params.url;
let method = params.method;
let status = params.status;
let fallback_url = params.fallback_url;
let fallback_method = params.fallback_method;
let status_callback = params.status_callback;
let status_callback_method = params.status_callback_method;
let twiml = params.twiml;
let time_limit = params.time_limit;
let local_var_client = &local_var_configuration.client;
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));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
};
let mut local_var_form_params = std::collections::HashMap::new();
if let Some(local_var_param_value) = url {
local_var_form_params.insert("Url", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = method {
local_var_form_params.insert("Method", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = status {
local_var_form_params.insert("Status", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = fallback_url {
local_var_form_params.insert("FallbackUrl", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = fallback_method {
local_var_form_params.insert("FallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = status_callback {
local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = status_callback_method {
local_var_form_params.insert("StatusCallbackMethod", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = twiml {
local_var_form_params.insert("Twiml", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = time_limit {
local_var_form_params.insert("TimeLimit", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UpdateCallError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}