Migrate #4
+4
-1
@@ -32,7 +32,10 @@ pub async fn parse_config() -> (textsender_models::config::auxiliary::TwilioConf
|
||||
config.phone_number = phone_number_var.value;
|
||||
config.service_sid = service_sid_var.value;
|
||||
let success = {
|
||||
!config.account_sid.is_empty() && !config.auth_token.is_empty() && !config.phone_number.is_empty() && !config.service_sid.is_empty()
|
||||
!config.account_sid.is_empty()
|
||||
&& !config.auth_token.is_empty()
|
||||
&& !config.phone_number.is_empty()
|
||||
&& !config.service_sid.is_empty()
|
||||
};
|
||||
|
||||
(config, success)
|
||||
|
||||
@@ -1 +1,42 @@
|
||||
use textsender_models::config::auxiliary::TwilioConfig;
|
||||
use textsender_models::contact::Contact;
|
||||
use textsender_models::message::Message;
|
||||
|
||||
pub async fn send_messages(
|
||||
config: &TwilioConfig,
|
||||
contacts: &Vec<Contact>,
|
||||
message: &Message,
|
||||
second_interval: u64,
|
||||
) {
|
||||
let long_sleep_limit: i64 = 5;
|
||||
let mut count: i64 = 0;
|
||||
|
||||
for contact in contacts {
|
||||
println!("Sending to: {:?}", contact.phone_number);
|
||||
let param = swoosh::twilio::types::Parameters {
|
||||
schedule: false,
|
||||
schedule_at: None,
|
||||
};
|
||||
match swoosh::twilio::api::send_mssage(message, contact, param, config).await {
|
||||
Ok(response) => {
|
||||
println!("Raw response: {response:?}");
|
||||
let val = swoosh::twilio::api::response_to_json(response).await;
|
||||
println!("Response: {val:?}");
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
if count % long_sleep_limit == 0 {
|
||||
// Sleep for X seconds
|
||||
let wait_time = second_interval;
|
||||
std::thread::sleep(std::time::Duration::from_secs(wait_time));
|
||||
} else {
|
||||
// Sleep for a second
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
}
|
||||
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user