Skip to content

Commit

Permalink
Merge branch 'main' into barebones
Browse files Browse the repository at this point in the history
  • Loading branch information
CaspianA1 committed Jul 10, 2024
2 parents df2b58a + 26b8d85 commit 2ab06c3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/dashboard_defs/twilio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,15 +320,23 @@ impl Updatable for TwilioStateData {
- When messages are sent with very small time gaps between each other, they can end up out of order - how to resolve? And is this a synchronization issue?
*/

/* This is very much a magic number! It's set in our cloud console.
For every text sent, it's forwarded this many times to different management numbers. */
const NUM_NUMBERS_FORWARDED_TO: usize = 2;

let max_messages = self.immutable.max_num_messages_in_history;
let amt_messages_to_actually_get = max_messages * (NUM_NUMBERS_FORWARDED_TO + 1);

// TODO: the page size is limiting what I need here (every inbound gets 2 outbound)
let json = self.do_twilio_request("Messages", &[],
&[
("PageSize", Cow::Borrowed(&max_messages.to_string())),
("PageSize", Cow::Borrowed(&amt_messages_to_actually_get.to_string())),
("DateSent%3E", Cow::Borrowed(&history_cutoff_day.to_string())) // Note: the '%3E' is a URL-encoded '>'
]
)?;

// println!("{json}");

////////// Creating a map of incoming messages

// This will always be in the range of 0 <= num_messages <= self.num_messages_in_history
Expand All @@ -338,6 +346,12 @@ impl Updatable for TwilioStateData {
json_messages.iter().filter_map(|message| {
let message_field = |name| message[name].as_str().unwrap();

/* Filtering the outbound messages out (some inbound messages
are forwarded to other numbers, making them outbound) */
if message_field("direction") != "inbound" {
return None;
}

// Using the date created instead, since it is never null at the beginning (unlike the date sent)
let unparsed_time_sent = message_field("date_created");
let time_sent = DateTime::parse_from_rfc2822(unparsed_time_sent).unwrap();
Expand Down

0 comments on commit 2ab06c3

Please sign in to comment.