I’m trying to write a script so when the Mikrotik receives an SMS it runs the script, gathers some information from the Mikrotik, and then sends an SMS back to the number that sent the request.
Is there any way to pass the phone number of the incoming message to the script so it can be used within the script to send the reply?
I’m also exploring the option of the script just searching the inbox from the last message, extracting the number and then using that but trying to see if there is a more direct solution.
SMS received by the RouterBoard can be read by following command
/tool sms print
With “/tool sms print” you can see the received SMSes and pick fields from them etc…
Maybe the above examples are outdated. Better use the examples from the link below:
I guess that the part you are missing is how to fetch the sender number from the received message.
So you need something like :local senderNumber [tool sms inbox get [find message~“a regexp to check that it is the expected query message, not a spam”] number]
and then you can send the response, using $senderNumber:
Having no 3G modem at hand, I cannot check it, so I hope it is sufficient like this. However, a script for actual deployment would have to use a foreach cycle to create a snapshot of the list of received messages and process it regardless whether some further SMS eventually arrive during the processing.
Hi @sindy, thanks for the idea, I’ve had another thread open trying to look at it from another angle and that solution seems like it will be suitable enough for me. Thanks for your input.
Well, the only difference is that in that other thread you use the print as-value approach for the same thing, although the (slightly simpler) get works for /tool sms inbox. My perfectionist sould aches because for some types of data, only get works, for other ones, only print as-value does, and for yet another ones, both methods are available.
Hello, How are you?
I have the same doubt about the configuration of the sms, I have an LtAP LTE, with three ports for sim cards, currently I only have a single sim working, which is slot two, but I have not been able to get the messages to be sent , I had already made a configuration but for him to send me the gps information and signal status, I could achieve this through some scripts for email and also with telegram, but I have not yet been able to with the sms, and I want him to do what @harvey says.
If you can help me, I would really appreciate it.