Page 1 of 1

Extracting last SMS number

Posted: Fri Jul 03, 2020 11:49 pm
by harvey
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

Re: Extracting last SMS number

Posted: Sat Jul 04, 2020 12:18 am
by harvey
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

Re: Extracting last SMS number

Posted: Sun Jul 05, 2020 3:35 am
by mutluit
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

Re: Extracting last SMS number  [SOLVED]

Posted: Sun Jul 05, 2020 1:06 pm
by redmonkey
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") 

Re: Extracting last SMS number

Posted: Sun Jul 05, 2020 2:15 pm
by harvey
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):"

Re: Extracting last SMS number

Posted: Sun Jul 05, 2020 2:17 pm
by harvey
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

Re: Extracting last SMS number

Posted: Sun Jul 05, 2020 2:35 pm
by mutluit
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)

Re: Extracting last SMS number

Posted: Tue Aug 25, 2020 10:47 pm
by AlexRodac
Hello i may see your script, plases

Re: Extracting last SMS number

Posted: Tue Nov 10, 2020 5:40 pm
by AlexRodac
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.

Re: Extracting last SMS number

Posted: Tue Nov 10, 2020 5:42 pm
by AlexRodac
I want know how send sms to the device to answer me .