Fix phone number speech formatting for agent announcements
Updated the format_phone_number_for_speech function to properly read phone numbers digit by digit instead of as large numbers. Changes: - Phone number 9095737372 now reads as "9 0 9, 5 7 3, 7 3 7 2" - Instead of "nine hundred nine, five hundred seventy three" - Added proper digit separation with commas for natural speech flow - Handles both 10-digit and 11-digit (with country code) numbers - Strips all non-numeric characters before processing This makes the agent announcement much clearer when receiving forwarded calls. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2975,17 +2975,32 @@ class TWP_Webhooks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format phone number for speech (adds pauses between digits)
|
* Format phone number for speech (reads each digit individually)
|
||||||
*/
|
*/
|
||||||
private function format_phone_number_for_speech($number) {
|
private function format_phone_number_for_speech($number) {
|
||||||
// Remove +1 country code and format for speech
|
// Remove +1 country code and any formatting
|
||||||
$cleaned = preg_replace('/^\+1/', '', $number);
|
$cleaned = preg_replace('/^\+1/', '', $number);
|
||||||
|
$cleaned = preg_replace('/[^0-9]/', '', $cleaned);
|
||||||
|
|
||||||
if (strlen($cleaned) == 10) {
|
if (strlen($cleaned) == 10) {
|
||||||
// Format as (xxx) xxx-xxxx with pauses
|
// Break into individual digits with pauses for natural speech
|
||||||
return substr($cleaned, 0, 3) . ' ' . substr($cleaned, 3, 3) . ' ' . substr($cleaned, 6, 4);
|
// Area code: 9-0-9, Main number: 5-7-3-7-3-7-2
|
||||||
|
$area_code = str_split(substr($cleaned, 0, 3));
|
||||||
|
$exchange = str_split(substr($cleaned, 3, 3));
|
||||||
|
$number_part = str_split(substr($cleaned, 6, 4));
|
||||||
|
|
||||||
|
// Join with spaces so TTS reads each digit individually
|
||||||
|
return implode(' ', $area_code) . ', ' . implode(' ', $exchange) . ', ' . implode(' ', $number_part);
|
||||||
|
} elseif (strlen($cleaned) == 11 && substr($cleaned, 0, 1) == '1') {
|
||||||
|
// Handle numbers that still have the 1 prefix
|
||||||
|
$area_code = str_split(substr($cleaned, 1, 3));
|
||||||
|
$exchange = str_split(substr($cleaned, 4, 3));
|
||||||
|
$number_part = str_split(substr($cleaned, 7, 4));
|
||||||
|
|
||||||
|
return implode(' ', $area_code) . ', ' . implode(' ', $exchange) . ', ' . implode(' ', $number_part);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $number;
|
// Fallback: just break into individual digits
|
||||||
|
return implode(' ', str_split($cleaned));
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user