code push
This commit is contained in:
@@ -658,11 +658,10 @@ class TWP_Webhooks {
|
||||
* Send default response
|
||||
*/
|
||||
private function send_default_response() {
|
||||
$twiml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><Response></Response>');
|
||||
$say = $twiml->addChild('Say', 'Thank you for calling. Goodbye.');
|
||||
$say->addAttribute('voice', 'alice');
|
||||
$twiml->addChild('Hangup');
|
||||
echo $twiml->asXML();
|
||||
$response = new \Twilio\TwiML\VoiceResponse();
|
||||
$response->say('Thank you for calling. Goodbye.', ['voice' => 'alice']);
|
||||
$response->hangup();
|
||||
echo $response->asXML();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1074,17 +1073,13 @@ class TWP_Webhooks {
|
||||
error_log('TWP Outbound Webhook - All params: ' . print_r($params, true));
|
||||
|
||||
if ($target_number && $from_number) {
|
||||
// Create TwiML to call the target number with the specified from number
|
||||
$twiml = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$twiml .= '<Response>';
|
||||
$twiml .= '<Say voice="alice">Connecting your outbound call...</Say>';
|
||||
$twiml .= '<Dial callerId="' . esc_attr($from_number) . '" timeout="30">';
|
||||
$twiml .= '<Number>' . esc_html($target_number) . '</Number>';
|
||||
$twiml .= '</Dial>';
|
||||
$twiml .= '<Say voice="alice">The number you called is not available. Please try again later.</Say>';
|
||||
$twiml .= '</Response>';
|
||||
// Create TwiML using SDK directly
|
||||
$response = new \Twilio\TwiML\VoiceResponse();
|
||||
$response->say('Connecting your outbound call...', ['voice' => 'alice']);
|
||||
$response->dial($target_number, ['callerId' => $from_number, 'timeout' => 30]);
|
||||
|
||||
return $this->send_twiml_response($twiml);
|
||||
// If call isn't answered, the TwiML will handle the fallback
|
||||
return $this->send_twiml_response($response->asXML());
|
||||
} else {
|
||||
// Enhanced error message with debugging info
|
||||
$error_msg = 'Unable to process outbound call.';
|
||||
@@ -1097,16 +1092,18 @@ class TWP_Webhooks {
|
||||
|
||||
error_log('TWP Outbound Error: ' . $error_msg . ' Params: ' . json_encode($params));
|
||||
|
||||
$twiml = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$twiml .= '<Response><Say voice="alice">' . esc_html($error_msg) . '</Say><Hangup/></Response>';
|
||||
return $this->send_twiml_response($twiml);
|
||||
$error_response = new \Twilio\TwiML\VoiceResponse();
|
||||
$error_response->say($error_msg, ['voice' => 'alice']);
|
||||
$error_response->hangup();
|
||||
return $this->send_twiml_response($error_response->asXML());
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log('TWP Outbound Webhook Exception: ' . $e->getMessage());
|
||||
$twiml = '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
$twiml .= '<Response><Say voice="alice">Technical error occurred. Please try again.</Say><Hangup/></Response>';
|
||||
return $this->send_twiml_response($twiml);
|
||||
$exception_response = new \Twilio\TwiML\VoiceResponse();
|
||||
$exception_response->say('Technical error occurred. Please try again.', ['voice' => 'alice']);
|
||||
$exception_response->hangup();
|
||||
return $this->send_twiml_response($exception_response->asXML());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user