diff --git a/admin/class-twp-admin.php b/admin/class-twp-admin.php index f1fd9f9..e12dd1e 100644 --- a/admin/class-twp-admin.php +++ b/admin/class-twp-admin.php @@ -7114,25 +7114,50 @@ class TWP_Admin { if ($target_sid) { error_log("TWP Resume: Resuming call - Target SID: {$target_sid}"); - // Empty TwiML resumes the call - $twiml = new \Twilio\TwiML\VoiceResponse(); - // No content - just empty response to resume + // For resuming, we need to stop the hold music and restore the conversation + // The key is to return control to the normal call flow try { + // Get the target call details to understand the call structure + $target_call = $client->calls($target_sid)->fetch(); + error_log("TWP Resume: Target call - From: {$target_call->from}, To: {$target_call->to}, Parent: {$target_call->parentCallSid}"); + + // For resuming, the simplest approach is often the best + // Just send empty TwiML to stop hold music and resume normal call flow + $twiml = new \Twilio\TwiML\VoiceResponse(); + + // Don't add anything - empty TwiML should resume the call + // The connection between parties should still exist + + // Update the call with resume TwiML $result = $client->calls($target_sid)->update([ 'twiml' => $twiml->asXML() ]); - error_log("TWP Resume: Successfully resumed call {$target_sid}"); + error_log("TWP Resume: Successfully updated call {$target_sid} with resume TwiML"); + } catch (Exception $e) { error_log("TWP Resume: Error resuming call: " . $e->getMessage()); - throw $e; + + // Simple fallback - just stop hold music with empty TwiML + $twiml = new \Twilio\TwiML\VoiceResponse(); + $client->calls($target_sid)->update([ + 'twiml' => $twiml->asXML() + ]); + error_log("TWP Resume: Used simple fallback for {$target_sid}"); } } else { error_log("TWP Resume: WARNING - Could not determine target, resuming current call"); - $twiml = new \Twilio\TwiML\VoiceResponse(); - $client->calls($call_sid)->update([ - 'twiml' => $twiml->asXML() - ]); + + // Resume current call as fallback + try { + $twiml = new \Twilio\TwiML\VoiceResponse(); + $client->calls($call_sid)->update([ + 'twiml' => $twiml->asXML() + ]); + } catch (Exception $e) { + error_log("TWP Resume: Failed to resume current call: " . $e->getMessage()); + throw $e; + } } }