Voice Banking in Laravel: Never Trust the Transcript for the Payment Recipient
TalkAm is a voice-banking app I built on WhatsApp. A user sends a voice note, something like "send 5,000 to my brother", and the money moves after a read-back, a PIN and, when the risk rules call for it, a face check. M
TalkAm is a voice-banking app I built on WhatsApp. A user sends a voice note, something like "send 5,000 to my brother", and the money moves after a read-back, a PIN and, when the risk rules call for it, a face check.
Most of a voice instruction is easy to check. The amount gets read back. The intent is one of six, a closed set. The recipient is different. Speech-to-text is worst at exactly the part a transfer can't afford to get wrong: names. Nigerian names and nicknames are what automatic transcription mangles most. The user says "my brother"; the recogniser hears "my broda", "mai brother", or something unrecognisable.
So one rule sits in the code, written as a comment above the call that enforces it:
The recipient is resolved against the user's own saved payees, or against the bank by name enquiry โ never trusted from the transcript. What comes back is a destination or a question.
This article walks through how that's built in Laravel, and the decisions behind it.
The transcript holds a reference, not a destination
The language model's job in TalkAm is to propose. It reads the transcript and returns an intent plus entities, one of which is a recipient_reference: the words the user used for the person they want to pay. "My brother", or "7733992211".
That string is never an account. It's a clue. A single class, BeneficiaryResolver, turns it into one of four outcomes, and the design turns on the fact that only one of them is an error.
final readonly class RecipientResolution
{
// "my brother" matched someone they have paid before
public static function savedPayee(Beneficiary $b): self { /* ... */ }
// ten digits, and the bank's name enquiry says whose account it is
public static function accountNumber(string $number, string $name): self { /* ... */ }
// "my brother" matched nobody: not a refusal, a question
public static function unknownName(string $spokenReference): self { /* ... */ }
// ten digits that aren't an account: they almost certainly misspoke
public static function accountNotFound(string $number): self { /* ... */ }
public function isComplete(): bool
{
return $this->beneficiary !== null
|| ($this->accountNumber !== null && ! $this->accountNotFound);
}
}
Only a complete resolution can open a transaction. Everything else turns into something the user hears and answers.
Digits first
Order matters in the resolver. Ten digits are checked before any name matching:
public function resolveRecipient(User $user, ?string $reference): RecipientResolution
{
$accountNumber = $this->asAccountNumber($reference);
if ($accountNumber !== null) {
return $this->resolveAccountNumber($accountNumber);
}
$beneficiary = $this->resolve($user, $reference);
return $beneficiary !== null
? RecipientResolution::savedPayee($beneficiary)
: RecipientResolution::unknownName(trim((string) $reference));
}
"Send 2,000 to 7733992211" is a complete instruction. It should not be run past a fuzzy name matcher that might find an 80% resemblance between a number and somebody's nickname.
Spoken account numbers rarely arrive clean. They come spaced, grouped, or with words around them ("the number na 7733992211"), and sometimes as spoken numbers in Yoruba, Hausa or Pidgin. A digit parser lifts the ten digits out of whatever was said instead of requiring the whole string to look like a number. A NUBAN is ten digits, which is long enough not to collide with most other things a person says.
Matching the words the user actually says
When there are no digits, the reference is matched against the user's saved payees. Not only against the name the bank holds, but against every alias saved for that payee, because the alias is the word the user actually says. Matching on "my brother" recovers the right payee from a transcript that got the spelling wrong.
Two numbers decide whether a match counts:
private const MINIMUM_SIMILARITY = 80.0;
private const MINIMUM_MARGIN = 8.0;
// inside resolve(): score every payee by its best-matching term
usort($scored, fn (array $a, array $b): int => $b['score'] <=> $a['score']);
$winner = $scored[0];
if ($winner['score'] < self::MINIMUM_SIMILARITY) {
return null;
}
$runnerUp = $scored[1]['score'] ?? 0.0;
if ($winner['score'] - $runnerUp < self::MINIMUM_MARGIN && count($scored) > 1) {
return null;
}
return $winner['beneficiary'];
The threshold sits well above the midpoint because the two kinds of mistake don't cost the same. A false match sends money to the wrong saved payee, silently. Nobody catches that failure, because everything looked normal. A miss costs one extra question. Those aren't comparable, so the matcher is built to miss rather than guess.
The margin handles a different problem. "My sister" and "my sitter" can both score 82. That isn't a strong match; it's an ambiguous reference, and picking the higher of two near-identical scores is a coin toss with someone's money. If the winner doesn't clear the runner-up by 8 points, there is no winner.
Similarity is measured with PHP's similar_text rather than levenshtein. similar_text scores on the longest common substrings, which is a better model for a recogniser that drops or doubles a syllable than an edit distance built around single-character substitutions. Case and surrounding whitespace are normalised away first, since neither survives transcription in any meaningful way.
A miss is a question, not a risk signal
When the name matches nobody, two things don't happen.
First, no transaction is opened. A transfer with no destination isn't a transaction yet, and opening one would put a half-specified request into the state machine that money is supposed to flow through. Instead, the question is written to the voice session: "That name isn't saved. What's the account number?" The next thing the user says answers it.
When the question is asked, the intent and the amount are written down with it. When the account number arrives, the transfer is opened from what was written down, not from whatever a language model makes of a string of digits. A misheard second voice note can't change how much money moves.
Second, nothing about this counts against the user. TalkAm's risk gate runs a closed set of named monitoring rules, things like odd hours, velocity, amount, device and location. "The payee isn't saved" is deliberately not one of them. Paying someone for the first time is the most ordinary thing in banking: a trader paying a new supplier, a parent paying a school account read off a letter. Treating it as risky by definition would put a face check in front of the most common transfer there is. Whether a payee is saved is a convenience. The monitoring rules decide whether a transfer needs more than a PIN.
The name is read back before the PIN
For an account number, the bank's name enquiry runs when the recipient is resolved, not at settlement:
public function resolveAccountNumber(string $accountNumber): RecipientResolution
{
$name = $this->bank->nameEnquiry($accountNumber);
return $name === null
? RecipientResolution::accountNotFound($accountNumber)
: RecipientResolution::accountNumber($accountNumber, $name);
}
That timing is the point. The read-back message says the amount and the recipient's name before the PIN prompt opens, as two separate messages, so the one sentence the user needs to check isn't buried behind a tap. Someone who transposed two digits is far more likely to notice the wrong name than the wrong number. And a user who can't read gets the same protection as one who can, because they hear it.
If the digits aren't an account, TalkAm says so and asks again. If it heard too few or too many digits, the question stays open rather than being dropped, so the user isn't sent back to the start of a transfer they already described.
Learning the user's words
After a transfer to a new account settles, TalkAm offers to save it, phrased in the user's own words: "Save this account as 'my brother'?" The new payee is stored with the bank's account name as its name and the user's words as its alias, because the alias is what they'll say next time. Next time, "send 5,000 to my brother" resolves straight to a saved payee.
The offer only comes after the money has moved. Asking mid-transfer would put a filing question between a person and their money, and a user who ignores it loses nothing. It's answered with a button or a spoken yes, which is fine here. A tapped button posts its value into the chat thread, and "Yes" sitting in a thread is harmless. That's also exactly why a PIN never goes through a button.
What I'd carry into any payments system
- A transcript, or a model's output, is a claim. Resolve it against data you own (saved payees, the bank's own name enquiry) before money depends on it.
- Make "I don't know" a first-class outcome. A resolution that can come back as a question is easier to build safely than one that must always return an answer.
- Set thresholds from the cost of each mistake. When a false match is silent and a miss costs one question, the threshold belongs well above the middle, and a winner should also have to beat the runner-up.
- Put the checkable thing in front of the irreversible step. The account name, read back before the PIN, is the cheapest fraud and error control in the flow.
- Don't treat novelty as risk. Paying someone new is normal. Let named monitoring rules decide when to ask for more.
None of this needs a better speech model. It needs the code to be honest about what a transcript can and can't tell you.
I'm curious how others handle this: where in your systems does uncertainty turn into a question rather than a guess?
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.