Refactoring
This commit is contained in:
+57
-43
@@ -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,49 +58,61 @@ 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(
|
||||||
let now = time::OffsetDateTime::now_utc();
|
contact: &textsender_models::contact::Contact,
|
||||||
let mut params = std::collections::HashMap::new();
|
message: &textsender_models::message::Message,
|
||||||
params.insert(String::from("To"), contact.phone_number.clone());
|
config: &textsender_models::config::auxiliary::TwilioConfig,
|
||||||
params.insert(String::from("ProvideFeedback"), String::from("true"));
|
param: &crate::twilio::types::Parameters,
|
||||||
params.insert(String::from("ForceDelivery"), String::from("false"));
|
) -> std::collections::HashMap<String, String> {
|
||||||
params.insert(String::from("ContentRetention"), String::from("retain"));
|
let now = time::OffsetDateTime::now_utc();
|
||||||
params.insert(String::from("AddressRetention"), String::from("obfuscate"));
|
|
||||||
params.insert(String::from("SmartEncoded"), String::from("true"));
|
|
||||||
params.insert(String::from("ShortenUrls"), String::from("true"));
|
|
||||||
let date = match param.schedule_at {
|
|
||||||
Some(date_value) => date_value.to_string(),
|
|
||||||
None => String::new(),
|
|
||||||
};
|
|
||||||
if param.schedule && is_scheduleable(&Some(now), ¶m.schedule_at) {
|
|
||||||
params.insert(String::from("ScheduleType"), String::from("fixed"));
|
|
||||||
params.insert(String::from("SendAt"), date);
|
|
||||||
}
|
|
||||||
params.insert(String::from("SendAsMms"), String::from("true"));
|
|
||||||
params.insert(String::from("RiskCheck"), String::from("enable"));
|
|
||||||
params.insert(String::from("From"), config.phone_number.clone());
|
|
||||||
params.insert(String::from("MessagingServiceSid"), config.service_sid.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(String::from("To"), contact.phone_number.clone());
|
||||||
params.insert("MaxPrice", "1");
|
params.insert(String::from("ProvideFeedback"), String::from("true"));
|
||||||
params.insert("ProvideFeedback", "true");
|
params.insert(String::from("ForceDelivery"), String::from("false"));
|
||||||
params.insert("Attempt", "5");
|
params.insert(String::from("ContentRetention"), String::from("retain"));
|
||||||
params.insert("ValidityPeriod", "1537");
|
params.insert(String::from("AddressRetention"), String::from("obfuscate"));
|
||||||
params.insert("ForceDelivery", "false");
|
params.insert(String::from("SmartEncoded"), String::from("true"));
|
||||||
params.insert("ContentRetention", "retain");
|
params.insert(String::from("ShortenUrls"), String::from("true"));
|
||||||
params.insert("AddressRetention", "obfuscate");
|
let date = match param.schedule_at {
|
||||||
params.insert("SmartEncoded", "true");
|
Some(date_value) => date_value.to_string(),
|
||||||
params.insert("PersistentAction", "string");
|
None => String::new(),
|
||||||
params.insert("PersistentAction", "string");
|
};
|
||||||
params.insert("ShortenUrls", "true");
|
let scheduled_at = match param.schedule_at {
|
||||||
params.insert("SendAsMms", "true");
|
Some(s) => s,
|
||||||
params.insert("RiskCheck", "enable");
|
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("SendAt"), date);
|
||||||
|
}
|
||||||
|
params.insert(String::from("SendAsMms"), String::from("true"));
|
||||||
|
params.insert(String::from("RiskCheck"), String::from("enable"));
|
||||||
|
params.insert(String::from("From"), config.phone_number.clone());
|
||||||
|
params.insert(
|
||||||
|
String::from("MessagingServiceSid"),
|
||||||
|
config.service_sid.clone(),
|
||||||
|
);
|
||||||
|
params.insert(String::from("Body"), message.content.clone());
|
||||||
|
|
||||||
params
|
/*
|
||||||
|
let mut params = std::collections::HashMap::new();
|
||||||
|
params.insert("StatusCallback", "http://OjQozHznkhNTTR.vpnrM1zdXFuiQ");
|
||||||
|
params.insert("MaxPrice", "1");
|
||||||
|
params.insert("ProvideFeedback", "true");
|
||||||
|
params.insert("Attempt", "5");
|
||||||
|
params.insert("ValidityPeriod", "1537");
|
||||||
|
params.insert("ForceDelivery", "false");
|
||||||
|
params.insert("ContentRetention", "retain");
|
||||||
|
params.insert("AddressRetention", "obfuscate");
|
||||||
|
params.insert("SmartEncoded", "true");
|
||||||
|
params.insert("PersistentAction", "string");
|
||||||
|
params.insert("PersistentAction", "string");
|
||||||
|
params.insert("ShortenUrls", "true");
|
||||||
|
params.insert("SendAsMms", "true");
|
||||||
|
params.insert("RiskCheck", "enable");
|
||||||
|
*/
|
||||||
|
|
||||||
|
params
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_auth(
|
fn generate_auth(
|
||||||
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user