diff --git a/api/application/config/constants.php b/api/application/config/constants.php index 633bea55..3dd54341 100644 --- a/api/application/config/constants.php +++ b/api/application/config/constants.php @@ -94,6 +94,7 @@ defined('ROUTE_LOGIN_W') OR define('ROUTE_LOGIN_W', 'saveSalesPDImage'); defined('ROUTE_LOGIN_V') OR define('ROUTE_LOGIN_V', 'generateSatelliteImg'); // no errors defined('ROUTE_LOGIN_A') OR define('ROUTE_LOGIN_A', 'getAuditedImages'); // no errors defined('TURN_SERVER_API') OR define('TURN_SERVER_API', 'getServerInfo'); // no errors +defined('VIDEO_CHAT_ACCESS_KEY_API') OR define('VIDEO_CHAT_ACCESS_KEY_API', 'getVideoChatAccessKey'); // no errors //defined('ROUTE_LOGIN') OR define('ROUTE_LOGIN','getFullPDDetails'); // no errors /*********************AWS resources Constants*************************************************/ @@ -142,6 +143,12 @@ else if(ENVIRONMENT == 'production') /*********************END of AWS resources Constants*************************************************/ +/*************************TWILO CONSTANTS************************************************************/ + +defined('TWLIO_SID') OR define('TWLIO_SID','AC01bf87391506e1df7e05cbe3d015bf81'); +defined('TWLIO_AUTH_TOKEN') OR define('TWLIO_AUTH_TOKEN','470de1016b533c390703c40c7fea474b'); +/*************************END OF TWILO CONSTANTS************************************************************/ + defined('PROCESSJSON') OR define('PROCESSJSON',1); diff --git a/api/application/config/routes.php b/api/application/config/routes.php index 80918736..ef4ae698 100644 --- a/api/application/config/routes.php +++ b/api/application/config/routes.php @@ -85,6 +85,7 @@ $route['getCustomerSegment'] = 'Common_Masters_Controller/getCustomerSegment'; $route['(checkAppVersion/:any)'] = 'Common_Masters_Controller/checkAppVersion'; $route['getCommonConfig'] = 'Common_Masters_Controller/getCommonConfig'; $route['getServerInfo'] = 'Common_Masters_Controller/getServerInfo'; +$route['getVideoChatAccessKey'] = 'Common_Masters_Controller/getVideoChatAccessKey'; diff --git a/api/application/controllers/Common_Masters_Controller.php b/api/application/controllers/Common_Masters_Controller.php index a21fc65c..5bdeb24d 100644 --- a/api/application/controllers/Common_Masters_Controller.php +++ b/api/application/controllers/Common_Masters_Controller.php @@ -1228,4 +1228,48 @@ class Common_Masters_Controller extends REST_Controller { } } + + + public function getVideoChatAccessKey_post() + { + $pd_id = $this->post('pd_id'); + $random_key = $this->post('random_key'); + $user_type = $this->post('user_type'); + + //echo $pd_id,$random_key,$user_type; + $this->load->library('Twlio'); + $apiKeySecret = $this->twlio->getAPIKey(); + //echo $d; + //if get API key sucessfully from twlio + if($apiKeySecret) + { + + $roomName = $random_key.$pd_id; + $officerName = $user_type == 'PDOFFICER' ? 'PDOFFICER' : 'CUTOMER'; + $videoAccessToken = $this->twlio->getVideoAccessJWTToken($apiKeySecret,$roomName,$officerName); + + if($videoAccessToken) + { + $data['dataStatus'] = true; + $data['status'] = REST_Controller::HTTP_OK; + $data['records'] = $videoAccessToken; + $this->response($data,REST_Controller::HTTP_OK); + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR; + $data['msg'] = 'Couldn`t get access Token from Twlio '; + $this->response($data,REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + } + else + { + $data['dataStatus'] = false; + $data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR; + $data['msg'] = ' Couldn`t get API secret Key from Twlio '; + $this->response($data,REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + + } } \ No newline at end of file diff --git a/api/application/helpers/authorization_helper.php b/api/application/helpers/authorization_helper.php index e3746b7e..9d7d88f0 100644 --- a/api/application/helpers/authorization_helper.php +++ b/api/application/helpers/authorization_helper.php @@ -72,7 +72,7 @@ class AUTHORIZATION } - if( $routingName == ROUTE_LOGIN_X || $routingName == ROUTE_LOGIN_Y || $routingName == ROUTE_LOGIN_Z || $routingName == ROUTE_LOGIN_W || $routingName == ROUTE_LOGIN_V || $routingName == ROUTE_LOGIN_A || $routingName == TURN_SERVER_API) + if( $routingName == ROUTE_LOGIN_X || $routingName == ROUTE_LOGIN_Y || $routingName == ROUTE_LOGIN_Z || $routingName == ROUTE_LOGIN_W || $routingName == ROUTE_LOGIN_V || $routingName == ROUTE_LOGIN_A || $routingName == TURN_SERVER_API || $routingName == VIDEO_CHAT_ACCESS_KEY_API) { return true; } diff --git a/api/application/libraries/Twlio.php b/api/application/libraries/Twlio.php index 0b9e3cbc..56a68f8d 100644 --- a/api/application/libraries/Twlio.php +++ b/api/application/libraries/Twlio.php @@ -3,26 +3,15 @@ include_once APPPATH.'/vendor/autoload.php'; -//define('DOMPDF_ENABLE_AUTOLOAD', false); -//include_once APPPATH.'/vendor/dompdf/dompdf/src/autoloader.php'; -//require_once APPPATH.'/vendor/dompdf/dompdf/src/autoloader.php'; -// require_once APPPATH.'/vendor/dompdf/dompdf/lib/html5lib/Parser.php'; -// //require_once APPPATH.'/vendor/dompdf/dompdf/lib/php-font-lib/src/FontLib/Autoloader.php'; -// //require_once APPPATH.'/vendor/dompdf/dompdf/lib/php-svg-lib/src/autoload.php'; -// require_once APPPATH.'/vendor/dompdf/dompdf/src/Autoloader.php'; -// require_once APPPATH.'/vendor/dompdf/dompdf/src/Dompdf.php'; -// require_once APPPATH.'/vendor/dompdf/dompdf/src/Adapter/CPDF.php'; -// Dompdf\Autoloader::register(); - use Twilio\Rest\Client; + use Twilio\Jwt\AccessToken; + use Twilio\Jwt\Grants\VideoGrant; class Twlio { - + function getServerInfo($print = false,$json = false) { - $sid = "AC01bf87391506e1df7e05cbe3d015bf81"; - $token = "470de1016b533c390703c40c7fea474b"; - $twilio = new Client($sid, $token); + $twilio = new Client(TWLIO_SID, TWLIO_AUTH_TOKEN); $token = $twilio->tokens ->create(); $response_data = array(); @@ -44,7 +33,78 @@ class Twlio return json_encode($response_data,true); } + } + + function getAPIKey($print = false,$json = false) + { + $twilio = new Client(TWLIO_SID, TWLIO_AUTH_TOKEN); + + $new_key = $twilio->newKeys->create(); + return $new_key->secret; + + // print_r($new_key->dateCreated); + // print_r($new_key->secret); + // print_r($new_key->friendyName); + // try + // { + // if(is_object($new_key) && property_exists($new_key, 'secret')) + // { + // return $new_key->secret; + // } + // else + // { + // throw new Exception("Couldn't get API Key from Twlio", 1); + + // } + + + // } + // catch(Exception $e) + // { + // // print_r($e->getMessage()); + // $data['dataStatus'] = false; + // $data['status'] = REST_Controller::HTTP_INTERNAL_SERVER_ERROR; + // $data['msg'] = $e->getMessage(); + // $this->response($data,REST_Controller::HTTP_OK); + // } + + } + + + function getVideoAccessJWTToken($apiKeySecret,$roomName,$officerName) + { + + + // Required for all Twilio access tokens + $twilioAccountSid = TWLIO_SID; + $twilioApiKey = TWLIO_AUTH_TOKEN; + $twilioApiSecret = $apiKeySecret; + + // Required for Video grant + $roomName = $roomName; + // An identifier for your app - can be anything you'd like + $identity = $officerName; + + // Create access token, which we will serialize and send to the client + $token = new AccessToken( + $twilioAccountSid, + $twilioApiKey, + $twilioApiSecret, + 3600, + $identity + ); + + // Create Video grant + $videoGrant = new VideoGrant(); + $videoGrant->setRoom($roomName); + + // Add grant to token + $token->addGrant($videoGrant); + + // render token to string + return $token->toJWT(); + } } diff --git a/api/application/views/report_templates/JSONTOREPORT_SAL_TELE_PD.php b/api/application/views/report_templates/JSONTOREPORT_SAL_TELE_PD.php index 65a28d1a..b27ad030 100644 --- a/api/application/views/report_templates/JSONTOREPORT_SAL_TELE_PD.php +++ b/api/application/views/report_templates/JSONTOREPORT_SAL_TELE_PD.php @@ -653,7 +653,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); if(count($person_met_data)) { - echo '

Person(s) Met:

'; + echo '

Person Contacted:

'; echo '
'; foreach($person_met_data as $pk => $person) @@ -1158,7 +1158,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo $employeement_data['total_business_previous_experience'] ? ("

Previously, applicant ".$employeement_data['total_business_previous_experience']) : ''; - //echo $employeement_data['was_met'] == 'no'? "

No one was met at the visited premises who could confirm the employment details of loan applicant.

":"

During PD visit, ".$employeement_data['name_person_met'].' ( '. ($employeement_data['others_person_met'] ? $employeement_data['others_person_met'] : $employeement_data['designation_person_met_master']) .' ) was met at the visited premises.'; + echo $employeement_data['was_met'] == 'no'? "

No one was met at the visited premises who could confirm the employment details of loan applicant.

":"

During PD, ".$employeement_data['name_person_met'].' ( '. ($employeement_data['others_person_met'] ? $employeement_data['others_person_met'] : $employeement_data['designation_person_met_master']) .' ) was contacted for Tele PD.'; echo ($employeement_data['confirm_salary'] == 'no'? '

Salary amount was not confirmed because '.$employeement_data['sal_amount_was_not_confirmed'].'

' : '

Salary amount confirmed by person contacted is '.$rupee_symbol.' '.MYUTIL::customIndianNumberFormat($employeement_data['confirm_salary_amount']).'.

'); @@ -1190,7 +1190,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); echo $employeement_data['check_validated'] == "not validated" ? "

The salary amount was not validated because ".$employeement_data['why_was_it_not_validated']."

": "

The salary amount was validated ".$employeement_data['how_was_it_validated']."

"; - echo $employeement_data['any_delays'] == 'yes' ? '

As per person met, sometimes there is delay in salary payment.

' : '

Generally, there is no delay in salary payment.

'; + echo $employeement_data['any_delays'] == 'yes' ? '

As per person contacted, sometimes there is delay in salary payment.

' : '

Generally, there is no delay in salary payment.

'; echo $employeement_data['bonus_incentive'] ? "

The applicant receives a bonus ( ".($employeement_data['bonus_type'] == 'others' ? $employeement_data['bonus_type_other']: $employeement_data['bonus_type']).") of ".$rupee_symbol." ".MYUTIL::customIndianNumberFormat($employeement_data['bonus_incentive'])." ".$employeement_data['bonus_frequency_master'].'.

': '

Applicant does not get any Bonus amount or Incentives.

';