Improve call recording functionality with better debugging and Call SID detection
## Recording Issues Fixed - Enhanced Call SID detection for browser phone calls - Try multiple methods to get Call SID: parameters.CallSid, customParameters.CallSid, outgoingConnectionId, sid - Added comprehensive console logging for debugging recording issues - Better error handling and user feedback ## Backend Improvements - Verify call exists and is in-progress before attempting recording - Enhanced error logging with call status and details - Improved AJAX error responses with specific error messages - Database insert error checking and logging ## Frontend Improvements - Multiple Call SID detection methods for browser phone compatibility - Console logging of call object and Call SID for debugging - Enhanced error handling with xhr response details - Validation of active call before recording attempt ## Debugging Features - Detailed error logs in PHP error log - Console logging in browser for JavaScript debugging - Specific error messages for different failure scenarios - Call status validation to ensure recording is possible These changes should resolve the "recording not working" issue by properly detecting the Call SID for browser phone calls and providing detailed debugging information. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6771,7 +6771,25 @@ class TWP_Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function adminStartRecording() {
|
function adminStartRecording() {
|
||||||
var callSid = currentCall.parameters.CallSid || currentCall.customParameters.CallSid;
|
if (!currentCall) {
|
||||||
|
showNotice('No active call to record', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try multiple ways to get the call SID for browser phone calls
|
||||||
|
var callSid = currentCall.parameters.CallSid ||
|
||||||
|
currentCall.customParameters.CallSid ||
|
||||||
|
currentCall.outgoingConnectionId ||
|
||||||
|
currentCall.sid;
|
||||||
|
|
||||||
|
console.log('Current call object:', currentCall);
|
||||||
|
console.log('Attempting to record call SID:', callSid);
|
||||||
|
|
||||||
|
if (!callSid) {
|
||||||
|
showNotice('Could not determine call SID for recording', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var $recordBtn = $('#admin-record-btn');
|
var $recordBtn = $('#admin-record-btn');
|
||||||
|
|
||||||
$.post(ajaxurl, {
|
$.post(ajaxurl, {
|
||||||
@@ -6787,8 +6805,9 @@ class TWP_Admin {
|
|||||||
} else {
|
} else {
|
||||||
showNotice('Failed to start recording: ' + (response.data || 'Unknown error'), 'error');
|
showNotice('Failed to start recording: ' + (response.data || 'Unknown error'), 'error');
|
||||||
}
|
}
|
||||||
}).fail(function() {
|
}).fail(function(xhr, status, error) {
|
||||||
showNotice('Failed to start recording', 'error');
|
console.error('Recording start failed:', xhr.responseText);
|
||||||
|
showNotice('Failed to start recording: ' + error, 'error');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7034,10 +7053,32 @@ class TWP_Admin {
|
|||||||
$call_sid = sanitize_text_field($_POST['call_sid']);
|
$call_sid = sanitize_text_field($_POST['call_sid']);
|
||||||
$user_id = get_current_user_id();
|
$user_id = get_current_user_id();
|
||||||
|
|
||||||
|
if (empty($call_sid)) {
|
||||||
|
wp_send_json_error('Call SID is required for recording');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_log("TWP: Starting recording for call SID: $call_sid");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$twilio = new TWP_Twilio_API();
|
$twilio = new TWP_Twilio_API();
|
||||||
$client = $twilio->get_client();
|
$client = $twilio->get_client();
|
||||||
|
|
||||||
|
// First, verify the call exists and is in progress
|
||||||
|
try {
|
||||||
|
$call = $client->calls($call_sid)->fetch();
|
||||||
|
error_log("TWP: Call found - Status: {$call->status}, From: {$call->from}, To: {$call->to}");
|
||||||
|
|
||||||
|
if (!in_array($call->status, ['in-progress', 'ringing'])) {
|
||||||
|
wp_send_json_error("Cannot record call in status: {$call->status}. Call must be in-progress.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Exception $call_error) {
|
||||||
|
error_log("TWP: Error fetching call details: " . $call_error->getMessage());
|
||||||
|
wp_send_json_error("Call not found or not accessible: " . $call_error->getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Start recording the call
|
// Start recording the call
|
||||||
$recording = $client->calls($call_sid)->recordings->create([
|
$recording = $client->calls($call_sid)->recordings->create([
|
||||||
'recordingStatusCallback' => home_url('/wp-json/twilio-webhook/v1/recording-status'),
|
'recordingStatusCallback' => home_url('/wp-json/twilio-webhook/v1/recording-status'),
|
||||||
@@ -7045,14 +7086,13 @@ class TWP_Admin {
|
|||||||
'recordingChannels' => 'dual'
|
'recordingChannels' => 'dual'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
error_log("TWP: Recording created with SID: {$recording->sid}");
|
||||||
|
|
||||||
// Store recording info in database
|
// Store recording info in database
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$recordings_table = $wpdb->prefix . 'twp_call_recordings';
|
$recordings_table = $wpdb->prefix . 'twp_call_recordings';
|
||||||
|
|
||||||
// Get call details
|
$insert_result = $wpdb->insert($recordings_table, [
|
||||||
$call = $client->calls($call_sid)->fetch();
|
|
||||||
|
|
||||||
$wpdb->insert($recordings_table, [
|
|
||||||
'call_sid' => $call_sid,
|
'call_sid' => $call_sid,
|
||||||
'recording_sid' => $recording->sid,
|
'recording_sid' => $recording->sid,
|
||||||
'from_number' => $call->from,
|
'from_number' => $call->from,
|
||||||
@@ -7062,11 +7102,16 @@ class TWP_Admin {
|
|||||||
'started_at' => current_time('mysql')
|
'started_at' => current_time('mysql')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($insert_result === false) {
|
||||||
|
error_log("TWP: Database insert failed: " . $wpdb->last_error);
|
||||||
|
}
|
||||||
|
|
||||||
wp_send_json_success([
|
wp_send_json_success([
|
||||||
'message' => 'Recording started',
|
'message' => 'Recording started',
|
||||||
'recording_sid' => $recording->sid
|
'recording_sid' => $recording->sid
|
||||||
]);
|
]);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
error_log("TWP: Recording start error: " . $e->getMessage());
|
||||||
wp_send_json_error('Failed to start recording: ' . $e->getMessage());
|
wp_send_json_error('Failed to start recording: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1668,6 +1668,25 @@
|
|||||||
* Start recording the current call
|
* Start recording the current call
|
||||||
*/
|
*/
|
||||||
function startRecording() {
|
function startRecording() {
|
||||||
|
if (!currentCall || currentCall.status() !== 'open') {
|
||||||
|
showMessage('No active call to record', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try multiple ways to get the call SID
|
||||||
|
const callSid = currentCall.parameters.CallSid ||
|
||||||
|
currentCall.customParameters.CallSid ||
|
||||||
|
currentCall.outgoingConnectionId ||
|
||||||
|
currentCall.sid;
|
||||||
|
|
||||||
|
console.log('Frontend currentCall object:', currentCall);
|
||||||
|
console.log('Frontend attempting to record call SID:', callSid);
|
||||||
|
|
||||||
|
if (!callSid) {
|
||||||
|
showMessage('Could not determine call SID for recording', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const $recordBtn = $('#twp-record-btn');
|
const $recordBtn = $('#twp-record-btn');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -1675,7 +1694,7 @@
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
action: 'twp_start_recording',
|
action: 'twp_start_recording',
|
||||||
call_sid: currentCall.parameters.CallSid,
|
call_sid: callSid,
|
||||||
nonce: twp_frontend_ajax.nonce
|
nonce: twp_frontend_ajax.nonce
|
||||||
},
|
},
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
@@ -1688,8 +1707,9 @@
|
|||||||
showMessage('Failed to start recording: ' + (response.data || 'Unknown error'), 'error');
|
showMessage('Failed to start recording: ' + (response.data || 'Unknown error'), 'error');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function(xhr, status, error) {
|
||||||
showMessage('Failed to start recording', 'error');
|
console.error('Frontend recording start failed:', xhr.responseText);
|
||||||
|
showMessage('Failed to start recording: ' + error, 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user