Instant message #24
+49
-2
@@ -76,8 +76,13 @@ pub mod endpoint {
|
||||
if !contacts.is_empty() {
|
||||
match message_repo::get(&pool, &payload.message_id).await {
|
||||
Ok(message) => {
|
||||
let t_config = textsender_models::config::auxiliary::TwilioConfig {
|
||||
..Default::default()
|
||||
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 mut results: Vec<reqwest::Response> = Vec::new();
|
||||
|
||||
@@ -107,6 +112,23 @@ pub mod endpoint {
|
||||
axum::Json(response),
|
||||
)
|
||||
} else {
|
||||
for result in results {
|
||||
let response_body = match result.text().await {
|
||||
Ok(response_body) => response_body,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
response.message = String::from("Error parsing body after sending");
|
||||
return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response));
|
||||
}
|
||||
};
|
||||
let val: serde_json::Value = match serde_json::from_str(&response_body) {
|
||||
Ok(val) => val,
|
||||
Err(err) => {
|
||||
eprintln!("Error: {err:?}");
|
||||
return (axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::Json(response));
|
||||
}
|
||||
};
|
||||
}
|
||||
response.message = String::from(super::super::response::SUCCESSFUL);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
}
|
||||
@@ -126,4 +148,29 @@ 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