CHANGE_ ticket related changes in chat bot : GWM
This commit is contained in:
parent
3c155e6bd0
commit
127d8876db
@ -73,11 +73,10 @@ class ChatBotController extends AdminController
|
||||
|
||||
public function getChatResponse()
|
||||
{
|
||||
try {
|
||||
// try {
|
||||
$request_for = $this->request->getGet('request_for');
|
||||
$option = $this->request->getGet('option');
|
||||
$is_option = $this->request->getGet('is_option');
|
||||
$custom_options = $this->request->getGet('custom_options');
|
||||
|
||||
$responseData = $this->ChatBotModel->where('request', $request_for)
|
||||
->where('is_active', 1 )
|
||||
@ -89,18 +88,38 @@ class ChatBotController extends AdminController
|
||||
if(isset($option) && $option != 0){
|
||||
|
||||
$decodedData = json_decode($responseData['options'],true);
|
||||
|
||||
$requestFor = $decodedData[$option];
|
||||
|
||||
|
||||
if (isset($decodedData[$option]) && $decodedData[$option] !== null) {
|
||||
|
||||
$responseData = $this->ChatBotModel->where('request', $requestFor)
|
||||
$requestFor = $decodedData[$option];
|
||||
$responseData = $this->ChatBotModel->where('request', $requestFor)
|
||||
->where('is_active', 1 )
|
||||
->first();
|
||||
|
||||
}else{
|
||||
|
||||
if( $request_for == 'Create claim'){
|
||||
$result = [
|
||||
'request_for' => $request_for,
|
||||
'options' => json_decode($responseData['options'], true),
|
||||
'text' => "Enter Message",
|
||||
'is_option' => "0",
|
||||
'policy_id' => $option,
|
||||
'mobile_no' => $this->request->getGet('mobile_no')
|
||||
];
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}else{
|
||||
|
||||
$result = $this->sendDefaultMessage();
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($custom_options))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(isset($is_option) && $is_option == 0){
|
||||
|
||||
@ -120,8 +139,38 @@ class ChatBotController extends AdminController
|
||||
|
||||
}else{
|
||||
|
||||
if( $request_for == 'Create claim' && $text == 'Enter Message'){
|
||||
|
||||
|
||||
$ticket = $this->claimTicket();
|
||||
|
||||
$ticket = json_decode($ticket,true);
|
||||
|
||||
if (isset($ticket['success']) && $ticket['success'] == 1) {
|
||||
|
||||
$result = [
|
||||
'request_for' => $request_for,
|
||||
'options' => null,
|
||||
'text' => $ticket['message'].', Your Ticket id is '.$ticket['ticket_id'],
|
||||
'is_option' => "0"
|
||||
];
|
||||
}else{
|
||||
|
||||
$result = [
|
||||
'request_for' => $request_for,
|
||||
'options' => null,
|
||||
'text' => $ticket['message'],
|
||||
'is_option' => "0"
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}else{
|
||||
|
||||
$result = $this->sendDefaultMessage();
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $result ],200);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -145,9 +194,9 @@ class ChatBotController extends AdminController
|
||||
|
||||
return $this->respond(['status' => 'failed','code' => 404,'data' => 'No Data'],404);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
}
|
||||
// } catch (\Throwable $th) {
|
||||
// return $this->respond(['status' => 'failed','code' => 500,'data' => $th],500);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@ -220,14 +269,15 @@ public function getAllPolicyByMobileNumber($mobileNo,$action)
|
||||
'options' => $options[count($options) - 1],
|
||||
'text' => null,
|
||||
'is_option' => "1",
|
||||
'custom_options'=>'create_ticket'
|
||||
'mobile_no' => $mobileNo,
|
||||
];
|
||||
}else{
|
||||
return [
|
||||
'request_for' => $this->request->getGet('request_for'),
|
||||
'options' => null,
|
||||
'text' => $text,
|
||||
'is_option' => "0"
|
||||
'is_option' => "0",
|
||||
'mobile_no' => $mobileNo,
|
||||
];
|
||||
}
|
||||
|
||||
@ -258,6 +308,64 @@ public function getAllPolicyByMobileNumber($mobileNo,$action)
|
||||
}
|
||||
|
||||
|
||||
public function claimTicket()
|
||||
{
|
||||
|
||||
|
||||
$employee = $this->employeeModel->where('mobile', $this->request->getGet('mobile_no'))->where('is_active', 1 )->first();
|
||||
if($employee){
|
||||
|
||||
$url = 'https://venbait.in/nhance/helpdesk/dev/api/tickets/create';
|
||||
|
||||
|
||||
$token = 'uncp8FvG310bEyYdV9MmStlo7KDRZ65fLWTeXCI2JzwPrNHjBqQhUiAgxsaO';
|
||||
$headers = [
|
||||
'Token: ' . $token,
|
||||
];
|
||||
|
||||
// Form data
|
||||
$data = [
|
||||
'opener' => 'user',
|
||||
'department_id' => 2,
|
||||
'subject' => 'Claim Raised by Chat Bot',
|
||||
'body' => $this->request->getGet('value'),
|
||||
'policy_id' => $this->request->getGet('policy_id'),
|
||||
'emp_code' => $employee['emp_code'],
|
||||
'mobile_number' => $this->request->getGet('mobile_no'),
|
||||
'email' => 'adhavanvalli@gmail.com',
|
||||
'fullname' => $employee['name'],
|
||||
];
|
||||
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
return $response;
|
||||
// Check for errors
|
||||
// if (curl_errno($ch)) {
|
||||
// $error = curl_error($ch);
|
||||
// curl_close($ch);
|
||||
// return ['status' => 'failed', 'response' => $error];
|
||||
// } else {
|
||||
// // Close cURL session
|
||||
// curl_close($ch);
|
||||
// return ['status' => 'success', 'response' => $response];
|
||||
// }
|
||||
|
||||
|
||||
}else{
|
||||
return ['status' => 'failed', 'response' => 'Employee Not Found'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user