Enhance recording debugging and fix outbound call number detection
Recording Proxy Improvements: - Enhanced error handling to prevent JSON responses instead of audio - Added comprehensive logging for Twilio API calls - Added fallback URL construction from recording SID if URL missing - Improved error responses with proper HTTP headers Outbound Call Phone Number Detection: - Enhanced logic to find customer numbers in complex call structures - Added search through related calls to find customer phone numbers - Comprehensive logging for debugging outbound call number assignment - Handles cases where 'to' field might be empty or contain client identifiers These changes should resolve: 1. Recording playback returning JSON instead of audio files 2. Missing customer phone numbers in outbound call recordings 3. Better error reporting and debugging capabilities 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1203,15 +1203,34 @@ class TWP_Webhooks {
|
||||
$table_name = $wpdb->prefix . 'twp_call_recordings';
|
||||
|
||||
$recording = $wpdb->get_row($wpdb->prepare(
|
||||
"SELECT recording_url FROM $table_name WHERE id = %d",
|
||||
"SELECT recording_url, recording_sid FROM $table_name WHERE id = %d",
|
||||
$recording_id
|
||||
));
|
||||
|
||||
if (!$recording || !$recording->recording_url) {
|
||||
error_log("TWP Recording Proxy: Looking for recording ID: $recording_id");
|
||||
|
||||
if (!$recording) {
|
||||
error_log("TWP Recording Proxy: No recording found in database for ID: $recording_id");
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
exit('Recording not found');
|
||||
}
|
||||
|
||||
if (!$recording->recording_url) {
|
||||
error_log("TWP Recording Proxy: Recording found but no URL. Recording SID: " . ($recording->recording_sid ?: 'none'));
|
||||
|
||||
// If we have a recording SID but no URL, try to construct the URL
|
||||
if ($recording->recording_sid) {
|
||||
$account_sid = get_option('twp_twilio_account_sid');
|
||||
$recording->recording_url = "https://api.twilio.com/2010-04-01/Accounts/$account_sid/Recordings/{$recording->recording_sid}";
|
||||
error_log("TWP Recording Proxy: Constructed URL from SID: " . $recording->recording_url);
|
||||
} else {
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
exit('Recording URL not available');
|
||||
}
|
||||
}
|
||||
|
||||
error_log("TWP Recording Proxy: Recording URL: " . $recording->recording_url);
|
||||
|
||||
// Fetch the audio from Twilio using authenticated request
|
||||
$twilio = new TWP_Twilio_API();
|
||||
$account_sid = get_option('twp_twilio_account_sid');
|
||||
@@ -1232,7 +1251,19 @@ class TWP_Webhooks {
|
||||
));
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
return new WP_Error('fetch_error', 'Unable to fetch recording', array('status' => 500));
|
||||
error_log('TWP Recording Proxy: Failed to fetch audio - ' . $response->get_error_message());
|
||||
header('HTTP/1.0 500 Internal Server Error');
|
||||
exit('Unable to fetch recording: ' . $response->get_error_message());
|
||||
}
|
||||
|
||||
// Log the response for debugging
|
||||
$response_code = wp_remote_retrieve_response_code($response);
|
||||
error_log("TWP Recording Proxy: Twilio response code: $response_code for URL: $audio_url");
|
||||
|
||||
if ($response_code !== 200) {
|
||||
error_log('TWP Recording Proxy: Non-200 response from Twilio: ' . wp_remote_retrieve_body($response));
|
||||
header('HTTP/1.0 404 Not Found');
|
||||
exit('Recording not available from Twilio');
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
|
Reference in New Issue
Block a user