fix(voice): harden destination parsing and phone matching#46
Merged
ByteStreams-AI merged 2 commits intomainfrom May 6, 2026
Merged
fix(voice): harden destination parsing and phone matching#46ByteStreams-AI merged 2 commits intomainfrom
ByteStreams-AI merged 2 commits intomainfrom
Conversation
Owner
Author
|
Addressed review feedback in 1b22cac:
|
This was referenced May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #44
Hardens vapi call-start by:
Prevents brittle call-start failures caused by format/schema drift.
Greptile Summary
This PR hardens the Vapi call-start handler against phone number format and payload schema drift. The restaurant phone lookup is switched from an exact DB match to a normalized candidate query, and the destination phone extraction now handles both
phoneNumber.number(nested) andphoneNumber(direct string) payload shapes.context.ts:lookupRestaurantByDestinationnow generates 2–3 normalized candidate strings viaphoneLookupCandidates, queries with.in('phone_number', candidates)(preserving the DB index), then appliesnormalizeUsE164ishin-memory to confirm the match. A warning is emitted when multiple restaurants normalize to the same destination number.index.ts: Three new fallback paths are added tofirstString(...)fordestinationPhone, covering Vapi payloads wherephoneNumberis a raw string instead of an object. The validation error message is updated to describe all accepted shapes.Confidence Score: 5/5
Safe to merge — the lookup change preserves DB-side filtering and the new fallback paths in the webhook handler are correctly guarded by type-checking within
deepReadString.Both changes are narrowly scoped defensive fixes. The DB query now uses
.in()over a small, bounded candidate list, restoring index usage. The newphoneNumber-as-string fallbacks only activate whentypeof value === 'string', so they cannot accidentally capture object payloads. The normalization logic is correct for all US E164 variants (10-digit, 11-digit with leading 1,+-prefixed). No regressions are introduced to the existing happy path.No files require special attention.
Important Files Changed
.in()over normalized candidate variants; adds in-memory normalization filter and multi-match warning. The full-table-scan concern from the previous review is addressed.phoneNumberas a direct string (notphoneNumber.numberobject). Error message updated to reflect the broader accepted shapes. Logic is correct —deepReadStringreturns null for object values, so the new paths only fire for string payloads.Comments Outside Diff (1)
supabase/functions/vapi_call_start/index.ts, line 159 (link)phoneNumber.number, but this PR adds three new fallback paths that acceptphoneNumberas a direct string. Callers who hit the validation guard will get a misleading message that doesn't mention the new accepted shapes.Reviews (2): Last reviewed commit: "fix(voice): address PR #46 review on loo..." | Re-trigger Greptile