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

@@ -212,10 +212,16 @@ class TWP_Agent_Manager {
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);
if (!$phone_number) {
if ($call_mode === 'cell' && !$phone_number) {
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
), $status_callback_url);
// Make call to agent with proper workflow number as caller ID and status tracking
$result = $twilio->make_call(
$phone_number,
$connect_url,
$status_callback_url, // Track call status for voicemail detection
$workflow_number // Use queue's phone number as caller ID
);
// 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(
$phone_number,
$connect_url,
$status_callback_url, // Track call status for voicemail detection
$workflow_number // Use queue's phone number as caller ID
);
}
if ($result['success']) {
// Log the call acceptance