From e65004fa9f742342305ca28bce5614df0c70f1e6 Mon Sep 17 00:00:00 2001 From: Danny Gershman Date: Wed, 25 Jul 2018 00:29:47 -0400 Subject: [PATCH] fix for #112 --- helpline-dialer.php | 20 ++++++++++++++------ voicemail-complete.php | 2 +- voicemail.php | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/helpline-dialer.php b/helpline-dialer.php index 802bc269b..6014170f6 100644 --- a/helpline-dialer.php +++ b/helpline-dialer.php @@ -12,12 +12,11 @@ class CallConfig { function getCallConfig($client, $serviceBodyConfiguration) { $tracker = !isset( $_REQUEST["tracker"] ) ? 0 : $_REQUEST["tracker"]; - $numbers = $client->incomingPhoneNumbers->read( array( "phoneNumber" => $_REQUEST['Caller'] ) ); - $voice_url = $numbers[0]->voiceUrl; + $voice_url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; if (strpos(basename($voice_url), ".php")) { $webhook_url = substr( $voice_url, 0, strrpos( $voice_url, "/" ) ); } else if (strpos($voice_url, "?")) { - $webhook_url = substr( $voice_url, 0, strrpos( $voice_url, "?" ) ); + $webhook_url = substr( $voice_url, 0, strrpos( $voice_url, "?" ) ); } else { $webhook_url = $voice_url; } @@ -28,16 +27,25 @@ function getCallConfig($client, $serviceBodyConfiguration) { $caller_id = isset( $_REQUEST["Caller"] ) ? $_REQUEST["Caller"] : SpecialPhoneNumber::UNKNOWN; } + if (isset( $_REQUEST["OriginalCallerId"] )) { + $original_caller_id = $_REQUEST["OriginalCallerId"]; + } elseif (isset($_REQUEST["Caller"])) { + $original_caller_id = $_REQUEST["Caller"]; + } else { + $original_caller_id = SpecialPhoneNumber::UNKNOWN; + } + $config = new CallConfig(); $config->phone_number = getHelplineVolunteer( $serviceBodyConfiguration->service_body_id, $tracker, $serviceBodyConfiguration->call_strategy ); $config->voicemail_url = $webhook_url . '/voicemail.php?service_body_id=' . $serviceBodyConfiguration->service_body_id . '&caller_id=' . trim($caller_id); $config->options = array( 'url' => $webhook_url . '/helpline-outdial-response.php?conference_name=' . $_REQUEST['FriendlyName'], - 'statusCallback' => $webhook_url . '/helpline-dialer.php?service_body_id=' . $serviceBodyConfiguration->service_body_id . '&tracker=' . ++ $tracker . '&FriendlyName=' . $_REQUEST['FriendlyName'], + 'statusCallback' => $webhook_url . '/helpline-dialer.php?service_body_id=' . $serviceBodyConfiguration->service_body_id . '&tracker=' . ++$tracker . '&FriendlyName=' . $_REQUEST['FriendlyName'] . '&OriginalCallerId=' . trim($original_caller_id), 'statusCallbackEvent' => 'completed', 'statusCallbackMethod' => 'GET', 'timeout' => $serviceBodyConfiguration->call_timeout, - 'callerId' => $caller_id + 'callerId' => $caller_id, + 'originalCallerId' => $original_caller_id ); return $config; @@ -84,7 +92,7 @@ function getCallConfig($client, $serviceBodyConfiguration) { $callConfig->phone_number, array( "body" => "You have an incoming helpline call from " . $callerNumber . ".", - "from" => $callConfig->options['callerId'] + "from" => $callConfig->options['originalCallerId'] ) ); } diff --git a/voicemail-complete.php b/voicemail-complete.php index 9e1a35bfb..a4a8867d3 100644 --- a/voicemail-complete.php +++ b/voicemail-complete.php @@ -21,7 +21,7 @@ $client->messages->create( $serviceBodyConfiguration->primary_contact_number, array( - "from" => $_REQUEST["caller_id"], + "from" => $_REQUEST["called_number"], "body" => "You have a message from the " . $serviceBodyName . " helpline from caller " . $_REQUEST["caller_number"] . ", " . $_REQUEST["RecordingUrl"] ) ); diff --git a/voicemail.php b/voicemail.php index b48c018d2..e36bf9c83 100644 --- a/voicemail.php +++ b/voicemail.php @@ -16,7 +16,7 @@ &caller_id=&caller_number=" + recordingStatusCallback="voicemail-complete.php?service_body_id=&caller_id=&caller_number=&called_number=" recordingStatusCallbackMethod="GET" maxLength="120" timeout="15"/>