Able to get events
This commit is contained in:
+11
-5
@@ -39,7 +39,7 @@ impl Service {
|
|||||||
|
|
||||||
let events_req = super::event::Event {
|
let events_req = super::event::Event {
|
||||||
app: self.app.clone(),
|
app: self.app.clone(),
|
||||||
token: self.token.clone()
|
token: self.token.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let scheduled_message_id = queue_item.id;
|
let scheduled_message_id = queue_item.id;
|
||||||
@@ -51,8 +51,13 @@ impl Service {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// for event in &events {
|
let events = if events.is_some() {
|
||||||
while let Some(event) = &events {
|
events.unwrap()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
for event in events {
|
||||||
println!("Event: {event:?}");
|
println!("Event: {event:?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +72,13 @@ impl Service {
|
|||||||
|
|
||||||
1. Check the queue - Done
|
1. Check the queue - Done
|
||||||
2. If there is an item, get the data - Done
|
2. If there is an item, get the data - Done
|
||||||
3. Evaluate if it is schedulable
|
3. Evaluate if it is schedulable - Done
|
||||||
4. Get the events and iterate each one
|
4. Get the events and iterate each one - Done
|
||||||
5. starting with the message
|
5. starting with the message
|
||||||
6. Get the contact
|
6. Get the contact
|
||||||
7. Send the message
|
7. Send the message
|
||||||
8. Record the message event response
|
8. Record the message event response
|
||||||
|
9. Add to scheduler
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -7,9 +7,11 @@ impl Event {
|
|||||||
pub async fn get(
|
pub async fn get(
|
||||||
&self,
|
&self,
|
||||||
scheduled_message_id: &uuid::Uuid,
|
scheduled_message_id: &uuid::Uuid,
|
||||||
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error> {
|
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error>
|
||||||
|
{
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let endpoint = format!("api/v1/schedule/message/event?scheduled_message_id={scheduled_message_id}");
|
let endpoint =
|
||||||
|
format!("api/v1/schedule/message/event?scheduled_message_id={scheduled_message_id}");
|
||||||
let api_url = format!("{}/{endpoint}", self.app.api_url);
|
let api_url = format!("{}/{endpoint}", self.app.api_url);
|
||||||
|
|
||||||
println!("Url: {api_url:?}");
|
println!("Url: {api_url:?}");
|
||||||
@@ -18,15 +20,13 @@ impl Event {
|
|||||||
|
|
||||||
match client.get(api_url).header(key, header).send().await {
|
match client.get(api_url).header(key, header).send().await {
|
||||||
Ok(response) => match response.status() {
|
Ok(response) => match response.status() {
|
||||||
reqwest::StatusCode::OK => {
|
reqwest::StatusCode::OK => match response.text().await {
|
||||||
match response.text().await {
|
|
||||||
Ok(val) => match parse_response(&val).await {
|
Ok(val) => match parse_response(&val).await {
|
||||||
Ok(login_result) => Ok(login_result),
|
Ok(login_result) => Ok(login_result),
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
},
|
},
|
||||||
Err(err) => Err(std::io::Error::other(err)),
|
Err(err) => Err(std::io::Error::other(err)),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
_ => Err(std::io::Error::other("Error getting token")),
|
_ => Err(std::io::Error::other("Error getting token")),
|
||||||
},
|
},
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
@@ -38,13 +38,14 @@ async fn parse_response(
|
|||||||
response: &str,
|
response: &str,
|
||||||
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error> {
|
) -> Result<Vec<textsender_models::message::scheduling::ScheduledMessageEvent>, std::io::Error> {
|
||||||
match serde_json::from_str::<serde_json::Value>(response) {
|
match serde_json::from_str::<serde_json::Value>(response) {
|
||||||
Ok(j) => {
|
Ok(j) => match j.get("data") {
|
||||||
match j.get("data") {
|
|
||||||
Some(serde_json::Value::Array(lrs)) => {
|
Some(serde_json::Value::Array(lrs)) => {
|
||||||
if lrs.is_empty() {
|
if lrs.is_empty() {
|
||||||
Err(std::io::Error::other("Error response is empty"))
|
Err(std::io::Error::other("Error response is empty"))
|
||||||
} else {
|
} else {
|
||||||
let mut events: Vec<textsender_models::message::scheduling::ScheduledMessageEvent> = Vec::new();
|
let mut events: Vec<
|
||||||
|
textsender_models::message::scheduling::ScheduledMessageEvent,
|
||||||
|
> = Vec::new();
|
||||||
|
|
||||||
for event in lrs.iter() {
|
for event in lrs.iter() {
|
||||||
let ll: textsender_models::message::scheduling::ScheduledMessageEvent =
|
let ll: textsender_models::message::scheduling::ScheduledMessageEvent =
|
||||||
@@ -61,8 +62,7 @@ async fn parse_response(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(std::io::Error::other("Error parsing response")),
|
_ => Err(std::io::Error::other("Error parsing response")),
|
||||||
}
|
},
|
||||||
}
|
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user