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:
@@ -283,7 +283,12 @@ class TWP_Agent_Manager {
|
|||||||
if ($call_mode === 'browser') {
|
if ($call_mode === 'browser') {
|
||||||
// For browser mode, redirect the existing call to the browser client
|
// For browser mode, redirect the existing call to the browser client
|
||||||
$current_user = get_userdata($user_id);
|
$current_user = get_userdata($user_id);
|
||||||
$client_name = 'agent_' . $user_id . '_' . sanitize_title($current_user->display_name);
|
// Twilio requires alphanumeric characters only - must match generate_capability_token
|
||||||
|
$clean_name = preg_replace('/[^a-zA-Z0-9]/', '', $current_user->display_name);
|
||||||
|
if (empty($clean_name)) {
|
||||||
|
$clean_name = 'user';
|
||||||
|
}
|
||||||
|
$client_name = 'agent' . $user_id . $clean_name;
|
||||||
|
|
||||||
// Create TwiML to redirect call to browser client
|
// Create TwiML to redirect call to browser client
|
||||||
$twiml = new \Twilio\TwiML\VoiceResponse();
|
$twiml = new \Twilio\TwiML\VoiceResponse();
|
||||||
|
@@ -408,7 +408,12 @@ class TWP_Webhooks {
|
|||||||
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
|
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
|
||||||
|
|
||||||
if ($call_mode === 'browser') {
|
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;
|
$browser_agents[] = $client_name;
|
||||||
} elseif (!empty($agent_phone)) {
|
} elseif (!empty($agent_phone)) {
|
||||||
$cell_agents[] = $agent_phone;
|
$cell_agents[] = $agent_phone;
|
||||||
@@ -485,7 +490,12 @@ class TWP_Webhooks {
|
|||||||
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
|
$agent_phone = get_user_meta($agent->ID, 'twp_phone_number', true);
|
||||||
|
|
||||||
if ($call_mode === 'browser') {
|
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;
|
$browser_agents[] = $client_name;
|
||||||
} elseif (!empty($agent_phone)) {
|
} elseif (!empty($agent_phone)) {
|
||||||
$cell_agents[] = $agent_phone;
|
$cell_agents[] = $agent_phone;
|
||||||
|
@@ -458,7 +458,12 @@ class TWP_Workflow {
|
|||||||
));
|
));
|
||||||
|
|
||||||
foreach ($agents as $agent) {
|
foreach ($agents as $agent) {
|
||||||
$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;
|
||||||
$client = $dial->addChild('Client', $client_name);
|
$client = $dial->addChild('Client', $client_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user