Add FCM push notifications, queue alerts, caller ID fixes, and auto-revert agent status
All checks were successful
Create Release / build (push) Successful in 6s
All checks were successful
Create Release / build (push) Successful in 6s
Server-side: - Add push credential auto-creation for FCM incoming call notifications - Add queue alert FCM notifications (data-only for background delivery) - Add queue alert cancellation on call accept/disconnect - Fix caller ID to show caller's number instead of Twilio number - Fix FCM token storage when refresh_token is null - Add pre_call_status tracking to revert agent status 30s after call ends - Add SSE fallback polling for mobile app connectivity Mobile app: - Add Android telecom permissions and phone account registration - Add VoiceFirebaseMessagingService for incoming call push handling - Add insistent queue alert notifications with custom sound - Fix caller number display on active call screen - Add caller ID selection dropdown on dashboard - Add phone numbers endpoint and provider support - Add unit tests for CallInfo, QueueState, and CallProvider - Remove local.properties from tracking, add .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -619,35 +619,35 @@ class TWP_Agent_Manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and revert agents from auto-busy to available after 1 minute
|
||||
* Check and revert agents from auto-busy to their previous status after 30 seconds
|
||||
*/
|
||||
public static function revert_auto_busy_agents() {
|
||||
global $wpdb;
|
||||
$table_name = $wpdb->prefix . 'twp_agent_status';
|
||||
|
||||
// Find agents who have been auto-busy for more than 1 minute and are still logged in
|
||||
$cutoff_time = date('Y-m-d H:i:s', strtotime('-1 minute'));
|
||||
|
||||
|
||||
// Find agents who have been auto-busy for more than 30 seconds and are still logged in
|
||||
$cutoff_time = date('Y-m-d H:i:s', strtotime('-30 seconds'));
|
||||
|
||||
$auto_busy_agents = $wpdb->get_results($wpdb->prepare(
|
||||
"SELECT user_id, current_call_sid FROM $table_name
|
||||
WHERE status = 'busy'
|
||||
AND auto_busy_at IS NOT NULL
|
||||
"SELECT user_id, current_call_sid, pre_call_status FROM $table_name
|
||||
WHERE status = 'busy'
|
||||
AND auto_busy_at IS NOT NULL
|
||||
AND auto_busy_at < %s
|
||||
AND is_logged_in = 1",
|
||||
$cutoff_time
|
||||
));
|
||||
|
||||
|
||||
foreach ($auto_busy_agents as $agent) {
|
||||
// Verify the call is actually finished before reverting
|
||||
$call_sid = $agent->current_call_sid;
|
||||
$call_active = false;
|
||||
|
||||
|
||||
if ($call_sid) {
|
||||
// Check if call is still active using Twilio API
|
||||
try {
|
||||
$api = new TWP_Twilio_API();
|
||||
$call_status = $api->get_call_status($call_sid);
|
||||
|
||||
|
||||
// If call is still in progress, don't revert yet
|
||||
if (in_array($call_status, ['queued', 'ringing', 'in-progress'])) {
|
||||
$call_active = true;
|
||||
@@ -655,17 +655,25 @@ class TWP_Agent_Manager {
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("TWP Auto-Revert: Could not check call status for {$call_sid}: " . $e->getMessage());
|
||||
// If we can't check call status, assume it's finished and proceed with revert
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Only revert if call is not active
|
||||
if (!$call_active) {
|
||||
error_log("TWP Auto-Revert: Reverting user {$agent->user_id} from auto-busy to available");
|
||||
self::set_agent_status($agent->user_id, 'available', null, false);
|
||||
$revert_to = !empty($agent->pre_call_status) ? $agent->pre_call_status : 'available';
|
||||
error_log("TWP Auto-Revert: Reverting user {$agent->user_id} from busy to {$revert_to}");
|
||||
self::set_agent_status($agent->user_id, $revert_to, null, false);
|
||||
// Clear pre_call_status
|
||||
$wpdb->update(
|
||||
$table_name,
|
||||
array('pre_call_status' => null),
|
||||
array('user_id' => $agent->user_id),
|
||||
array('%s'),
|
||||
array('%d')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return count($auto_busy_agents);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user