Twilio Config refactor (#27)
Reviewed-on: phoenix/textsender_api#27
This commit was merged in pull request #27.
This commit is contained in:
+13
-48
@@ -81,36 +81,34 @@ pub mod endpoint {
|
||||
match message_repo::get(&pool, &payload.message_id).await {
|
||||
Ok(message) => {
|
||||
println!("Valid message");
|
||||
let t_config = match load_config().await {
|
||||
Ok(config) => config,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error getting config");
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let t_config =
|
||||
match textsender_models::config::auxiliary::load_config().await {
|
||||
Ok(config) => config,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error getting config");
|
||||
return (
|
||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
axum::Json(response),
|
||||
);
|
||||
}
|
||||
};
|
||||
let mut results: Vec<
|
||||
textsender_models::message::event::MessageEventResponse,
|
||||
> = Vec::new();
|
||||
// let mut results: Vec<serde_json::Value> = Vec::new();
|
||||
let pp = swoosh::twilio::types::Parameters {
|
||||
schedule: false,
|
||||
schedule_at: None,
|
||||
};
|
||||
|
||||
for contact in &contacts {
|
||||
match swoosh::twilio::api::send_mssage(
|
||||
match swoosh::twilio::api::send_message(
|
||||
&message, contact, &pp, &t_config,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result) => {
|
||||
println!("Response: {result:?}");
|
||||
let val = swoosh::twilio::api::response_to_json(result).await;
|
||||
// results.push(val);
|
||||
let mer = textsender_models::message::event::MessageEventResponse {
|
||||
user_id: payload.user_id,
|
||||
// TODO: Make this more accurate
|
||||
@@ -170,37 +168,4 @@ pub mod endpoint {
|
||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_config()
|
||||
-> Result<textsender_models::config::auxiliary::TwilioConfig, std::io::Error> {
|
||||
let mut config = textsender_models::config::auxiliary::TwilioConfig {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let auth_sid_var = textsender_models::envy::environment::get_env("TWILIO_AUTH_SID").await;
|
||||
println!("{auth_sid_var:?}");
|
||||
let service_sid_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_SERVICE_SID").await;
|
||||
println!("{service_sid_var:?}");
|
||||
let auth_token_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_AUTH_TOKEN").await;
|
||||
println!("{auth_token_var:?}");
|
||||
let phone_number_var =
|
||||
textsender_models::envy::environment::get_env("TWILIO_PHONE_NUMBER").await;
|
||||
println!("{phone_number_var:?}");
|
||||
|
||||
if auth_sid_var.value.is_empty()
|
||||
|| service_sid_var.value.is_empty()
|
||||
|| auth_token_var.value.is_empty()
|
||||
|| phone_number_var.value.is_empty()
|
||||
{
|
||||
Err(std::io::Error::other("Config not set"))
|
||||
} else {
|
||||
config.account_sid = auth_sid_var.value;
|
||||
config.service_sid = service_sid_var.value;
|
||||
config.auth_token = auth_token_var.value;
|
||||
config.phone_number = phone_number_var.value;
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user