Skip to content

Commit

Permalink
fix for #112
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny Gershman committed Jul 25, 2018
1 parent 4a03d1f commit e65004f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions helpline-dialer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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']
) );
}

Expand Down
2 changes: 1 addition & 1 deletion voicemail-complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
)
);
Expand Down
2 changes: 1 addition & 1 deletion voicemail.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?php } ?>
<Record
playBeep="true"
recordingStatusCallback="voicemail-complete.php?service_body_id=<?php echo setting("service_body_id") ?>&amp;caller_id=<?php echo urlencode($_REQUEST["caller_id"])?>&amp;caller_number=<?php echo urlencode($_REQUEST["caller_number"])?>"
recordingStatusCallback="voicemail-complete.php?service_body_id=<?php echo setting("service_body_id") ?>&amp;caller_id=<?php echo urlencode($_REQUEST["caller_id"])?>&amp;caller_number=<?php echo urlencode($_REQUEST["caller_number"])?>&amp;called_number=<?php echo urlencode($_REQUEST["Called"])?>"
recordingStatusCallbackMethod="GET"
maxLength="120"
timeout="15"/>
Expand Down

0 comments on commit e65004f

Please sign in to comment.