From 2e10a80f95274be340ff90979410da239cb67620 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 4 Apr 2019 14:06:44 +0200 Subject: sms-forward: group messages for same sender --- sms-forward | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/sms-forward b/sms-forward index 9850d87..1c50552 100644 --- a/sms-forward +++ b/sms-forward @@ -18,21 +18,32 @@ :local Secret [ / tool sms get secret ]; # forward SMS in a loop -:foreach Sms in=[ / tool sms inbox find ] do={ - :local Message [ / tool sms inbox get $Sms message ]; - :local Phone [ / tool sms inbox get $Sms phone ]; - :local TimeStamp [ / tool sms inbox get $Sms timestamp ]; - :local Type [ / tool sms inbox get $Sms type ]; - - :if ($Phone = $Allowed && $Message~("^:cmd " . $Secret . " script ")) do={ - :log debug "Ignoring SMS, which starts a script."; - } else={ +:while ([ / tool sms inbox print count-only ] > 0) do={ + :local Phone [ / tool sms inbox get ([ find ]->0) phone ]; + :local Messages ""; + :local Delete [ :toarray "" ]; + + :foreach Sms in=[ / tool sms inbox find where phone=$Phone ] do={ + :local Message [ / tool sms inbox get $Sms message ]; + :local TimeStamp [ / tool sms inbox get $Sms timestamp ]; + :local Type [ / tool sms inbox get $Sms type ]; + + :if ($Phone = $Allowed && $Message~("^:cmd " . $Secret . " script ")) do={ + :log debug "Removing SMS, which started a script."; + / tool sms inbox remove $Sms; + } else={ + :set Messages ($Messages . "\n\nOn " . $TimeStamp . \ + " type " . $Type . ":\n" . $Message); + :set Delete ($Delete, $Sms); + } + } + + :if ([ :len $Messages ] > 0) do={ $SendNotification ("SMS Forwarding") \ - ("A message was received by " . $Identity . ":\n\n" . \ - "Phone: " . $Phone . "\n" . \ - "Timestamp: " . $TimeStamp . "\n" . \ - "Type: " . $Type . "\n\n" . \ - "Message:\n" . $Message); - / tool sms inbox remove $Sms; + ("These message(s) were received by " . $Identity . \ + " from " . $Phone . ":" . $Messages); + :foreach Sms in=$Delete do={ + / tool sms inbox remove $Sms; + } } } -- cgit v1.2.3-70-g09d2