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

@@ -283,7 +283,12 @@ class TWP_Agent_Manager {
if ($call_mode === 'browser') {
// For browser mode, redirect the existing call to the browser client
$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
$twiml = new \Twilio\TwiML\VoiceResponse();