<?php //_errors_on(); $dealId = "5232"; $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; ob_start(); $mail_heading = "Missed Customer Call"; $customer_phone = "919737128291"; include _PATH . "instance/front/tpl/missed_call_mail_template.php"; $content = ob_get_contents(); ob_end_clean(); echo $content; //_phpmail("*****@*****.**", "Test Mail", "Hi<br><br><br><br>How Are You?"); //_mail("*****@*****.**", "Test Mail", "Hi<br>How Are You?"); echo "Mail Sent"; die;
$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.")); die; } _errors_on(); # Get Pipedrive API object $apiPD = new apiPipeDrive(); $apiCall = new callWebhook(); # Set default timezone date_default_timezone_set('America/New_York'); # receive the payload $payload = file_get_contents('php://input'); $data = json_decode(@$payload, true); //Getting Deal Info and change stage if pipeline id is '1' (i.e. for "Leads") $deal_info = $apiPD->getDealInfo($data['current']['id']); $deal_info = json_decode($deal_info, TRUE); if ($deal_info['data']['pipeline_id'] == "1") { $deal_info = $apiPD->modifyDeal($data['current']['id'], array("stage_id" => "1")); } // store into the database //qi("pd_push_notification_log", array("payload" => _escape($payload))); # now, identify if that is hot lead then get the number of customer and start calling the customer # c2a6fc3129578b646ae55717ed15f03ce3ee4df0 - this is key for custom attribute/field - "Source" $deal_source = $data['current']['c2a6fc3129578b646ae55717ed15f03ce3ee4df0']; if (in_array($deal_source, array('37')) || 1) { # Get Person ID $person_id = $data['current']['person_id']; # Get Deal ID $deal_id = $data['current']['id']; # Get Person info
} 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'] . "'"); } } }
$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]; // 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.'|'.urlencode($recording_url.'|'.$recording_duration)));
$new_deal = qs("select * from call_detail where deal_id='{$each_deal['deal_id']}'"); if (isset($new_deal) && !empty($new_deal)) { //echo "<br>-" . $each_deal['is_updated'] . "-not-" . $each_deal['deal_id']; } else { $new = array(); $new['customer_phone'] = $each_deal['customer_phone']; $new['deal_id'] = $each_deal['deal_id']; $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;