Refactoring
swoosh pr / Check (pull_request) Successful in 2m9s
swoosh pr / Rustfmt (pull_request) Successful in 34s
swoosh pr / Clippy (pull_request) Successful in 2m7s
Release Tagging / release (pull_request) Successful in 32s

This commit is contained in:
2026-06-20 16:58:06 -04:00
parent 9faa9fd2e7
commit 9e8ec15910
+21 -7
View File
@@ -1,5 +1,7 @@
pub mod types; pub mod types;
/// Converts the response into a json value
/// That way you do not need to share swoosh's dependency
pub async fn response_to_json(response: reqwest::Response) -> serde_json::Value { pub async fn response_to_json(response: reqwest::Response) -> serde_json::Value {
match response.json().await { match response.json().await {
Ok(json_body) => json_body, Ok(json_body) => json_body,
@@ -56,7 +58,12 @@ pub async fn send_message(
} }
} }
fn init_params(contact: &textsender_models::contact::Contact, message: &textsender_models::message::Message, config: &textsender_models::config::auxiliary::TwilioConfig, param: &crate::twilio::types::Parameters) -> std::collections::HashMap<String, String> { fn init_params(
contact: &textsender_models::contact::Contact,
message: &textsender_models::message::Message,
config: &textsender_models::config::auxiliary::TwilioConfig,
param: &crate::twilio::types::Parameters,
) -> std::collections::HashMap<String, String> {
let now = time::OffsetDateTime::now_utc(); let now = time::OffsetDateTime::now_utc();
let mut params = std::collections::HashMap::new(); let mut params = std::collections::HashMap::new();
params.insert(String::from("To"), contact.phone_number.clone()); params.insert(String::from("To"), contact.phone_number.clone());
@@ -70,17 +77,24 @@ fn init_params(contact: &textsender_models::contact::Contact, message: &textsend
Some(date_value) => date_value.to_string(), Some(date_value) => date_value.to_string(),
None => String::new(), None => String::new(),
}; };
if param.schedule && is_scheduleable(&Some(now), &param.schedule_at) { let scheduled_at = match param.schedule_at {
Some(s) => s,
None => time::OffsetDateTime::now_utc(),
};
if param.schedule && is_scheduleable(Some(&now), Some(&scheduled_at)) {
params.insert(String::from("ScheduleType"), String::from("fixed")); params.insert(String::from("ScheduleType"), String::from("fixed"));
params.insert(String::from("SendAt"), date); params.insert(String::from("SendAt"), date);
} }
params.insert(String::from("SendAsMms"), String::from("true")); params.insert(String::from("SendAsMms"), String::from("true"));
params.insert(String::from("RiskCheck"), String::from("enable")); params.insert(String::from("RiskCheck"), String::from("enable"));
params.insert(String::from("From"), config.phone_number.clone()); params.insert(String::from("From"), config.phone_number.clone());
params.insert(String::from("MessagingServiceSid"), config.service_sid.clone()); params.insert(
String::from("MessagingServiceSid"),
config.service_sid.clone(),
);
params.insert(String::from("Body"), message.content.clone()); params.insert(String::from("Body"), message.content.clone());
/* /*
let mut params = std::collections::HashMap::new(); let mut params = std::collections::HashMap::new();
params.insert("StatusCallback", "http://OjQozHznkhNTTR.vpnrM1zdXFuiQ"); params.insert("StatusCallback", "http://OjQozHznkhNTTR.vpnrM1zdXFuiQ");
params.insert("MaxPrice", "1"); params.insert("MaxPrice", "1");
@@ -96,7 +110,7 @@ fn init_params(contact: &textsender_models::contact::Contact, message: &textsend
params.insert("ShortenUrls", "true"); params.insert("ShortenUrls", "true");
params.insert("SendAsMms", "true"); params.insert("SendAsMms", "true");
params.insert("RiskCheck", "enable"); params.insert("RiskCheck", "enable");
*/ */
params params
} }
@@ -114,8 +128,8 @@ fn generate_auth(
const DEFAULT_SCHEDULING_SECONDS: i64 = 300; const DEFAULT_SCHEDULING_SECONDS: i64 = 300;
fn is_scheduleable( fn is_scheduleable(
now: &Option<time::OffsetDateTime>, now: Option<&time::OffsetDateTime>,
scheduled: &Option<time::OffsetDateTime>, scheduled: Option<&time::OffsetDateTime>,
) -> bool { ) -> bool {
match scheduled { match scheduled {
Some(schedule_at) => { Some(schedule_at) => {