Community discussions

MikroTik App
 
User avatar
harvey
Member Candidate
Member Candidate
Topic Author
Posts: 130
Joined: Thu Apr 05, 2012 8:16 pm

Extracting last SMS number

Fri Jul 03, 2020 11:49 pm

Hi All,

I'm trying to write a script, that gets the phone number of the last received SMS message in the inbox. I'm running 6.45.9.

If I run `/tool sms inbox print` I can see messages. Looking at other forum posts it looks like `/tool sms inbox find` and `/tool sms inbox get $i phone` (where is presume $i is the id of the message) should be work but running those commands in the terminal returns no results. What am I missing?

I was planning on using `/tool sms inbox print count-only` to count the messages, subtract 1 (as ID's start form 0) and then pass that to `/tool sms inbox get $i phone`.

Any assistance would be appreciated.

Many thanks
 
User avatar
harvey
Member Candidate
Member Candidate
Topic Author
Posts: 130
Joined: Thu Apr 05, 2012 8:16 pm

Re: Extracting last SMS number

Sat Jul 04, 2020 12:18 am

More research suggests /tool sms inbox get $i phone doesn't use the index so using my count - 1 method won't work .

However `/tool sms inbox find` still returns nothing
 
User avatar
mutluit
Forum Veteran
Forum Veteran
Posts: 765
Joined: Wed Mar 25, 2020 4:04 am

Re: Extracting last SMS number

Sun Jul 05, 2020 3:35 am

More research suggests /tool sms inbox get $i phone doesn't use the index so using my count - 1 method won't work .

However `/tool sms inbox find` still returns nothing
Try this:

:global lastIx (:len [/tool sms inbox] - 1)
:global lastNum [/tool sms inbox get number=$lastIx phone]
:put $lastNum
...

Update: fixed first line as it had a typo
Last edited by mutluit on Sun Jul 05, 2020 2:49 pm, edited 1 time in total.
 
redmonkey
just joined
Posts: 8
Joined: Fri Jun 26, 2020 10:52 am

Re: Extracting last SMS number  [SOLVED]

Sun Jul 05, 2020 1:06 pm

The SMS inbox is a 2D array, tips on how to work with and get parameter values from arrays can be found in the Scripting Tips and Tricks section of the wiki, specifically sections 5. Get values for properties if 'get' command is not available and 6. Always check what value and type command returns provide useful information for this situation.

To answer the original question directly, the quick and dirty one liner for testing in the terminal would be -

`:put ([:pick [/tool sms inbox print as-value] ([/tool sms inbox print count-only] - 1)]->"phone")`

But for clarity and readability I would break it down a little to -
:global messageStore   [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->"phone") 
 
User avatar
harvey
Member Candidate
Member Candidate
Topic Author
Posts: 130
Joined: Thu Apr 05, 2012 8:16 pm

Re: Extracting last SMS number

Sun Jul 05, 2020 2:15 pm

More research suggests /tool sms inbox get $i phone doesn't use the index so using my count - 1 method won't work .

However `/tool sms inbox find` still returns nothing
Try this:

:global lastIx ([:len /tool sms inbox] - 1)
:global lastNum [/tool sms inbox get number=$lastIx phone]
:put $lastNum
...
Hi, thanks. However, the first line returns the error:

"expected end of command (line 1 column 29):"
 
User avatar
harvey
Member Candidate
Member Candidate
Topic Author
Posts: 130
Joined: Thu Apr 05, 2012 8:16 pm

Re: Extracting last SMS number

Sun Jul 05, 2020 2:17 pm

The SMS inbox is a 2D array, tips on how to work with and get parameter values from arrays can be found in the Scripting Tips and Tricks section of the wiki, specifically sections 5. Get values for properties if 'get' command is not available and 6. Always check what value and type command returns provide useful information for this situation.

To answer the original question directly, the quick and dirty one liner for testing in the terminal would be -

`:put ([:pick [/tool sms inbox print as-value] ([/tool sms inbox print count-only] - 1)]->"phone")`

But for clarity and readability I would break it down a little to -
:global messageStore   [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->"phone") 
Hi @redmonkey,

Your solutions looks to work fine, will need to run more tests but looks ideal
 
User avatar
mutluit
Forum Veteran
Forum Veteran
Posts: 765
Joined: Wed Mar 25, 2020 4:04 am

Re: Extracting last SMS number

Sun Jul 05, 2020 2:35 pm

More research suggests /tool sms inbox get $i phone doesn't use the index so using my count - 1 method won't work .

However `/tool sms inbox find` still returns nothing
Try this:

:global lastIx ([:len /tool sms inbox] - 1)
:global lastNum [/tool sms inbox get number=$lastIx phone]
:put $lastNum
...
Hi, thanks. However, the first line returns the error:

"expected end of command (line 1 column 29):"
Ah, sorry, here is the fix:
:global lastIx (:len [/tool sms inbox] - 1)
 
AlexRodac
just joined
Posts: 23
Joined: Tue Jun 30, 2020 6:37 pm

Re: Extracting last SMS number

Tue Aug 25, 2020 10:47 pm

Hello i may see your script, plases
 
AlexRodac
just joined
Posts: 23
Joined: Tue Jun 30, 2020 6:37 pm

Re: Extracting last SMS number

Tue Nov 10, 2020 5:40 pm

Hello, I have an LtAP LTE device, it is configured with two sims of three sims, it only sends sms through slot one, that is, sim one, however I still cannot receive an SMS response from the device with the execution of a created script. How can I tell the device that when you received a text message, it responds to that text?


I have this now until, but i feel lack a thing

:global messageStore [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->"phone")
/system gps monitor once do={
:set $lat $("latitude")
:set $lon $("longitude")
}

/tool sms send lte1 message="ANSWER 1 - Your location is $lat $lon - PRUEBA ONE" phone-number=([:pick $messageStore $lastMessageIdx]->"phone")





If you may help me, thanks.
 
AlexRodac
just joined
Posts: 23
Joined: Tue Jun 30, 2020 6:37 pm

Re: Extracting last SMS number

Tue Nov 10, 2020 5:42 pm

I want know how send sms to the device to answer me .

Who is online

Users browsing this forum: Baidu [Spider] and 25 guests