progress made
This commit is contained in:
@@ -234,21 +234,53 @@ class TWP_Agent_Manager {
|
||||
// Set agent status to busy
|
||||
self::set_agent_status($user_id, 'busy', $call->call_sid);
|
||||
|
||||
// Forward the call to the agent
|
||||
// Make a new call to the agent with proper caller ID
|
||||
$twilio = new TWP_Twilio_API();
|
||||
|
||||
// Create TwiML to redirect the call
|
||||
$twiml = new \Twilio\TwiML\VoiceResponse();
|
||||
$twiml->dial($phone_number, [
|
||||
'statusCallback' => home_url('/wp-json/twilio-webhook/v1/call-status'),
|
||||
'statusCallbackEvent' => array('completed')
|
||||
]);
|
||||
|
||||
// Update the call with new TwiML
|
||||
$result = $twilio->update_call($call->call_sid, array(
|
||||
'Twiml' => $twiml->asXML()
|
||||
// Get the queue's phone number for proper caller ID (same logic as SMS webhook)
|
||||
$queues_table = $wpdb->prefix . 'twp_call_queues';
|
||||
$queue_info = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT phone_number FROM $queues_table WHERE id = %d",
|
||||
$call->queue_id
|
||||
));
|
||||
|
||||
// Priority: 1) Queue's phone number, 2) Call's original to_number, 3) Default SMS number
|
||||
$workflow_number = null;
|
||||
if (!empty($queue_info->phone_number)) {
|
||||
$workflow_number = $queue_info->phone_number;
|
||||
error_log('TWP Web Accept: Using queue phone number: ' . $workflow_number);
|
||||
} elseif (!empty($call->to_number)) {
|
||||
$workflow_number = $call->to_number;
|
||||
error_log('TWP Web Accept: Using original workflow number: ' . $workflow_number);
|
||||
} else {
|
||||
$workflow_number = TWP_Twilio_API::get_sms_from_number();
|
||||
error_log('TWP Web Accept: Using default number: ' . $workflow_number);
|
||||
}
|
||||
|
||||
// Create webhook URL for screening the agent call
|
||||
$connect_url = home_url('/wp-json/twilio-webhook/v1/agent-screen');
|
||||
$connect_url = add_query_arg(array(
|
||||
'queued_call_id' => $call_id,
|
||||
'customer_number' => $call->from_number,
|
||||
'customer_call_sid' => $call->call_sid
|
||||
), $connect_url);
|
||||
|
||||
// Create status callback URL to detect voicemail/no-answer
|
||||
$status_callback_url = home_url('/wp-json/twilio-webhook/v1/agent-call-status');
|
||||
$status_callback_url = add_query_arg(array(
|
||||
'queued_call_id' => $call_id,
|
||||
'user_id' => $user_id,
|
||||
'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
|
||||
);
|
||||
|
||||
if ($result['success']) {
|
||||
// Log the call acceptance
|
||||
TWP_Call_Logger::log_call(array(
|
||||
@@ -390,7 +422,11 @@ class TWP_Agent_Manager {
|
||||
}
|
||||
|
||||
$twilio = new TWP_Twilio_API();
|
||||
return $twilio->send_sms($phone_number, $message);
|
||||
|
||||
// Get SMS from number with proper priority (no workflow context here)
|
||||
$from_number = TWP_Twilio_API::get_sms_from_number();
|
||||
|
||||
return $twilio->send_sms($phone_number, $message, $from_number);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user