twilio_rust_openapi/apis/
api20100401_message_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_message`]
18#[derive(Clone, Debug)]
19pub struct CreateMessageParams {
20    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) creating the Message resource.
21    pub account_sid: String,
22    /// The recipient's phone number in [E.164](https://www.twilio.com/docs/glossary/what-e164) format (for SMS/MMS) or [channel address](https://www.twilio.com/docs/messaging/channels), e.g. `whatsapp:+15552229999`.
23    pub to: String,
24    /// The URL of the endpoint to which Twilio sends [Message status callback requests](https://www.twilio.com/docs/sms/api/message-resource#twilios-request-to-the-statuscallback-url). URL must contain a valid hostname and underscores are not allowed. If you include this parameter with the `messaging_service_sid`, Twilio uses this URL instead of the Status Callback URL of the [Messaging Service](https://www.twilio.com/docs/messaging/api/service-resource). 
25    pub status_callback: Option<String>,
26    /// The SID of the associated [TwiML Application](https://www.twilio.com/docs/usage/api/applications). [Message status callback requests](https://www.twilio.com/docs/sms/api/message-resource#twilios-request-to-the-statuscallback-url) are sent to the TwiML App's `message_status_callback` URL. Note that the `status_callback` parameter of a request takes priority over the `application_sid` parameter; if both are included `application_sid` is ignored.
27    pub application_sid: Option<String>,
28    /// [OBSOLETE] This parameter will no longer have any effect as of 2024-06-03.
29    pub max_price: Option<f64>,
30    /// Boolean indicating whether or not you intend to provide delivery confirmation feedback to Twilio (used in conjunction with the [Message Feedback subresource](https://www.twilio.com/docs/sms/api/message-feedback-resource)). Default value is `false`.
31    pub provide_feedback: Option<bool>,
32    /// Total number of attempts made (including this request) to send the message regardless of the provider used
33    pub attempt: Option<i32>,
34    /// The maximum length in seconds that the Message can remain in Twilio's outgoing message queue. If a queued Message exceeds the `validity_period`, the Message is not sent. Accepted values are integers from `1` to `36000`. Default value is `36000`. A `validity_period` greater than `5` is recommended. [Learn more about the validity period](https://www.twilio.com/blog/take-more-control-of-outbound-messages-using-validity-period-html)
35    pub validity_period: Option<i32>,
36    /// Reserved
37    pub force_delivery: Option<bool>,
38    pub content_retention: Option<String>,
39    pub address_retention: Option<String>,
40    /// Whether to detect Unicode characters that have a similar GSM-7 character and replace them. Can be: `true` or `false`.
41    pub smart_encoded: Option<bool>,
42    /// Rich actions for non-SMS/MMS channels. Used for [sending location in WhatsApp messages](https://www.twilio.com/docs/whatsapp/message-features#location-messages-with-whatsapp).
43    pub persistent_action: Option<Vec<String>>,
44    /// For Messaging Services with [Link Shortening configured](https://www.twilio.com/docs/messaging/features/link-shortening) only: A Boolean indicating whether or not Twilio should shorten links in the `body` of the Message. Default value is `false`. If `true`, the `messaging_service_sid` parameter must also be provided.
45    pub shorten_urls: Option<bool>,
46    pub schedule_type: Option<String>,
47    /// The time that Twilio will send the message. Must be in ISO 8601 format.
48    pub send_at: Option<String>,
49    /// If set to `true`, Twilio delivers the message as a single MMS message, regardless of the presence of media.
50    pub send_as_mms: Option<bool>,
51    /// For [Content Editor/API](https://www.twilio.com/docs/content) only: Key-value pairs of [Template variables](https://www.twilio.com/docs/content/using-variables-with-content-api) and their substitution values. `content_sid` parameter must also be provided. If values are not defined in the `content_variables` parameter, the [Template's default placeholder values](https://www.twilio.com/docs/content/content-api-resources#create-templates) are used.
52    pub content_variables: Option<String>,
53    pub risk_check: Option<String>,
54    /// The sender's Twilio phone number (in [E.164](https://en.wikipedia.org/wiki/E.164) format), [alphanumeric sender ID](https://www.twilio.com/docs/sms/quickstart), [Wireless SIM](https://www.twilio.com/docs/iot/wireless/programmable-wireless-send-machine-machine-sms-commands), [short code](https://www.twilio.com/en-us/messaging/channels/sms/short-codes), or [channel address](https://www.twilio.com/docs/messaging/channels) (e.g., `whatsapp:+15554449999`). The value of the `from` parameter must be a sender that is hosted within Twilio and belongs to the Account creating the Message. If you are using `messaging_service_sid`, this parameter can be empty (Twilio assigns a `from` value from the Messaging Service's Sender Pool) or you can provide a specific sender from your Sender Pool.
55    pub from: Option<String>,
56    /// The SID of the [Messaging Service](https://www.twilio.com/docs/messaging/services) you want to associate with the Message. When this parameter is provided and the `from` parameter is omitted, Twilio selects the optimal sender from the Messaging Service's Sender Pool. You may also provide a `from` parameter if you want to use a specific Sender from the Sender Pool.
57    pub messaging_service_sid: Option<String>,
58    /// The text content of the outgoing message. Can be up to 1,600 characters in length. SMS only: If the `body` contains more than 160 [GSM-7](https://www.twilio.com/docs/glossary/what-is-gsm-7-character-encoding) characters (or 70 [UCS-2](https://www.twilio.com/docs/glossary/what-is-ucs-2-character-encoding) characters), the message is segmented and charged accordingly. For long `body` text, consider using the [send_as_mms parameter](https://www.twilio.com/blog/mms-for-long-text-messages).
59    pub body: Option<String>,
60    /// The URL of media to include in the Message content. `jpeg`, `jpg`, `gif`, and `png` file types are fully supported by Twilio and content is formatted for delivery on destination devices. The media size limit is 5 MB for supported file types (`jpeg`, `jpg`, `png`, `gif`) and 500 KB for [other types](https://www.twilio.com/docs/messaging/guides/accepted-mime-types) of accepted media. To send more than one image in the message, provide multiple `media_url` parameters in the POST request. You can include up to ten `media_url` parameters per message. [International](https://support.twilio.com/hc/en-us/articles/223179808-Sending-and-receiving-MMS-messages) and [carrier](https://support.twilio.com/hc/en-us/articles/223133707-Is-MMS-supported-for-all-carriers-in-US-and-Canada-) limits apply.
61    pub media_url: Option<Vec<String>>,
62    /// For [Content Editor/API](https://www.twilio.com/docs/content) only: The SID of the Content Template to be used with the Message, e.g., `HXXXXXXXXXXXXXXXXXXXXXXXXXXXXX`. If this parameter is not provided, a Content Template is not used. Find the SID in the Console on the Content Editor page. For Content API users, the SID is found in Twilio's response when [creating the Template](https://www.twilio.com/docs/content/content-api-resources#create-templates) or by [fetching your Templates](https://www.twilio.com/docs/content/content-api-resources#fetch-all-content-resources).
63    pub content_sid: Option<String>
64}
65
66/// struct for passing parameters to the method [`delete_message`]
67#[derive(Clone, Debug)]
68pub struct DeleteMessageParams {
69    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) associated with the Message resource
70    pub account_sid: String,
71    /// The SID of the Message resource you wish to delete
72    pub sid: String
73}
74
75/// struct for passing parameters to the method [`fetch_message`]
76#[derive(Clone, Debug)]
77pub struct FetchMessageParams {
78    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) associated with the Message resource
79    pub account_sid: String,
80    /// The SID of the Message resource to be fetched
81    pub sid: String
82}
83
84/// struct for passing parameters to the method [`list_message`]
85#[derive(Clone, Debug)]
86pub struct ListMessageParams {
87    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) associated with the Message resources.
88    pub account_sid: String,
89    /// Filter by recipient. For example: Set this `to` parameter to `+15558881111` to retrieve a list of Message resources with `to` properties of `+15558881111`
90    pub to: Option<String>,
91    /// Filter by sender. For example: Set this `from` parameter to `+15552229999` to retrieve a list of Message resources with `from` properties of `+15552229999`
92    pub from: Option<String>,
93    /// Filter by Message `sent_date`. Accepts GMT dates in the following formats: `YYYY-MM-DD` (to find Messages with a specific `sent_date`), `<=YYYY-MM-DD` (to find Messages with `sent_date`s on and before a specific date), and `>=YYYY-MM-DD` (to find Messages with `sent_dates` on and after a specific date).
94    pub date_sent: Option<String>,
95    /// Filter by Message `sent_date`. Accepts GMT dates in the following formats: `YYYY-MM-DD` (to find Messages with a specific `sent_date`), `<=YYYY-MM-DD` (to find Messages with `sent_date`s on and before a specific date), and `>=YYYY-MM-DD` (to find Messages with `sent_dates` on and after a specific date).
96    pub date_sent_less_than: Option<String>,
97    /// Filter by Message `sent_date`. Accepts GMT dates in the following formats: `YYYY-MM-DD` (to find Messages with a specific `sent_date`), `<=YYYY-MM-DD` (to find Messages with `sent_date`s on and before a specific date), and `>=YYYY-MM-DD` (to find Messages with `sent_dates` on and after a specific date).
98    pub date_sent_greater_than: Option<String>,
99    /// How many resources to return in each list page. The default is 50, and the maximum is 1000.
100    pub page_size: Option<i32>,
101    /// The page index. This value is simply for client state.
102    pub page: Option<i32>,
103    /// The page token. This is provided by the API.
104    pub page_token: Option<String>
105}
106
107/// struct for passing parameters to the method [`update_message`]
108#[derive(Clone, Debug)]
109pub struct UpdateMessageParams {
110    /// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the Message resources to update.
111    pub account_sid: String,
112    /// The SID of the Message resource to be updated
113    pub sid: String,
114    /// The new `body` of the Message resource. To redact the text content of a Message, this parameter's value must be an empty string
115    pub body: Option<String>,
116    pub status: Option<String>
117}
118
119
120/// struct for typed errors of method [`create_message`]
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(untagged)]
123pub enum CreateMessageError {
124    UnknownValue(serde_json::Value),
125}
126
127/// struct for typed errors of method [`delete_message`]
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(untagged)]
130pub enum DeleteMessageError {
131    UnknownValue(serde_json::Value),
132}
133
134/// struct for typed errors of method [`fetch_message`]
135#[derive(Debug, Clone, Serialize, Deserialize)]
136#[serde(untagged)]
137pub enum FetchMessageError {
138    UnknownValue(serde_json::Value),
139}
140
141/// struct for typed errors of method [`list_message`]
142#[derive(Debug, Clone, Serialize, Deserialize)]
143#[serde(untagged)]
144pub enum ListMessageError {
145    UnknownValue(serde_json::Value),
146}
147
148/// struct for typed errors of method [`update_message`]
149#[derive(Debug, Clone, Serialize, Deserialize)]
150#[serde(untagged)]
151pub enum UpdateMessageError {
152    UnknownValue(serde_json::Value),
153}
154
155
156/// Send a message
157pub async fn create_message(configuration: &configuration::Configuration, params: CreateMessageParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodMessage, Error<CreateMessageError>> {
158    let local_var_configuration = configuration;
159
160    // unbox the parameters
161    let account_sid = params.account_sid;
162    let to = params.to;
163    let status_callback = params.status_callback;
164    let application_sid = params.application_sid;
165    let max_price = params.max_price;
166    let provide_feedback = params.provide_feedback;
167    let attempt = params.attempt;
168    let validity_period = params.validity_period;
169    let force_delivery = params.force_delivery;
170    let content_retention = params.content_retention;
171    let address_retention = params.address_retention;
172    let smart_encoded = params.smart_encoded;
173    let persistent_action = params.persistent_action;
174    let shorten_urls = params.shorten_urls;
175    let schedule_type = params.schedule_type;
176    let send_at = params.send_at;
177    let send_as_mms = params.send_as_mms;
178    let content_variables = params.content_variables;
179    let risk_check = params.risk_check;
180    let from = params.from;
181    let messaging_service_sid = params.messaging_service_sid;
182    let body = params.body;
183    let media_url = params.media_url;
184    let content_sid = params.content_sid;
185
186
187    let local_var_client = &local_var_configuration.client;
188
189    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
190    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
191
192    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194    }
195    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
196        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
197    };
198    let mut local_var_form_params = std::collections::HashMap::new();
199    local_var_form_params.insert("To", to.to_string());
200    if let Some(local_var_param_value) = status_callback {
201        local_var_form_params.insert("StatusCallback", local_var_param_value.to_string());
202    }
203    if let Some(local_var_param_value) = application_sid {
204        local_var_form_params.insert("ApplicationSid", local_var_param_value.to_string());
205    }
206    if let Some(local_var_param_value) = max_price {
207        local_var_form_params.insert("MaxPrice", local_var_param_value.to_string());
208    }
209    if let Some(local_var_param_value) = provide_feedback {
210        local_var_form_params.insert("ProvideFeedback", local_var_param_value.to_string());
211    }
212    if let Some(local_var_param_value) = attempt {
213        local_var_form_params.insert("Attempt", local_var_param_value.to_string());
214    }
215    if let Some(local_var_param_value) = validity_period {
216        local_var_form_params.insert("ValidityPeriod", local_var_param_value.to_string());
217    }
218    if let Some(local_var_param_value) = force_delivery {
219        local_var_form_params.insert("ForceDelivery", local_var_param_value.to_string());
220    }
221    if let Some(local_var_param_value) = content_retention {
222        local_var_form_params.insert("ContentRetention", local_var_param_value.to_string());
223    }
224    if let Some(local_var_param_value) = address_retention {
225        local_var_form_params.insert("AddressRetention", local_var_param_value.to_string());
226    }
227    if let Some(local_var_param_value) = smart_encoded {
228        local_var_form_params.insert("SmartEncoded", local_var_param_value.to_string());
229    }
230    if let Some(local_var_param_value) = persistent_action {
231        local_var_form_params.insert("PersistentAction", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
232    }
233    if let Some(local_var_param_value) = shorten_urls {
234        local_var_form_params.insert("ShortenUrls", local_var_param_value.to_string());
235    }
236    if let Some(local_var_param_value) = schedule_type {
237        local_var_form_params.insert("ScheduleType", local_var_param_value.to_string());
238    }
239    if let Some(local_var_param_value) = send_at {
240        local_var_form_params.insert("SendAt", local_var_param_value.to_string());
241    }
242    if let Some(local_var_param_value) = send_as_mms {
243        local_var_form_params.insert("SendAsMms", local_var_param_value.to_string());
244    }
245    if let Some(local_var_param_value) = content_variables {
246        local_var_form_params.insert("ContentVariables", local_var_param_value.to_string());
247    }
248    if let Some(local_var_param_value) = risk_check {
249        local_var_form_params.insert("RiskCheck", local_var_param_value.to_string());
250    }
251    if let Some(local_var_param_value) = from {
252        local_var_form_params.insert("From", local_var_param_value.to_string());
253    }
254    if let Some(local_var_param_value) = messaging_service_sid {
255        local_var_form_params.insert("MessagingServiceSid", local_var_param_value.to_string());
256    }
257    if let Some(local_var_param_value) = body {
258        local_var_form_params.insert("Body", local_var_param_value.to_string());
259    }
260    if let Some(local_var_param_value) = media_url {
261        local_var_form_params.insert("MediaUrl", local_var_param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
262    }
263    if let Some(local_var_param_value) = content_sid {
264        local_var_form_params.insert("ContentSid", local_var_param_value.to_string());
265    }
266    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
267
268    let local_var_req = local_var_req_builder.build()?;
269    let local_var_resp = local_var_client.execute(local_var_req).await?;
270
271    let local_var_status = local_var_resp.status();
272    let local_var_content = local_var_resp.text().await?;
273
274    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
275        serde_json::from_str(&local_var_content).map_err(Error::from)
276    } else {
277        let local_var_entity: Option<CreateMessageError> = serde_json::from_str(&local_var_content).ok();
278        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
279        Err(Error::ResponseError(local_var_error))
280    }
281}
282
283/// Deletes a Message resource from your account
284pub async fn delete_message(configuration: &configuration::Configuration, params: DeleteMessageParams) -> Result<(), Error<DeleteMessageError>> {
285    let local_var_configuration = configuration;
286
287    // unbox the parameters
288    let account_sid = params.account_sid;
289    let sid = params.sid;
290
291
292    let local_var_client = &local_var_configuration.client;
293
294    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
295    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
296
297    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
298        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
299    }
300    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
301        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
302    };
303
304    let local_var_req = local_var_req_builder.build()?;
305    let local_var_resp = local_var_client.execute(local_var_req).await?;
306
307    let local_var_status = local_var_resp.status();
308    let local_var_content = local_var_resp.text().await?;
309
310    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
311        Ok(())
312    } else {
313        let local_var_entity: Option<DeleteMessageError> = serde_json::from_str(&local_var_content).ok();
314        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
315        Err(Error::ResponseError(local_var_error))
316    }
317}
318
319/// Fetch a specific Message
320pub async fn fetch_message(configuration: &configuration::Configuration, params: FetchMessageParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodMessage, Error<FetchMessageError>> {
321    let local_var_configuration = configuration;
322
323    // unbox the parameters
324    let account_sid = params.account_sid;
325    let sid = params.sid;
326
327
328    let local_var_client = &local_var_configuration.client;
329
330    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
331    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
332
333    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
334        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
335    }
336    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
337        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
338    };
339
340    let local_var_req = local_var_req_builder.build()?;
341    let local_var_resp = local_var_client.execute(local_var_req).await?;
342
343    let local_var_status = local_var_resp.status();
344    let local_var_content = local_var_resp.text().await?;
345
346    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
347        serde_json::from_str(&local_var_content).map_err(Error::from)
348    } else {
349        let local_var_entity: Option<FetchMessageError> = serde_json::from_str(&local_var_content).ok();
350        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
351        Err(Error::ResponseError(local_var_error))
352    }
353}
354
355/// Retrieve a list of Message resources associated with a Twilio Account
356pub async fn list_message(configuration: &configuration::Configuration, params: ListMessageParams) -> Result<models::ListMessageResponse, Error<ListMessageError>> {
357    let local_var_configuration = configuration;
358
359    // unbox the parameters
360    let account_sid = params.account_sid;
361    let to = params.to;
362    let from = params.from;
363    let date_sent = params.date_sent;
364    let date_sent_less_than = params.date_sent_less_than;
365    let date_sent_greater_than = params.date_sent_greater_than;
366    let page_size = params.page_size;
367    let page = params.page;
368    let page_token = params.page_token;
369
370
371    let local_var_client = &local_var_configuration.client;
372
373    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid));
374    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
375
376    if let Some(ref local_var_str) = to {
377        local_var_req_builder = local_var_req_builder.query(&[("To", &local_var_str.to_string())]);
378    }
379    if let Some(ref local_var_str) = from {
380        local_var_req_builder = local_var_req_builder.query(&[("From", &local_var_str.to_string())]);
381    }
382    if let Some(ref local_var_str) = date_sent {
383        local_var_req_builder = local_var_req_builder.query(&[("DateSent", &local_var_str.to_string())]);
384    }
385    if let Some(ref local_var_str) = date_sent_less_than {
386        local_var_req_builder = local_var_req_builder.query(&[("DateSent<", &local_var_str.to_string())]);
387    }
388    if let Some(ref local_var_str) = date_sent_greater_than {
389        local_var_req_builder = local_var_req_builder.query(&[("DateSent>", &local_var_str.to_string())]);
390    }
391    if let Some(ref local_var_str) = page_size {
392        local_var_req_builder = local_var_req_builder.query(&[("PageSize", &local_var_str.to_string())]);
393    }
394    if let Some(ref local_var_str) = page {
395        local_var_req_builder = local_var_req_builder.query(&[("Page", &local_var_str.to_string())]);
396    }
397    if let Some(ref local_var_str) = page_token {
398        local_var_req_builder = local_var_req_builder.query(&[("PageToken", &local_var_str.to_string())]);
399    }
400    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
401        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
402    }
403    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
404        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
405    };
406
407    let local_var_req = local_var_req_builder.build()?;
408    let local_var_resp = local_var_client.execute(local_var_req).await?;
409
410    let local_var_status = local_var_resp.status();
411    let local_var_content = local_var_resp.text().await?;
412
413    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
414        serde_json::from_str(&local_var_content).map_err(Error::from)
415    } else {
416        let local_var_entity: Option<ListMessageError> = serde_json::from_str(&local_var_content).ok();
417        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
418        Err(Error::ResponseError(local_var_error))
419    }
420}
421
422/// Update a Message resource (used to redact Message `body` text and to cancel not-yet-sent messages)
423pub async fn update_message(configuration: &configuration::Configuration, params: UpdateMessageParams) -> Result<models::ApiPeriodV2010PeriodAccountPeriodMessage, Error<UpdateMessageError>> {
424    let local_var_configuration = configuration;
425
426    // unbox the parameters
427    let account_sid = params.account_sid;
428    let sid = params.sid;
429    let body = params.body;
430    let status = params.status;
431
432
433    let local_var_client = &local_var_configuration.client;
434
435    let local_var_uri_str = format!("{}/2010-04-01/Accounts/{AccountSid}/Messages/{Sid}.json", local_var_configuration.base_path, AccountSid=crate::apis::urlencode(account_sid), Sid=crate::apis::urlencode(sid));
436    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
437
438    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
439        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
440    }
441    if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
442        local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
443    };
444    let mut local_var_form_params = std::collections::HashMap::new();
445    if let Some(local_var_param_value) = body {
446        local_var_form_params.insert("Body", local_var_param_value.to_string());
447    }
448    if let Some(local_var_param_value) = status {
449        local_var_form_params.insert("Status", local_var_param_value.to_string());
450    }
451    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);
452
453    let local_var_req = local_var_req_builder.build()?;
454    let local_var_resp = local_var_client.execute(local_var_req).await?;
455
456    let local_var_status = local_var_resp.status();
457    let local_var_content = local_var_resp.text().await?;
458
459    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
460        serde_json::from_str(&local_var_content).map_err(Error::from)
461    } else {
462        let local_var_entity: Option<UpdateMessageError> = serde_json::from_str(&local_var_content).ok();
463        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
464        Err(Error::ResponseError(local_var_error))
465    }
466}
467