Community discussions

MikroTik App
 
domlator
just joined
Topic Author
Posts: 1
Joined: Fri May 24, 2024 9:57 am

Script for auto-repy sms

Fri May 24, 2024 10:39 am

Hello all,

First of all, I don't know if I am in the correct "folder" on this site, and if I'm not, sorry.

I made this script with a little help from ChatGPT (I know, it's cheating :) ) for my needs. In my country, like many others, the most usable internet is via LTE/5G. Most providers don't offer true unlimited (FLAT) internet; instead, once you use up the data included in your payment plan, you need to send a message to a certain number to continue surfing at the maximum available speed. If you don't send that message, your speed is limited to approximately 4Mbps.

This is my situation as well, so I created this auto-reply SMS script to avoid manually sending the SMS each time I use up 20GB of traffic.

This is the script :
______________________________________________________________________________________________________________________________________________________________
/system script add name=auto-reply-sms source={
:local senderPhone "YOUR_INPUT"
:local message "YOUR_INPUT"
:local responseNumber "YOUR_INPUT"
:local responseMessage "YOUR_INPUT"
:local notifyNumber "YOUR INPUT"
:local notifyMessage "YOUR_INPUT"

# Check for messages from the specific sender
:local messages [/tool sms inbox find]

:foreach i in=$messages do={
:local messageText [/tool sms inbox get $i message]
:local senderNumber [/tool sms inbox get $i phone]
:log info ("Processing message from " . $senderNumber . ": " . $messageText)

# Check if the message is from the specific sender and contains the keyword
:if (($senderNumber = $senderPhone) && ([:find $messageText $message] != -1)) do={
:log info ("Keyword found in message from " . $senderNumber)

# Check if we've already replied to this keyword
:local alreadyReplied [/tool sms inbox find where phone=$responseNumber and message=$responseMessage]
:if ([:len $alreadyReplied] = 0) do={
:log info ("Reply not sent yet, sending reply to " . $responseNumber)
/tool sms send phone=$responseNumber message=$responseMessage

:log info ("Sending notification to " . $notifyNumber)
/tool sms send phone=$notifyNumber message=$notifyMessage
} else={
:log info ("Already replied to this keyword")
}
}
}

# Remove all messages from the SMS inbox to prevent it from getting full
/tool sms inbox remove [find]
}
______________________________________________________________________________________________________________________________________________________________
I just added lines to divide the script from the text. The script is fairly simple, and it works as intended (the lazy way :) ).

Anyway, you can see in the script YOUR_INPUT, which indicates where you should check the inbox and change according to your specific details. The lines :local notifyNumber and :local notifyMessage are not mandatory. I just added them to notify me on my phone when the router sends a reply message so I can monitor how often it sends.

All you need to do is add a scheduler with an appropriate interval for how often you want to run the script. You can add it via the terminal as well:
______________________________________________________________________________________________________________________________________________________________

/system scheduler add name=auto-reply-sms-scheduler interval=1h on-event=auto-reply-sms
______________________________________________________________________________________________________________________________________________________________

I hope it will help someone.

Cheers.
 
abbio90
Member Candidate
Member Candidate
Posts: 293
Joined: Fri Aug 27, 2021 9:16 pm
Contact:

Re: Script for auto-repy sms

Sun Jun 16, 2024 10:33 am

what exactly do you use this script for?
 
jaclaz
Forum Veteran
Forum Veteran
Posts: 863
Joined: Tue Oct 03, 2023 4:21 pm

Re: Script for auto-repy sms

Sun Jun 16, 2024 11:02 am

what exactly do you use this script for?
Not the OP, but in some countries/with some mobile operators, you can have a contract with "unlimited" (or however rather large) volume of traffic, but for *some reasons* the traffic is allowed in "chunks", once you have used (say) 10 GB of traffic, data rate is lowered to a minimum and (it depends on the operator) you need to send a sms to ask for more or a message is sent to you with a code/keyword that allows - sent back by SMS - to "unlock" the next 10 GB at "full speed".

See also:
viewtopic.php?t=183911
viewtopic.php?t=203246

Who is online

Users browsing this forum: No registered users and 15 guests