aboutsummaryrefslogtreecommitdiffstats
path: root/sms-forward
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2019-04-04 14:06:44 +0200
committerGravatar Christian Hesse <mail@eworm.de>2019-04-05 09:24:04 +0200
commit2e10a80f95274be340ff90979410da239cb67620 (patch)
treea5cba2811ee8fbe1f505b66705990ea1ca9092d2 /sms-forward
parent15d3e9ea7ba1ed0457277462f409c75a7f4b5171 (diff)
sms-forward: group messages for same sender
Diffstat (limited to 'sms-forward')
-rw-r--r--sms-forward41
1 files 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;
+ }
}
}