Пример #1
0
$page_size = 20;
$call_try[1] = 'First';
$call_try[2] = 'Second';
$call_try[3] = 'Third';
$call_try[4] = 'Fourth';
$call_try[5] = 'Fifth';
$call_try[6] = 'Sixth';
$call_try[7] = 'Seventh';
$call_try[8] = 'Eighth';
$call_try[9] = 'Ninth';
$call_try[10] = 'Tenth';
if (isset($_REQUEST['change_call_status']) && $_REQUEST['change_call_status'] == "1") {
    if ($_REQUEST['curr_status'] == "on") {
        qu("config", array("value" => "off"), "`key`='CALL_STATUS'");
    } else {
        qu("config", array("value" => "on"), "`key`='CALL_STATUS'");
    }
    die;
}
if (isset($_REQUEST['download']) && $_REQUEST['download'] == 3) {
    $destination_name_ulaw = "https://api.twilio.com/2010-04-01/Accounts/" . ACCOUNT_SID . "/Recordings/RE338a2c7e3153c26600a45d42c6c4b358.wav";
    $src = $destination_name_ulaw;
    $dest = _PATH . "b.wav";
    file_put_contents($dest, file_get_contents($src));
    die;
    exit;
}
if (isset($_REQUEST['download'])) {
    //$destination_name_ulaw1 = 'a.wav';
    $destination_name_ulaw = _PATH . 'RE338a2c7e3153c26600a45d42c6c4b358.wav';
    //$destination_name_ulaw = "https://api.twilio.com/2010-04-01/Accounts/".ACCOUNT_SID."/Recordings/RE338a2c7e3153c26600a45d42c6c4b358";
        $dealId = $each_data['deal_id'];
        $apiCall = new callWebhook();
        $apiCall->callNow($phone_value, $new_agent_numbers, $dealId, "0");
        echo "<br><br>Call Generated -<br>Agents:";
        d($new_agent_numbers);
        echo "<br>Customer Phone:";
    }
}
$agent_call_detail = q("SELECT deal_id,customer_phone, is_mail_send,COUNT(id) FROM `agent_call_dialed` where is_redial='0'  AND modified_at>=CURRENT_DATE  - INTERVAL 1 DAY GROUP BY deal_id HAVING COUNT(id)>=5");
foreach ($agent_call_detail as $each_data) {
    if ($each_data['is_mail_send'] == '0') {
        $apiPD = new apiPipeDrive();
        $deal_data = json_decode($apiPD->getDealInfo($each_data['deal_id']));
        $source_id = isset($deal_data->data->c2a6fc3129578b646ae55717ed15f03ce3ee4df0) ? $deal_data->data->c2a6fc3129578b646ae55717ed15f03ce3ee4df0 : '';
        //qi("call_detail",  _escapeArray(array("deal_id"=>$each_data['deal_id'],"recording_duration"=>"0","source_id"=>$source_id)));
        qu("agent_call_dialed", _escapeArray(array("is_mail_send" => "1")), " deal_id='{$each_data['deal_id']}'");
        $dealId = $each_data['deal_id'];
        //$dealId = "5232";// Test Mode
        $apiPD = new apiPipeDrive();
        $deal_data = $apiPD->getDealInfo($dealId);
        $deal_data = json_decode($deal_data);
        $deal_amount = number_format($deal_data->data->value, 2);
        $deal_amount = $deal_amount . ' ' . $deal_data->data->currency;
        $organization = $deal_data->data->org_name;
        $customer_name = $deal_data->data->person_name;
        $customer_phone = $each_data['customer_phone'];
        ob_start();
        $mail_subject = $mail_heading = "Missed Customer Call";
        include _PATH . "instance/front/tpl/missed_call_mail_template.php";
        $content = ob_get_contents();
        ob_end_clean();
$call_detail_id = qi('call_detail', _escapeArray($call_detail_fields));
qu("agent_call_dialed", _escapeArray(array("is_updated" => "1")), "deal_id='" . $dealId . "'");
$fields['subject'] = 'Call';
$fields['done'] = '1';
$fields['type'] = 'call';
$fields['deal_id'] = $dealId;
// Test Deal Id - $fields['deal_id'] = '4586';
$fields['person_id'] = $person_id;
$fields['org_id'] = $org_id;
$param = http_build_query(array('call_detail_id' => $call_detail_id));
//$fields['note'] = "<iframe src='https://www.leadpropel.com/".FOLDER_RUN."playAudio?".$param."' width='380' height='110'></iframe>";
$fields['note'] = "<span call-recording-id-{$call_detail_id}>Call Recording: <br>We are loading call recording.</span>";
$data = $apiPD->createActivity($fields);
$activity_data = json_decode($data);
if (isset($activity_data->success) && $activity_data->success) {
    qu('call_detail', array("activity_id" => $activity_data->data->id), "id='{$call_detail_id}'");
}
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
// <Dial>+18774942065</Dial>
?>
<Response>
    <Say>Connecting to customer!</Say>    
    <Dial record="record-from-answer" action="<?php 
print _U;
?>
RecordCallBack/<?php 
print $cur_agent;
?>
/<?php 
print $dealId;
<?php

/**
 * Admin side Login file
 * 
 * 
 * @version 1.0
 * @package lysoft
 * 
 */
//$jsInclude = "home.js.php";
//_R(lr('dashboard'));
$urlArgs = _cg("url_vars");
if (isset($_REQUEST['hid_sid_id']) && isset($_REQUEST['hid_token_id'])) {
    qu("config", array("value" => $_REQUEST['txt_account_sid']), "id='{$_REQUEST['hid_sid_id']}'");
    qu("config", array("value" => $_REQUEST['txt_auth_token']), "id='{$_REQUEST['hid_token_id']}'");
    $_SESSION['greetings_msg'] = 'Keys Updated successfully!';
}
$TWILIO_ACCOUNT_SID = qs("SELECT * FROM  `config` WHERE  `key` LIKE  'TWILIO_ACCOUNT_SID'");
$TWILIO_AUTH_TOKEN = qs("SELECT * FROM  `config` WHERE  `key` LIKE  'TWILIO_AUTH_TOKEN'");
_cg("page_title", "Twilio Settings");
Пример #5
0
    $cell = _escape(trim($_REQUEST['cell']));
    $group = _escape(trim($_REQUEST['group']));
    $affected_row = -1;
    /*if ($phone || $cell) {
          $affected_row = qu('pd_users', array("phone" => $phone,"cell" => $cell,"group" => $group), " id = '{$agent_id}'  ");
      }else{
          $affected_row=0;
      }*/
    $affected_row = qu('pd_users', array("phone" => $phone, "cell" => $cell, "group" => $group), " id = '{$agent_id}'  ");
    echo $affected_row;
    die;
}
if ($_REQUEST['doUpdateAgent']) {
    $agent_id = _escape($_REQUEST['doUpdateAgent']);
    $value = _escape($_REQUEST['value']);
    if ($value) {
        qu('pd_users', array("phone" => $value), " id = '{$agent_id}'  ");
    }
    die;
}
if ($_REQUEST['doUpdateAgentCell']) {
    $agent_id = _escape($_REQUEST['doUpdateAgentCell']);
    $value = _escape($_REQUEST['value']);
    if ($value) {
        qu('pd_users', array("cell" => $value), " id = '{$agent_id}'  ");
    }
    die;
}
$agents = q("select * From pd_users where is_active='1' order by name asc ");
_cg("page_title", "Pipedrive Agents List");
$jsInclude = "agents.js.php";
 if (!empty($user_list) && count($user_list) > 0) {
     $json_user_list = json_encode($user_list);
 }
 $source_pk_id = '';
 $source_pk_id = trim($_REQUEST["source_pk_id"]);
 $source_id_arr = array();
 $source_id_arr = qs("SELECT * FROM pd_sources WHERE id = '{$source_pk_id}'");
 $source_id = '';
 $source_id = $source_id_arr["pd_source_id"];
 if (1 == 1) {
     unset($fields);
     $check_source_id = 0;
     $check_source_id = Call_distribution::CheckSourceID($source_id);
     if ($check_source_id > 0) {
         $fields["pd_user_id"] = $json_user_list;
         $user_list_update = qu("call_list_by_source", $fields, " pd_source_id = '{$source_id}'");
         $user_list_update = 1;
     } else {
         $user_list_insert = 0;
         $fields["pd_source_id"] = $source_id;
         $fields["pd_user_id"] = $json_user_list;
         $user_list_insert = qi("call_list_by_source", $fields);
     }
 }
 /*
  if (isset($_REQUEST['fields']) && $_REQUEST['fields'] != '') {
  if (isset($_REQUEST['fields']['call']) && count($_REQUEST['fields']['call']) > 0) {
 
  $call_list = $_REQUEST['fields']['call'];
  foreach ($call_list as $source_id => $each_call):
  if (isset($each_call) && count($each_call) > 0) {
                if (count($new_agent_numbers) > 0) {
                    qu("voice_call", array("in_progress" => "1"), "deal_id='" . $each_call['deal_id'] . "'");
                    $apiCall = new callWebhook();
                    echo "cust: " . $first_voice_call[0]['customer_phone'] . "<br>";
                    echo "Agents: <br>";
                    d($new_agent_numbers);
                    $apiCall->callNow($first_voice_call[0]['customer_phone'], $new_agent_numbers, $each_call['deal_id'], "1", $cate);
                } else {
                    qu("voice_call", array("is_aborted" => "2"), "deal_id='" . $each_call['deal_id'] . "'");
                    $data = qs("select * From pd_users where is_active='1' and is_default='1' order by name asc");
                    $dealId = $each_call['deal_id'];
                    if (!empty($data)) {
                        $apiPD = new apiPipeDrive();
                        $agent_id = $data['pd_id'];
                        $deal_data = json_decode($apiPD->getDealInfo($dealId));
                        $person_id = isset($deal_data->data->person_id->value) ? $deal_data->data->person_id->value : '';
                        $org_id = isset($deal_data->data->org_id->value) ? $deal_data->data->org_id->value : '';
                        $apiPD->assignDeal($dealId, $agent_id);
                        $apiPD->assignPerson($person_id, $agent_id);
                        $apiPD->assignOrganization($org_id, $agent_id);
                        die;
                    }
                }
                break;
            }
        } else {
            qu("voice_call", array("is_handled" => "1"), "deal_id='" . $each_call['deal_id'] . "'");
        }
    }
}
die;
         $fields['agent_id'] = $each_deal['user_id']['id'];
         $fields['agent_name'] = $each_deal['user_id']['name'];
         $fields['agent_email'] = $each_deal['user_id']['email'];
         $fields['cust_id'] = $each_deal['person_id']['value'];
         $fields['cust_name'] = $each_deal['person_id']['name'];
         $fields['cust_email'] = $each_deal['person_id']['email'][0]['value'];
         $fields['stage_id'] = $each_deal['stage_id'];
         $fields['source'] = _e($source[$each_deal['c2a6fc3129578b646ae55717ed15f03ce3ee4df0']]['label'], "");
         $fields['status'] = $each_deal['status'];
         $fields['curr_stage'] = $stage[$each_deal['stage_id']]['name'];
         $fields['initial_move_stage'] = $filter_stage_name;
         $fields['stage_order_nr'] = $stage[$each_deal['stage_id']]['order_nr'];
         $duplicate = qs("select * from dashboard_stage_entering_deals where deal_id = '{$fields['deal_id']}' and initial_move_stage = '{$fields['initial_move_stage']}'");
         if (!empty($duplicate)) {
             unset($fields['reference']);
             qu("dashboard_stage_entering_deals", _escapeArray($fields), "deal_id= '{$fields['deal_id']}' and initial_move_stage = '{$fields['initial_move_stage']}'");
             echo "<br> Record Update for deal: " . $fields['deal_id'];
         } else {
             $fields['date'] = _mysqlDate();
             qi("dashboard_stage_entering_deals", _escapeArray($fields));
             echo "<br>Record Insert for deal: " . $fields['reference'];
         }
     }
     echo "new call<Br><Br><br>";
     $start_record_from += $no_of_records;
     $deal_data = array();
     $deal_data = $apiPD->getFilterDeals($filter_id, $start_record_from, $no_of_records);
     $deal_data = json_decode($deal_data, "true");
 } else {
     echo "no more records";
     break;
Пример #9
0
            $new['call_handled'] = '0';
            $a = qi("call_detail", $new);
            //echo "<br>-" . $each_deal['is_updated'] . "-added-" . $each_deal['deal_id'];
        }
    }
    $apiPD = new apiPipeDrive();
    $agent_call_dialed = q("select * from agent_call_dialed where is_updated='0'");
    foreach ($agent_call_dialed as $each_deal) {
        $deal_data = $apiPD->getDealInfo($each_deal['deal_id']);
        $deal_data = json_decode($deal_data);
        //d($deal_data);
        $person_id = isset($deal_data->data->person_id->value) ? $deal_data->data->person_id->value : '';
        $org_id = isset($deal_data->data->org_id->value) ? $deal_data->data->org_id->value : '';
        $source_id = isset($deal_data->data->c2a6fc3129578b646ae55717ed15f03ce3ee4df0) ? $deal_data->data->c2a6fc3129578b646ae55717ed15f03ce3ee4df0 : '';
        $cust_name = isset($deal_data->data->person_id->name) ? $deal_data->data->person_id->name : '';
        $add_time = isset($deal_data->data->add_time) ? $deal_data->data->add_time : '';
        $add_time = date("Y-m-d H:i:s", strtotime($add_time) - 3600 * 4);
        $cust_email = isset($deal_data->data->person_id->email[0]->value) ? $deal_data->data->person_id->email[0]->value : '';
        $org_name = isset($deal_data->data->org_name) ? $deal_data->data->org_name : '';
        $created_at = qs("select created_at from agent_call_dialed where deal_id='{$each_deal['deal_id']}' order by id asc limit 0,1");
        $call_detail_fields['source_id'] = $source_id;
        $call_detail_fields['customer_name'] = $cust_name;
        $call_detail_fields['customer_email'] = $cust_email;
        $call_detail_fields['org_name'] = $org_name;
        $call_detail_fields['deal_id'] = $each_deal['deal_id'];
        $call_detail_fields['deal_added'] = $add_time;
        $call_detail_fields['created_at'] = $created_at['created_at'];
        $call_detail_id = qu('call_detail', _escapeArray($call_detail_fields), "deal_id='{$each_deal['deal_id']}'");
        $call_detail_id = qu('agent_call_dialed', array("is_updated" => '1'), "deal_id='{$each_deal['deal_id']}'");
    }
}
Пример #10
0
function updateTripCar($tripCode, $limoApiObj = null)
{
    if (is_null($limoApiObj)) {
        $limoApiObj = new apiLimo();
    }
    $tripCodeOriginal = compatibleTripCode($tripCode);
    $tripId = getTripId($tripCode);
    //_ls('updating trip car ');
    //_ls("TripCode " . $tripCode);
    //_ls($tripCode);
    //_ls($tripCodeOriginal);
    //_ls($tripId);
    if (!$tripCodeOriginal || !$tripId) {
        return;
    }
    $data = $limoApiObj->getTripCar($tripCodeOriginal, $tripId);
    //d($data);
    $carName = $data['GetTripCarResult']->Car->CarName;
    $carId = $data['GetTripCarResult']->Car->CarId;
    //_ls("Updating TripCar: {$carName} - {$carId} - TripCode : - {$tripCode}");
    $carType = Vehicle::getCarTypeFromCode($carName);
    //d($carType);
    qu("tripconfirmationtexts", array('carIdLA' => $carId, 'carName' => $carName, 'vehicleType' => $carType), " tripCode = '{$tripCode}' ");
}
    foreach ($source_list_arr as $each_source) {
        $source_id = '';
        $source_id = trim($each_source["id"]);
        if ($source_id != '') {
            $check_source_id = array();
            $check_source_id = Call_distribution::CheckMainSourceId($source_id);
            echo $check_source_id . "****" . $each_source["label"];
            echo "<br/>";
            $data_insert = 1;
            if (!empty($check_source_id)) {
                if ($check_source_id["id"] != '') {
                    unset($fields);
                    $fields["source_name"] = trim($each_source["label"]);
                    $fields["is_deleted"] = 0;
                    $fields = _escapeArray($fields);
                    qu("pd_sources", $fields, " id = '{$check_source_id}' ");
                    $data_insert = 0;
                }
            }
            if ($data_insert == 1) {
                $fields["pd_source_id"] = trim($each_source["id"]);
                $fields["source_name"] = trim($each_source["label"]);
                $fields["is_deleted"] = 0;
                $fields = _escapeArray($fields);
                qi("pd_sources", $fields);
            }
        }
    }
}
echo "<br/><br/>===================Script Is Done================";
die;
            $messageId = $key;
            $phone = $value;
        }
        $conv_fields = array();
        $conv_fields['deal_id'] = $_REQUEST['hidDealId'];
        $conv_fields['message_id'] = $messageId;
        $conv_fields['receiver'] = $phone;
        $conv_fields['receiver_last10'] = last10Char($phone);
        $conv_fields['type'] = 'SENT';
        $conv_fields['text'] = $results['sent_text'];
        $conv_fields['messageTime'] = _mysqlDate();
        $text_conv_list = q("select id from text_conversation where message_id='{$messageId}'");
        if (count($text_conv_list) == 0) {
            qi("text_conversation", $conv_fields);
        } else {
            qu("text_conversation", $conv_fields, "message_id='{$messageId}'");
        }
    }
    echo "success";
    die;
}
if (isset($_REQUEST['conv_list'])) {
    $dealId = $_REQUEST['dealId'];
    $conversation_list = q("select * from text_conversation where deal_id='{$dealId}' order by messageTime asc");
    include _PATH . 'instance/front/tpl/conversation_list_data.php';
    die;
}
$dealId = $_REQUEST['dealId'];
$phone_count = $_REQUEST['phone_count'];
$contact_list = array();
for ($index = 1; $index <= $phone_count; $index++) {
<?php

/**
 * Admin side Login file
 * 
 * 
 * @version 1.0
 * @package lysoft
 * 
 */
//$jsInclude = "home.js.php";
//_R(lr('dashboard'));
$urlArgs = _cg("url_vars");
if (isset($_REQUEST['hid_is_edit'])) {
    qu("config", array("value" => $_REQUEST['txt_api_key']), "id='{$_REQUEST['hid_is_edit']}'");
    $_SESSION['greetings_msg'] = 'Api Key Updated successfully!';
}
$pipedriver_api_key = qs("SELECT * FROM  `config` WHERE  `key` LIKE  'PIPEDRIVER_API_KEY'");
_cg("page_title", "PipeDrive Settings");
 public static function AllLeadSorceNull()
 {
     unset($fields);
     $fields["pd_user_id"] = '';
     return qu("call_list_by_source", $fields, " 1 = 1 ");
 }
        </Gather>
        <Gather timeout="5" action="<?php 
    echo _U;
    ?>
ConnectingCustomer" method="GET" numDigits="1">        
        <Say>You had not press any key.</Say>
        <Say>Please Press 1 to continue.  Press 2 to Repeat.  Press any other key to hangup</Say>	
    </Gather>
        <Redirect method="POST"><?php 
    echo _U . "ConnectingCustomer";
    ?>
</Redirect>
    </Response>
    <?php 
} else {
    qu("voice_call", array("in_progress" => "0"), "deal_id='" . $dealId . "'");
    //Set in_progress=0 because call process is completed
    qi("voice_call", array("deal_id" => $dealId, "is_handled" => "0", "curr_agent" => $cur_agent, "all_agents" => $agent_numbers, "customer_phone" => $phone_value));
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    ?>

    <Response><Say>Good Buy!</Say></Response>    
<?php 
    $agent_name = 'agent';
    $agent_detail = qs("select * from pd_users where phone like '%" . $cur_agent . "%'");
    if (isset($agent_detail)) {
        $agent_name = $agent_detail['name'];
    }
    $message = '<b>Note: </b><br>Call went into voicemail of <b>' . $agent_name . "</b>. System will call again in <b>10 minutes</b>.";
    sendNote($dealId, $message);
 public function callNow($phone_value, $agent_numbers, $dealId, $is_redial = "0", $group = "A")
 {
     $account_sid = ACCOUNT_SID;
     $auth_token = AUTH_TOKEN;
     //$account_sid = 'AC4878ef9ccad9ce3b980fdd4d1d0f42ca';
     //$auth_token = 'ea532dd88a9ee7fb43259da56a40a38f';
     $call_status = qs("select *,value as call_status from config where `key` = 'CALL_STATUS'");
     if (strtolower($call_status['call_status']) != "on") {
         qi("test", array("t" => "call distribution is off.", "payload" => "someone is trying to call without permission!!!"));
         die;
     }
     if ($phone_value == '') {
         qi("activity_log", _escapeArray(array("log" => "Call can not be generated. Phone value is blank", "deal_id" => $dealId)));
         die;
     }
     if (IS_DEV_ENV && $is_redial == "0") {
         $agent_numbers = array(TOLL_FREE_NO);
         $phone_value = AGENT_NO;
     }
     if (count($agent_numbers) == 0) {
         return;
     }
     include _PATH . "/Services/Twilio.php";
     $agent_numbers_arr = $agent_numbers;
     $agent_numbers = implode(",", $agent_numbers_arr);
     $agent_numbers_search = implode("','", $agent_numbers_arr);
     $filter_agent_number = self::filterAgentsByGroup($agent_numbers_search, $group);
     //d($agent_numbers);
     //d($filter_agent_number);
     if (empty($filter_agent_number['agent'])) {
         qi("activity_log", _escapeArray(array("log" => "We have no agents for group '{$group}' or any lower level. ", "deal_id" => $dealId)));
         qu("agent_call_dialed", array("is_aborted" => "1"), "deal_id='" . $dealId . "'");
         qu("voice_call", array("in_progress" => "0"), "deal_id='" . $dealId . "'");
         die;
     }
     qi("agent_call_dialed", _escapeArray(array("agent_numbers" => $agent_numbers, "deal_id" => $dealId, "is_redial" => $is_redial, "customer_phone" => $phone_value, "category" => $filter_agent_number['group'])));
     $client = new Services_Twilio($account_sid, $auth_token);
     $deal_sid_data = q("select * from deal_sid where status!='R' AND status!='C' AND deal_id='{$dealId}'");
     qu("deal_sid", array("status" => "C"), " status!='R' AND status!='C' AND deal_id='{$dealId}'");
     foreach ($deal_sid_data as $each_sid) {
         $call = $client->account->calls->get($each_sid['sid']);
         $call->update(array("Status" => "completed"));
     }
     try {
         foreach ($filter_agent_number['agent'] as $key => $each_agent) {
             //foreach ($agent_numbers_arr as $key => $each_agent) {
             //echo $each_agent."<br>";
             $url_agent_calling = _U . "DialingAgent?";
             $url_agent_received = _U . "ReceivedAgent?";
             $params = "agent_numbers=" . $agent_numbers . "&dealId=" . $dealId . "&phone_value=" . $phone_value . "&cur_agent=" . $each_agent;
             $url_agent_calling .= $params;
             $url_agent_received .= $params;
             $call = $client->account->calls->create(TWILIO_PHONE_NUMBER, $each_agent, $url_agent_received, array("Method" => "GET", "StatusCallback" => $url_agent_calling, "StatusCallbackMethod" => "POST", "StatusCallbackEvent" => array("ringing", "completed"), "Timeout" => "25"));
             echo $call->sid . "<br>";
             //sleep(2);
         }
         echo "<br>We are calling on " . $phone_value;
         die;
     } catch (Exception $e) {
         // Failed calls will throw
         echo $e;
         die;
     }
 }
<?php

//d($_REQUEST);
$urlArgs = _cg("url_vars");
$click_to_call_id = $urlArgs[0];
$recording_url = isset($_REQUEST['RecordingUrl']) ? $_REQUEST['RecordingUrl'] : '';
$recording_duration = isset($_REQUEST['RecordingDuration']) ? $_REQUEST['RecordingDuration'] : '0';
$fields['recording_url'] = $recording_url;
$fields['recording_duration'] = $recording_duration;
qu("click_to_call", $fields, "id='{$click_to_call_id}'");
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response></Response>";
die;
<?php

$conv_fields = array();
$conv_fields['message_id'] = $_REQUEST['message_id'];
$conv_fields['price'] = $_REQUEST['credits_cost'];
$conv_fields['status'] = $_REQUEST['status'];
sleep(10);
// To Remove Duplicate Entry Sleep Is Required - Conversation List Page Also inserting Same Record;
$text_conv_list = q("select id from text_conversation where message_id='{$_REQUEST['message_id']}'");
if (count($text_conv_list) == 0) {
    qi("text_conversation", $conv_fields);
} else {
    qu("text_conversation", $conv_fields, "message_id='{$_REQUEST['message_id']}'");
}
die;
<?php

$params = explode("--", $_REQUEST['params']);
if (isset($params[2]) && $params[2] == "status") {
    $fields['CallStatus'] = $_REQUEST['CallStatus'];
    qu("website_number_dials", _escapeArray($fields), "id='" . $params[0] . "'");
} else {
    $fields['dial_agent'] = $params[1];
    qu("website_number_dials", _escapeArray($fields), "id='" . $params[0] . "'");
}
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response><Say>Good Bye</Say>
</Response>
    <?php 
die;
Пример #20
0
<?php

// just add an entry - for deal id and call sid
// to later hang the call
// when the other agent picks up the code
if ($_REQUEST['CallStatus'] == 'no-answer' || $_REQUEST['CallStatus'] == 'busy') {
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    qu("voice_call", array("in_progress" => "0"), "deal_id='" . $_REQUEST['dealId'] . "'");
    //Set in_progress=0 because call process is completed
    echo "<Response><say>Call Status - {$_REQUEST['CallStatus']}</say></Response>";
    die;
} else {
    if ($_REQUEST['CallStatus'] == 'ringing') {
        $agent_numbers = explode(',', $_REQUEST['agent_numbers']);
        $rand = mt_rand(1, 1000) . "_" . mt_rand(1, 1000);
        // for testing - the deal id should be random
        $dealId = _e($_REQUEST['dealId'], "T{$rand}");
        $phone_value = urlencode($_REQUEST['phone_value']);
        $cur_agent = $_REQUEST['cur_agent'];
        qi("deal_sid", array("deal_id" => $dealId, "sid" => $_REQUEST['CallSid']));
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        echo "<Response><say>Connecting to customer!</say></Response>";
    } else {
        header("content-type: text/xml");
        echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
        echo "<Response><say>Good Bye</say></Response>";
    }
}
die;
$recording_duration = isset($_REQUEST['RecordingDuration']) ? $_REQUEST['RecordingDuration'] : '0';
//qi('config',array("key"=>$agent_id,"value"=>$urlArgs[1]));
$apiPD = new apiPipeDrive();
//$apiPD->assignDeal($urlArgs[1], $agent_id);
$call_detail_data = q("select * from call_detail where sid='{$_REQUEST['CallSid']}'");
$call_detail_fields['agent_phone'] = $urlArgs[0];
$call_detail_fields['agent_id'] = $agent_id;
$call_detail_fields['agent_name'] = $agent_name;
$call_detail_fields['status'] = isset($_REQUEST['DialCallStatus']) ? $_REQUEST['DialCallStatus'] : '';
$call_detail_fields['recording_duration'] = $recording_duration;
$call_detail_fields['recording_url'] = $recording_url;
$call_detail_fields['customer_phone'] = urlencode($urlArgs[2]);
$call_detail_fields['deal_id'] = $urlArgs[1];
if (count($call_detail_data) > 0) {
    $call_detail_id = $call_detail_data[0]['id'];
    qu('call_detail', $call_detail_fields, "id='{$call_detail_data[0]['id']}'");
} else {
    $call_detail_fields['sid'] = $_REQUEST['CallSid'];
    $call_detail_id = qi('call_detail', $call_detail_fields);
}
$deal_data = json_decode($apiPD->getDealInfo($urlArgs[1]));
//$deal_data = json_decode($apiPD->getDealInfo('4586'));
//$deal_data = json_decode($apiPD->getDealInfo('4586'));
$person_id = isset($deal_data->data->person_id->value) ? $deal_data->data->person_id->value : '';
$org_id = isset($deal_data->data->org_id->value) ? $deal_data->data->org_id->value : '';
//$apiPD->assignPerson($person_id, $agent_id);
//$apiPD->assignOrganization($org_id, $agent_id);
$fields['subject'] = 'Call';
$fields['done'] = '1';
$fields['type'] = 'call';
$fields['deal_id'] = $urlArgs[1];
        if ($user_id != '') {
            $check_user_id = array();
            $check_user_id = Call_distribution::CheckMainUserId($user_id);
            echo $check_user_id . "****" . $each_user["name"];
            echo "<br/>";
            unset($fields);
            $fields["name"] = $each_user["name"];
            $fields["email"] = $each_user["email"];
            $fields["phone"] = $each_user["phone"];
            $fields["is_deleted"] = '0';
            if ($each_user['active_flag']) {
                $fields["is_active"] = '1';
            } else {
                $fields["phone"] = '';
                $fields["is_active"] = '0';
            }
            if ($check_user_id != '') {
                $fields = _escapeArray($fields);
                if ($each_user['active_flag']) {
                    unset($fields['phone']);
                }
                qu("pd_users", $fields, " id = '{$check_user_id}' ");
            } else {
                $fields["pd_id"] = $user_id;
                $fields = _escapeArray($fields);
                qi("pd_users", $fields);
            }
        }
    }
}
die;
    ?>
        <Response>
            <Say>Call is already accepted by Other Agent.</Say>
        </Response>
        <?php 
    die;
}
qu("deal_sid", array("status" => 'A'), "sid='" . $_REQUEST['CallSid'] . "'");
$apiPD = new apiPipeDrive();
$account_sid = ACCOUNT_SID;
$auth_token = AUTH_TOKEN;
include _PATH . "/Services/Twilio.php";
$client = new Services_Twilio($account_sid, $auth_token);
// call first
$data = q("select * from deal_sid where deal_id='{$dealId}' AND status!='C' AND sid!='{$_REQUEST['CallSid']}'");
qu("deal_sid", array("status" => 'R'), "deal_id='{$dealId}' AND status!='C' AND sid !='{$_REQUEST['CallSid']}'");
if (count($data) > 0) {
    foreach ($data as $each_data) {
        //echo "hanging up {$each_data['sid']} <br />\r\n";
        //sleep(1);
        $status = qs("select * from deal_sid where sid = '{$each_data['sid']}' ");
        if ($status != 'A') {
            $call = $client->account->calls->get($each_data['sid']);
            $call->update(array("Status" => "completed"));
        }
    }
}
$deal_data = $apiPD->getDealInfo($dealId);
//$deal_data = $apiPD->getDealInfo('5232'); //Test Mode
//$deal_data = $apiPD->getDealInfo('5232');
$deal_data = json_decode($deal_data);