Capturing a TFA Code from an Outlook Notification

4michaelmay

New member
Greetings all. I have been trying to get something to work for months, but sadly my familiarity of the intricacies of MD is falling short.

Here's what I'm trying to do. I log in daily to a portal that requires Two Factor Authentication. My phone receives an Outlook email (from a specific, consistent email address) and if I drag the top notification bar down I can see enough of the Notification to view the 6 digit code I need.

Example
- Outlook notification received from TFACode@Outlook.com
- Your Authentication Code is 123456. It expires in 15 minutes.

So is there a way of MD extracting the Code from the notification and displaying it as a pop-up?

I tried setting up a Trigger using the Notification Received (Specific App) and then set a variable and used Text Manipulation > Extract Text to no avail.

Any help would be much appreciated.

Running Android 14 and MD 5.43.8 Pro
 

Endercraft

Moderator (& bug finder :D)
There are many macros that do this on the template store. This is an example I made on the spot:
Extract_code.png
In case you're wondering, \d{6} is the Regular Expression for 6 digits following each other (6 digits in a row).
 

4michaelmay

New member
Thank you. I had something very close to this too and the suggested code is giving me the same problem which is frustrating me, that being when the pop up message appears it does not display the number I'm trying to extract... I just get "Code:"

Interestingly, if I look at the Macro after running / testing, the local variable shows as 'Empty' rather than 0 or any other number.
I feel I'm missing something fundamental here due to inexperience, but I can't fathom what.

FYI the code I'm trying to extract is in the body of the email I receive. It doesn't show on the brief 'toast' I get that appears and vanishes on arrival, I have to pull down the notification bar which then shows me a preview of the first lines of the email, who it's from, the subject, and the first lines of content, which shows the code I'm looking for.
 

Endercraft

Moderator (& bug finder :D)
Oh yeah I forgot to use a string variable. The first condition should match is variable equals "" (without quotes).
Now for the problem of the code not being extracted: try with every notification magic text instead of the one I used.
 

4michaelmay

New member
Thanks - I was continuing to search the templates and also found one that is the basis of something that works:

Seems the key is the String as suggested. Thank you for your pointers, very much appreciated
 
Top