Refactoring
This commit is contained in:
+19
-5
@@ -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,14 +77,21 @@ 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), ¶m.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());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -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