OTP reading flow

Post your questions and help other users.

Moderator: Martin

Post Reply
icefox56
Posts: 53
Joined: 15 Aug 2017 02:56

OTP reading flow

Post by icefox56 » 07 Dec 2018 11:42

How to create a flow that will

Trigger: when I receive an SMS containg the word 'OTP'

Action: Copy only the number part of that SMS to clipboard, so that I can paste it.

Note: I tried search first and found this viewtopic.php?f=5&t=2944
But i didn't understand anything because they were taking about variables and scripts, which I have no idea about.

What I tried:

1. Trigger: SMS Received, containg the word OTP
2. Action1: Copy Text From Clipboard: to Variable clip_data1 (This is to backup my orginal clipboard)
3. Action2: Copy Text to Clipboard:{sms_text}
4. Stuck

How can I fill the clipboard with the numbers contained in SMS?
Asus Zenfone Max pro M1, Stock android, Oreo 8.1, Rooted

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: OTP reading flow

Post by anuraag » 07 Dec 2018 14:47

First you need to find out otp using regex. If your otp contains only numbers then use script
otp=findAll(sms_text, '\\d+');
otp[0] is your otp.

1. Trigger: SMS Received, containg the word OTP
2. Action: Script: otp=findAll(sms_text, '\\d+');
3. Action2: Copy Text to Clipboard:{otp[0]}

icefox56
Posts: 53
Joined: 15 Aug 2017 02:56

Re: OTP reading flow

Post by icefox56 » 07 Dec 2018 18:42

It worked. Thanks a lot.

Questions:

1. Will you tell me the meaning of
otp=findAll(sms_text, '\\d+');
And :{otp[0]}

I looked for this '\\d+' all over the script documentation but couldn't find an explanation. I understand it's some kind of regex or something. Where can I learn more about stuff like these?

2. Will I be able to make flows like this if Google decide to remove SMS permission for apps like Automagic?

3. Is there any way to specify more than one 'conains the word' in SMS received trigger?

Currently I have only 'OTP'. what if I want to include 'code' also. The help section says no wildcards supported. Does that mean I have to create a separate flow for all possible 'words contain' part?
Asus Zenfone Max pro M1, Stock android, Oreo 8.1, Rooted

User avatar
digitalstone
Posts: 342
Joined: 21 Oct 2017 12:36
Location: The Netherlands

Re: OTP reading flow

Post by digitalstone » 07 Dec 2018 18:57

At the very bottom inside the Script action, you'll find the "REGULAR EXPRESSION TESTER" button. Click it.
Here you can test your regex (REGular EXpression) strings on all supported script functions.
In the upper-right corner there's the 3-dot menu with the Help-page inside. Click.
Now you can learn about regex ;)

Btw: '\\d+' is not 1 thing, so it makes sense you can't find it.
d = detecting digits
+ = 1 or more
Phone: LG Nexus 5X (rooted vanilla Android 7.1.2)

icefox56
Posts: 53
Joined: 15 Aug 2017 02:56

Re: OTP reading flow

Post by icefox56 » 07 Dec 2018 22:28

Thanks for pointing out the help section in regex tester. I didn't noticed that.

After reading help I tried to tweak the script. But I have problem making the flow work.

Some of the otp I receive include "-" eg. It look like this 123-456. So after reading help section in Regular expression tester I made this Regex

[[[a-z]&&[^\S]][\d][-]]{4,7}

The regex tester now correctly recognises 123-456 or 123456. And will not include words or dot(.) Or comma(,) but when I put this in script as

otp=findAll(sms_text,'[[[a-z]&&[^\S]][\d][-]]{4,7}')

And Action2 as Copy text to clipboard: {otp[0]}

It copy {error} into my clipboard.

What am I doing wrong?
How to correct it?
Asus Zenfone Max pro M1, Stock android, Oreo 8.1, Rooted

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: OTP reading flow

Post by anuraag » 07 Dec 2018 23:12

Inside Regular Expression Tester you need only one back slash but in script you need 2 backslash.
So your regex is
[[[a-z]&&[^\\S]][\\d][-]]{4,7}
Last edited by anuraag on 07 Dec 2018 23:48, edited 1 time in total.

icefox56
Posts: 53
Joined: 15 Aug 2017 02:56

Re: OTP reading flow

Post by icefox56 » 07 Dec 2018 23:26

Thanks Anuraag that fixed it.

Now can you please tell me what {otp[0]} is in Action2 copy to clipboard?
Asus Zenfone Max pro M1, Stock android, Oreo 8.1, Rooted

anuraag
Posts: 371
Joined: 24 Jan 2015 02:06

Re: OTP reading flow

Post by anuraag » 07 Dec 2018 23:47

findAll returns a list containing matching pattern. So otp is a list.
To get first element of your list you need to either use
getElement(otp, 0) or otp[0]

icefox56
Posts: 53
Joined: 15 Aug 2017 02:56

Re: OTP reading flow

Post by icefox56 » 08 Dec 2018 01:54

Thanks for the explanation.
Asus Zenfone Max pro M1, Stock android, Oreo 8.1, Rooted

Post Reply