testing progress

This commit is contained in:
2025-08-12 07:18:25 -07:00
parent b3ca14a151
commit 2d8420c7a2
2 changed files with 49 additions and 18 deletions

View File

@@ -3738,19 +3738,24 @@ class TWP_Admin {
global $wpdb; global $wpdb;
$calls_table = $wpdb->prefix . 'twp_queued_calls'; $calls_table = $wpdb->prefix . 'twp_queued_calls';
$queues_table = $wpdb->prefix . 'twp_call_queues'; $queues_table = $wpdb->prefix . 'twp_call_queues';
$groups_table = $wpdb->prefix . 'twp_group_members';
$waiting_calls = $wpdb->get_results(" $user_id = get_current_user_id();
// Get waiting calls only from queues the user is a member of
$waiting_calls = $wpdb->get_results($wpdb->prepare("
SELECT SELECT
c.*, c.*,
q.queue_name, q.queue_name,
TIMESTAMPDIFF(SECOND, c.joined_at, NOW()) as wait_seconds TIMESTAMPDIFF(SECOND, c.joined_at, NOW()) as wait_seconds
FROM $calls_table c FROM $calls_table c
JOIN $queues_table q ON c.queue_id = q.id JOIN $queues_table q ON c.queue_id = q.id
WHERE c.status = 'waiting' JOIN $groups_table gm ON gm.group_id = q.agent_group_id
WHERE c.status = 'waiting' AND gm.user_id = %d
ORDER BY c.position ASC ORDER BY c.position ASC
"); ", $user_id));
wp_send_json_success($waiting_calls); wp_send_json_success(['waiting_calls' => $waiting_calls]);
} }
/** /**
@@ -5430,12 +5435,13 @@ class TWP_Admin {
codecPreferences: ['opus', 'pcmu'] codecPreferences: ['opus', 'pcmu']
}); });
Twilio.Device.ready(function(device) { // Use modern EventEmitter interface instead of deprecated callbacks
Twilio.Device.on('ready', function(device) {
$('#phone-status').text('Ready').css('color', '#4CAF50'); $('#phone-status').text('Ready').css('color', '#4CAF50');
$('#call-btn').prop('disabled', false); $('#call-btn').prop('disabled', false);
}); });
Twilio.Device.error(function(error) { Twilio.Device.on('error', function(error) {
console.error('Twilio Device Error:', error); console.error('Twilio Device Error:', error);
var errorMsg = error.message; var errorMsg = error.message;
@@ -5452,7 +5458,7 @@ class TWP_Admin {
showError(errorMsg); showError(errorMsg);
}); });
Twilio.Device.connect(function(conn) { Twilio.Device.on('connect', function(conn) {
currentConnection = conn; currentConnection = conn;
$('#phone-status').text('Connected').css('color', '#2196F3'); $('#phone-status').text('Connected').css('color', '#2196F3');
$('#call-btn').hide(); $('#call-btn').hide();
@@ -5462,7 +5468,7 @@ class TWP_Admin {
startCallTimer(); startCallTimer();
}); });
Twilio.Device.disconnect(function(conn) { Twilio.Device.on('disconnect', function(conn) {
currentConnection = null; currentConnection = null;
$('#phone-status').text('Ready').css('color', '#4CAF50'); $('#phone-status').text('Ready').css('color', '#4CAF50');
$('#hangup-btn').hide(); $('#hangup-btn').hide();
@@ -5474,7 +5480,7 @@ class TWP_Admin {
stopCallTimer(); stopCallTimer();
}); });
Twilio.Device.incoming(function(conn) { Twilio.Device.on('incoming', function(conn) {
currentConnection = conn; currentConnection = conn;
$('#phone-status').text('Incoming Call').css('color', '#FF9800'); $('#phone-status').text('Incoming Call').css('color', '#FF9800');
$('#phone-number-display').text(conn.parameters.From || 'Unknown Number'); $('#phone-number-display').text(conn.parameters.From || 'Unknown Number');

View File

@@ -212,10 +212,16 @@ class TWP_Agent_Manager {
return array('success' => false, 'error' => 'Call not found or already answered'); return array('success' => false, 'error' => 'Call not found or already answered');
} }
// Get user's phone number // Check user's call mode
$call_mode = get_user_meta($user_id, 'twp_call_mode', true);
if (empty($call_mode)) {
$call_mode = 'cell'; // Default to cell phone
}
// Get user's phone number (needed for cell mode and as fallback)
$phone_number = get_user_meta($user_id, 'twp_phone_number', true); $phone_number = get_user_meta($user_id, 'twp_phone_number', true);
if (!$phone_number) { if ($call_mode === 'cell' && !$phone_number) {
return array('success' => false, 'error' => 'No phone number configured for user'); return array('success' => false, 'error' => 'No phone number configured for user');
} }
@@ -273,13 +279,32 @@ class TWP_Agent_Manager {
'original_call_sid' => $call->call_sid 'original_call_sid' => $call->call_sid
), $status_callback_url); ), $status_callback_url);
// Make call to agent with proper workflow number as caller ID and status tracking // Handle different call modes
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);
// Create TwiML to redirect call to browser client
$twiml = new \Twilio\TwiML\VoiceResponse();
$twiml->say('Connecting you to an agent.', ['voice' => 'alice']);
$dial = $twiml->dial(['timeout' => 30]);
$dial->client($client_name);
// Update the existing call to redirect to browser
$result = $twilio->update_call($call->call_sid, [
'twiml' => $twiml->asXML()
]);
} else {
// For cell mode, make call to agent's phone number
$result = $twilio->make_call( $result = $twilio->make_call(
$phone_number, $phone_number,
$connect_url, $connect_url,
$status_callback_url, // Track call status for voicemail detection $status_callback_url, // Track call status for voicemail detection
$workflow_number // Use queue's phone number as caller ID $workflow_number // Use queue's phone number as caller ID
); );
}
if ($result['success']) { if ($result['success']) {
// Log the call acceptance // Log the call acceptance