Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "sms_otp_parse"

Title:Extract one-time passcodes, sender, expiry and SMS Retriever hash from verification texts
Rating:Not rated. Create the first rating!
Latest version:1.0.0
SHA1 sum:616a7852acd2fefa014111584598d67317e202f5
Author:CryptoeSIM.io https://cryptoesim.io/blog/buynumber-io-alternatives-3
Maintainer:CryptoeSIM.io https://cryptoesim.io/blog/buynumber-io-alternatives-3
Packager:CryptoeSIM.io https://cryptoesim.io/blog/buynumber-io-alternatives-3
Home page:https://cryptoesim.io/blog/buynumber-io-alternatives-3
Download URL:https://gitea.com/cryptoesim/sms_otp_parse/raw/branch/main/releases/sms_otp_parse-*.tgz

Reviews

No reviews. Create the first review!.

Details by download location

VersionSHA1#DownloadsURL
1.0.0616a7852acd2fefa014111584598d67317e202f52https://gitea.com/cryptoesim/sms_otp_parse/raw/branch/main/releases/sms_otp_parse-1.0.0.tgz

sms_otp_parse

A small SWI-Prolog library that reads a verification text message and gives back the one-time passcode, the service that sent it, how long the code is valid and, if present, the Android SMS Retriever app hash.

?- pack_install(sms_otp_parse).
?- use_module(library(sms_otp_parse)).

?- otp_code("G-482913 is your Google verification code.", C).
C = '482913'.

?- otp_code("Call 07700 900123 if this wasn't you. Your code: 5521", C).
C = '5521'.

?- otp_message("<#> Uber: 4829 is your code. Expires in 5 min\nFA+9qCX9VSu", D).
D = otp{code:'4829', expiry_minutes:5, retriever_hash:'FA+9qCX9VSu', service:'Uber'}.

Predicates

PredicateWhat it does
otp_code(+Text, -Code)Most likely passcode, digits only ("482 913" and "482-913" both give '482913'). Fails if none.
otp_candidates(+Text, -List)Every candidate as otp(Code, Score, Offset), in text order.
otp_service(+Text, -Name)Sender from [Name], `<#> Name:`, `Name:` or "your Name verification code".
otp_expiry_minutes(+Text, -Min)"expires in 10 minutes" gives 10, "1 hour" gives 60, "90 seconds" rounds up to 2.
sms_retriever_hash(+Text, -Hash)The 11-character app hash Android's SMS Retriever API puts at the end of the message.
otp_message(+Text, -Dict)All of the above; missing fields are none.

How codes are picked

A candidate is 4 to 8 digits in a row, or two groups of three digits joined by one space or hyphen. A run is dropped when it is part of a longer number (phone numbers, dates such as 23-11-2026), starts with +, or sits next to a currency sign, `%`, /, a colon (times like 14:05) or a decimal point (amounts like 1250.00). Each remaining candidate gets a score: +3 for a code keyword (code, OTP, passcode, PIN, verification, token, kod, código) in the 60 characters before it, +2 if the keyword only comes after it, +1 for six digits, and -2 for a 4-digit value that looks like a year. Highest score wins; ties go to the first one in the text.

Run the tests with:

swipl -g run_tests -t halt test/test_sms_otp_parse.pl

Why we wrote it

We built this while testing numbers for our comparison of BuyNumber.io alternatives. BuyNumber-style activation numbers get you one code and then return to the pool, so a later login or password-reset code goes to someone else. Renting a non-VoIP UK number for SMS verification, paid in crypto, keeps the same number for the whole term, which is the case where parsing many codes from one inbox is useful.

MIT licence.

Contents of pack "sms_otp_parse"

Pack contains 5 files holding a total of 15.1K bytes.