Fix browser phone client name mismatch causing immediate disconnection

- Standardized client name generation across all files to use alphanumeric only
- Fixed mismatch between token generation and call routing that caused calls to disconnect
- Updated TWP_Workflow, TWP_Webhooks, and TWP_Agent_Manager to use same format
- Client names now consistently formatted as 'agent123Username' without underscores

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-13 10:21:57 -07:00
parent c0f0ea8158
commit 30b0cd355f
3 changed files with 24 additions and 4 deletions

View File

@@ -408,7 +408,12 @@ class TWP_Webhooks {
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
if ($call_mode === 'browser') {
$client_name = 'agent_' . $agent->ID . '_' . sanitize_title($agent->display_name);
// Twilio requires alphanumeric characters only
$clean_name = preg_replace('/[^a-zA-Z0-9]/', '', $agent->display_name);
if (empty($clean_name)) {
$clean_name = 'user';
}
$client_name = 'agent' . $agent->ID . $clean_name;
$browser_agents[] = $client_name;
} elseif (!empty($agent_phone)) {
$cell_agents[] = $agent_phone;
@@ -485,7 +490,12 @@ class TWP_Webhooks {
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
if ($call_mode === 'browser') {
$client_name = 'agent_' . $agent->ID . '_' . sanitize_title($agent->display_name);
// Twilio requires alphanumeric characters only
$clean_name = preg_replace('/[^a-zA-Z0-9]/', '', $agent->display_name);
if (empty($clean_name)) {
$clean_name = 'user';
}
$client_name = 'agent' . $agent->ID . $clean_name;
$browser_agents[] = $client_name;
} elseif (!empty($agent_phone)) {
$cell_agents[] = $agent_phone;