| Did you know ... | Search Documentation: |
| Pack sms_otp_parse -- prolog/sms_otp_parse.pl |
Verification texts come in many shapes: "G-482913 is your Google verification code", "[Bank] Code: 482 913. Expires in 10 minutes", "<#> 4829 is your code\nFA+9qCX9VSu". This library finds the code, the sending service, the stated expiry and the Android SMS Retriever hash, while skipping phone numbers, prices, dates, times and percentages that often sit in the same message.
A candidate is a run of 4 to 8 digits, or two groups of three digits joined by a single space or hyphen ("482 913", "482-913"). Runs that touch other digit groups (phone numbers, dates), start with "+", or sit next to a currency sign, a percent sign, a colon (times) or a decimal point (amounts) are dropped. Remaining candidates are scored: a code keyword in the 60 characters before it (code, OTP, passcode, PIN, verification, ...) adds 3, or 2 if the keyword only follows it; six digits adds 1, a 4-digit value that looks like a year (1900-2099) loses 2. The best score wins; ties go to the earliest candidate.
otp(Code, Score, Offset) terms in the order
they appear in Text.none when it cannot be found.