mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2026-06-04 17:52:34 +00:00
Allow sms forward actions
This commit is contained in:
parent
7594345da8
commit
2d7f764c69
4 changed files with 66 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
*~
|
||||
*.patch
|
||||
*.html
|
||||
.DS_Store
|
||||
|
|
|
|||
|
|
@ -39,6 +39,36 @@ Also you have to enable receiving of SMS:
|
|||
|
||||
/tool/sms/set receive-enabled=yes;
|
||||
|
||||
The configuration goes to `global-config-overlay`, this is the only parameter:
|
||||
|
||||
* `SmsForwardHooks`: an array with pre-defined actions in form where the key of the array is the regular expression to match the SMS text and the value is the action to execute:
|
||||
|
||||
```
|
||||
:global SmsForwardHooks {
|
||||
{ match="command";
|
||||
allowed-number="1234";
|
||||
command=":put "command executed"" };
|
||||
# add more here...
|
||||
};
|
||||
```
|
||||
|
||||
in this example the command `:put "command executed"` will be executed
|
||||
when a SMS with text starting with `command` is received from number `1234`.
|
||||
|
||||
Useful use case is to send an SMS to order an additional internet package when the current one is about to deplete, and the automatic SMS is sent from the provider with the text that 80%, 100% of the package are used. Then, an automated SMS can be sent to a provider back to order a new package automatically.
|
||||
For example, for the [KPN](https://kpn.com/) provider, the SMS text is `NL2000 AAN` sent to number `1266` to order an additional 2GB package.
|
||||
Then, the following configuration can be used:
|
||||
|
||||
```
|
||||
:global SmsForwardHooks {
|
||||
{ match="80%";
|
||||
allowed-number="KPN";
|
||||
command="/tool/sms/send lte1 phone-number=1266 message=\"NL2000 AAN\";" };
|
||||
};
|
||||
```
|
||||
This reads as: when the SMS with text `80%` is received from number `KPN`, the SMS with text `NL2000 AAN` is sent to the provider.
|
||||
If you use unlimited plan, this is exactly what you need to do to order a new package automatically.
|
||||
|
||||
See also
|
||||
--------
|
||||
|
||||
|
|
|
|||
|
|
@ -147,6 +147,14 @@
|
|||
# add more here...
|
||||
};
|
||||
|
||||
# Run commands on SMS forward action.
|
||||
:global SmsForwardHooks {
|
||||
# { match="magic string";
|
||||
# allowed-number="1234";
|
||||
# command="/system/script/run ..." };
|
||||
# add more here...
|
||||
};
|
||||
|
||||
# This is the address used to send gps data to.
|
||||
:global GpsTrackUrl "https://example.com/index.php";
|
||||
|
||||
|
|
|
|||
27
sms-forward
27
sms-forward
|
|
@ -18,6 +18,12 @@
|
|||
:global SendNotification2;
|
||||
:global SymbolForNotification;
|
||||
:global WaitFullyConnected;
|
||||
:global ValidateSyntax;
|
||||
:global SmsForwardHooks;
|
||||
|
||||
:if ([ :typeof $SmsForwardHooks ] != "array") do={
|
||||
:global SmsForwardHooks ({});
|
||||
}
|
||||
|
||||
$ScriptLock $0;
|
||||
|
||||
|
|
@ -43,6 +49,27 @@ $WaitFullyConnected;
|
|||
$LogPrintExit2 debug $0 ("Removing SMS, which started a script.") false;
|
||||
/tool/sms/inbox/remove $Sms;
|
||||
} else={
|
||||
:local processed false;
|
||||
$LogPrintExit2 debug $0 ("Processing message:" . $SmsVal->"message" . " " . $Phone) false;
|
||||
:foreach Hook in=$SmsForwardHooks do={
|
||||
$LogPrintExit2 debug $0 ("Checking SMS forward hook '" . $Hook . "' on message: '" . $SmsVal->"message" . "'") false;
|
||||
:local Code ($Hook->"command");
|
||||
:local Regex ($Hook->"match");
|
||||
:local AllowedNumber ($Hook->"allowed-number");
|
||||
:if ($processed = false && $Phone~$AllowedNumber && ($SmsVal->"message")~$Regex) do={
|
||||
:if ([ $ValidateSyntax $Code ] = true) do={
|
||||
:log info ("Acting on SMS forward hook '" . $Regex . "': " . $Code);
|
||||
:delay 1s;
|
||||
[ :parse $Code ];
|
||||
:log info ("Finished SMS forward hook '" . $Regex . "': " . $Code);
|
||||
} else={
|
||||
$LogPrintExit2 warning $0 ("The code for forward hook '" . $Regex . "': '" . $Code . "' failed syntax validation!") false;
|
||||
}
|
||||
# $LogPrintExit2 debug $0 ("Removing SMS, which started a forward script.") false;
|
||||
# /tool/sms/inbox/remove $Sms;
|
||||
:set processed true;
|
||||
}
|
||||
}
|
||||
:set Messages ($Messages . "\n\nOn " . $SmsVal->"timestamp" . \
|
||||
" type " . $SmsVal->"type" . ":\n" . $SmsVal->"message");
|
||||
:set Delete ($Delete, $Sms);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue