Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev

This commit is contained in:
VENKATESHWARAN 2025-02-01 17:34:39 +05:30
commit e8ccaefcb6
18 changed files with 597 additions and 19 deletions

View File

@ -6,6 +6,9 @@ use CodeIgniter\Router\RouteCollection;
/**
* @var RouteCollection $routes
*/
$routes->post('/chat', 'ChatbotControllerNew::index');
$routes->get('/widget', 'ChatbotControllerNew::widget');
$routes->get('/chatbot', 'ChatbotControllerNew::chatbot');
$routes->get('/swagger', 'SwaggerController::index', ['filter' => 'authMVC']);

View File

@ -0,0 +1,110 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
class BotService
{
public static function sendMainOptions(BotMan $bot)
{
$bot->reply('Welcome! Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Card Download'],
['Network Hospital'],
['Reimbursement Claim Process'],
['Reimbursement Claim Status'],
['New Policy'],
['Renew Policy']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleCardDownload(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Download Card'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleNetworkHospital(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Find Hospital'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleReimbursementClaimProcess(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Submit Claim'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleReimbursementClaimStatus(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Check Status'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleNewPolicy(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Get Quote'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
public static function handleRenewPolicy(BotMan $bot)
{
$bot->reply('Please choose an option:', [
'reply_markup' => json_encode([
'keyboard' => [
['Renew Now'],
['Go Back']
],
'resize_keyboard' => true,
'one_time_keyboard' => true
])
]);
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Outgoing\Actions\ButtonTemplate;
use BotMan\BotMan\Messages\Outgoing\Actions\ElementButton;
class ClaimHandler
{
public static function handle(BotMan $bot, $option)
{
$responses = [
'reimbursement_claim_process' => "Reimbursement Claim Process: Here is a dummy response.",
'reimbursement_claim_status' => "Reimbursement Claim Status: Here is a dummy response."
];
if (isset($responses[$option])) {
$bot->reply($responses[$option]);
} else {
$bot->reply("Unknown claim option.");
}
// Send Back Button
self::sendBackButton($bot);
}
private static function sendBackButton(BotMan $bot)
{
$bot->reply(ButtonTemplate::create("Would you like to return?")
->addButton(ElementButton::create("Go Back")->type('postback')->payload("main_menu"))
);
}
}

View File

@ -0,0 +1,65 @@
<?php
// namespace App\Conversations;
namespace App\Controllers\Chatbot;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use App\Helpers\ChatbotHelper;
class EcardDownloadConversation extends Conversation
{
public function run()
{
$this->showEcardMenu();
}
protected function showEcardMenu()
{
$policy_list = ChatbotHelper::getListOfPolicies();
$buttons = [];
$question = 'Choose Policy to Download Ecard:';
if(is_array($policy_list) && count($policy_list))
{
foreach($policy_list as $policy)
{
// $question = Question::create("Choose Policy to Download Ecard:")
// ->addButtons([
// Button::create("🔹 $policy['policy_name']")->value("$policy['emp_policy_id']"),
// Button::create("◀️ Go Back")->value("go_back"),
// ]);
$buttons[] = Button::create("🔹 {$policy['policy_name']}")->value($policy['emp_policy_id'].'#'.$policy['rand_string']);
}
}
else
{
$question = 'No policy found';
}
$buttons = array_merge($buttons,[Button::create("◀️ Go Back")->value("go_back")]);
$question = Question::create($question)
->addButtons($buttons);
$this->bot->ask($question, function ($answer) {
// print_r($answer->getValue());die();
switch ($answer->getValue()) {
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2:
$link = base_url().'/download-e-card/' . explode('#',$answer->getValue())[1].'/1';
$this->say('Click here to downlad: <a href="'.$link.'" target="_blank">Ecard</a>');
$this->bot->startConversation(new EcardDownloadConversation()); // ✅ Restart the
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->bot->startConversation(new EcardDownloadConversation()); // ✅ Restart the conversation
break;
}
});
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
class MainMenuConversation extends Conversation
{
public function run()
{
$this->showMainMenu();
}
protected function showMainMenu()
{
$question = Question::create("Please choose")
->addButtons([
Button::create("📄 Ecard Download")->value("ecard_download"),
Button::create("🏥 Network Hospital")->value("network_hospital"),
Button::create("💰 Reimbursement Claim Process")->value("reimbursement_claim"),
Button::create("📑 Reimbursement Claim Status")->value("reimbursement_status"),
Button::create("🆕 New Policy")->value("new_policy"),
Button::create("🔄 Renew Policy")->value("renew_policy"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "ecard_download":
$this->say("📄 Ecard Download Menu:");
$this->bot->startConversation(new EcardDownloadConversation());
break;
case "network_hospital":
$this->say("🏥 Network Hospital Menu:");
$this->bot->startConversation(new NetworkHospitalConversation());
break;
case "reimbursement_claim":
$this->say("Reimbursement Claim Process selected. (Dummy Response)");
break;
case "reimbursement_status":
$this->say("Reimbursement Claim Status selected. (Dummy Response)");
break;
case "new_policy":
$this->say("New Policy selected. (Dummy Response)");
break;
case "renew_policy":
$this->say("Renew Policy selected. (Dummy Response)");
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->bot->startConversation(new MainMenuConversation());
break;
}
});
}
}

View File

@ -0,0 +1,44 @@
<?php
// namespace App\Conversations;
namespace App\Controllers\Chatbot;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
class NetworkHospitalConversation extends Conversation
{
public function run()
{
$this->showHospitalMenu();
}
protected function showHospitalMenu()
{
$question = Question::create("Choose your Network Hospital option:")
->addButtons([
Button::create("🔹 Search by City")->value("search_city"),
Button::create("🔹 Search by Pincode")->value("search_pincode"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "search_city":
$this->say("Searching by City... (Dummy Response)");
break;
case "search_pincode":
$this->say("Searching by Pincode... (Dummy Response)");
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->showHospitalMenu();
break;
}
});
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Outgoing\Actions\ButtonTemplate;
use BotMan\BotMan\Messages\Outgoing\Actions\ElementButton;
class PolicyHandler
{
public static function handle(BotMan $bot, $option)
{
$responses = [
'ecard_download' => "Ecard Download: Here is a dummy response.",
'network_hospital' => "Network Hospital: Here is a dummy response.",
'new_policy' => "New Policy: Here is a dummy response.",
'renew_policy' => "Renew Policy: Here is a dummy response."
];
if (isset($responses[$option])) {
$bot->reply($responses[$option]);
} else {
$bot->reply("Unknown policy option.");
}
// Send Back Button
self::sendBackButton($bot);
}
private static function sendBackButton(BotMan $bot)
{
$bot->reply(ButtonTemplate::create("Would you like to return?")
->addButton(ElementButton::create("Go Back")->type('postback')->payload("main_menu"))
);
}
}

View File

@ -0,0 +1,90 @@
<?php
namespace App\Controllers;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Cache\SymfonyCache;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use BotMan\Drivers\Web\WebDriver;
use App\Controllers\Chatbot\MainMenuConversation;
use App\Helpers\ChatbotHelper;
class ChatbotControllerNew extends BaseController
{
protected $myLogger;
protected $session;
protected $botman;
public function __construct()
{
set_session_context('CHATBOT CON');
$this->myLogger = \Config\Services::mylogger();
$this->session = \Config\Services::session();
$this->myLogger->logme('error', 'CALLED');
// Load BotMan driver
DriverManager::loadDriver(WebDriver::class);
// Setup BotMan with cache
$cache = new SymfonyCache(new FilesystemAdapter());
$this->botman = BotManFactory::create([], $cache);
// Retrieve user ID from session or request
$extras = request()->getGet('conf');
$extras = json_decode($extras);
$router = service('router');
$method = $router->methodName();
$this->myLogger->logme('error', $method);
if (isset($extras) && $method == 'widget') {
$extras = $extras->parameters;
$this->session->set('CHATBOT_USER_ID', $extras->employee_id);
}
$this->myLogger->logme('error', $this->session->get('CHATBOT_USER_ID'));
// print_rr(ChatbotHelper::getListOfPolicies());die();
}
public function index()
{
// Start the Main Menu when user says "hi" or "start"
$this->botman->hears('start|hi|hello', function (BotMan $bot) {
$bot->reply('How how can i assit?');
$bot->startConversation(new MainMenuConversation());
});
// $this->botman->hears('main_menu', function (BotMan $bot) {
// BotService::sendMainOptions($bot);
// });
// // Register Option Handlers
// $this->registerHandlers();
// Listen for Messages
$this->botman->listen();
}
private function registerHandlers()
{
// Handling Policy and Claims
$this->botman->hears('group:policy:{option}', [\App\Controllers\Chatbot\PolicyHandler::class, 'handle']);
$this->botman->hears('group:claim:{option}', [\App\Libraries\Chatbot\ClaimHandler::class, 'handle']);
}
public function chatbot()
{
$this->loadLayout('chatbot.php');
}
public function widget()
{
echo view('widget.php');
}
}

View File

@ -1658,7 +1658,7 @@ class MasterController extends AdminController
$email_id = CLI::getOption('to') ? CLI::getOption('to') : $email_id;
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]);
echo "Inside the master controller";
print_r($res['data']['zepto_api']);
print_r($res);
}

View File

@ -0,0 +1,28 @@
<?php
// File: App\Helpers\DepositHelper.php
namespace App\Helpers;
use App\Models\EmployeeModel;
use App\Models\CDMasterModel;
class ChatbotHelper
{
//get list of policies againest an employee_id
public static function getListOfPolicies()
{
$emp_id = 12288;
$emp_code = 'HTL-007';
$client_id = 159;
$policy_id = 0;
$client_branch_id = 126;
$relationship ='Father';
$EmployeeModel = new EmployeeModel();
return $EmployeeModel->getEmpFamilybyEmpCode(emp_code: $emp_code,client_id: $client_id,emp_status: ['draft'],policy_status:['draft'],client_branch_id:[ $client_branch_id ],relationship:[$relationship]);
}
}
?>

View File

@ -235,7 +235,7 @@ if (!function_exists('get_username')) {
if (!function_exists('get_role_id')) {
function get_role_id() {
$role_id = get_session_userdata()->role;
$role_id = isset(get_session_userdata()->role) ? get_session_userdata()->role : null;
return $role_id;
}
}

View File

@ -106,7 +106,7 @@ class EmployeeModel extends Model
public function getEmpFamilybyEmpCode(string $client_policy_id = null,string $emp_code = null,string $client_id = null,array $emp_status = [],array $policy_status = [],array $relationship = [],array $client_branch_id = [])
{
$result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employees.file_id','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon', 'employee_polices.payable_employee'])
$result = $this->select(['employees.id as emp_id', 'employees.client_id','employees.client_branch_id', 'employees.relationship', 'employees.relationship_code', 'employees.change_event', 'employees.emp_code', 'employees.name', 'employees.email_personal', 'employees.email_corporate', 'employees.mobile', 'employees.gender', 'employees.dob', 'employees.doj', 'employees.basic_pay', 'employees.band', 'employees.designation', 'employees.emp_status','employees.unit','employees.file_id','employee_polices.id as emp_policy_id', 'employee_polices.employee_id', 'employee_polices.client_policy_id', 'employee_polices.tpa_id', 'employee_polices.uhid', 'employee_polices.batch_code', 'employee_polices.status', 'employee_polices.pre_existing_alignments', 'employee_polices.basic_cover_si', 'employee_polices.date_coverage', 'employee_polices.policy_end_date', 'employee_polices.days', 'employee_polices.premium', 'employee_polices.rata_premimum', 'employee_polices.gst', 'employee_polices.date_of_exit', 'employee_polices.reason_for_exit','policy_type.long_name as policy_name','client_policy.is_addon', 'employee_polices.payable_employee','employee_polices.rand_string','employee_polices.claim_status'])
->join('employee_polices', 'employee_polices.employee_id = employees.id')
->join('client_policy', 'client_policy.id = employee_polices.client_policy_id')
->join('policy_type', 'policy_type.id = client_policy.policy_type_id','left')

View File

@ -1732,7 +1732,7 @@ class EmployeePolicyModel extends Model
employee_polices ep
WHERE
ep.file_id = $file_id
AND ep.uhid IS NOT NULL'
AND ep.uhid IS NOT NULL
AND ep.status != 'truncated'
AND ep.status != 'truncated'
AND ep.is_active = 1;

View File

@ -494,7 +494,7 @@ class PolicyTransactionModel extends Model
")
->join('pt_co_share_details', 'policy_transaction.id = pt_co_share_details.pt_id', 'left')
->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left')
// ->join('insurer_statements', 'pt_co_share_details.statement_id = insurer_statements.id', 'left')
->join('clients', 'clients.id = policy_transaction.client_id')
->join('client_branch', 'policy_transaction.client_branch_id = client_branch.id', 'left')
->join('client_policy', 'policy_transaction.client_policy_id = client_policy.id', 'left')
@ -519,19 +519,27 @@ class PolicyTransactionModel extends Model
$builder->where('policy_transaction.'.$date_type.'>=', $startDate)
->where('policy_transaction.'.$date_type.'<=', $endDate);
}else{
// $fromDate = date('Y-m-d', strtotime('-30 days'));
// $toDate = date('Y-m-d 23:59:59');
// $builder->where('policy_transaction.created_at >=', $fromDate)
// ->where('policy_transaction.created_at <=', $toDate);
}
if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){
// if($date_type == 'statement_month' && $start_date != 0 && $end_date != 0){
$builder->where('policy_transaction.month >=', $startDate)
->where('policy_transaction.month <=', $endDate);
// $startDate = date('Y-m-d 00:00:00', strtotime($start_date));
// $endDate = date('Y-m-d 23:59:59', strtotime($end_date));
// $builder->where('policy_transaction.month >=', $startDate)
// ->where('policy_transaction.month <=', $endDate);
// }
// Conditionally join insurer_statements if $date_type == 'statement_month'
if ($date_type == 'statement_month' && $start_date != 0 && $end_date != 0) {
$startDate = date('Y-m-d', strtotime($start_date));
$endDate = date('Y-m-d', strtotime($end_date));
$builder->join('co_share_stmt_details', 'pt_co_share_details.id = co_share_stmt_details.co_share_id', 'left')
->join('insurer_statements', 'co_share_stmt_details.statement_id = insurer_statements.id','left')
->where('insurer_statements.is_active', 1)
->where('insurer_statements.month >=', $startDate)
->where('insurer_statements.month <=', $endDate)
->groupBy('co_share_stmt_details.co_share_id');
}
if ($client_id != 0) {

83
app/Views/chatbot.php Normal file
View File

@ -0,0 +1,83 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insurance ChatBot</title>
</head>
<style type="text/css">
</style>
<body>
<h1>Welcome to Insurance ChatBot </h1>
<script>
// var botmanWidget = {
// frameEndpoint: 'https://localhost/PHP828APPS/ruc/nhance/chat', // This should match your CI4 route
// introMessage: "Hi! I am your Insurance Bot. How can I assist you today?",
// placeholderText: "Type your message here...",
// title: "Insurance Bot",
// mainColor: "#5C6BC0",
// bubbleBackground: "#673AB7"
// };
var uid = Math.floor(100000 + Math.random() * 900000);
console.log('CURRENT_USER' + uid);
var botmanWidget = {
chatServer: "https://localhost/PHP828APPS/ruc/nhance/chat", // Make sure this URL is correct
frameEndpoint: 'https://localhost/PHP828APPS/ruc/nhance/widget', // This should match your CI4
title: "Ask ஆதிரை",
introMessage: "",
bubbleBackground: "#007bff",
mainColor: "#007bff",
placeholderText: "Type your message here...",
aboutText: "Insurance AI Assistant ஆதிரை",
enableAttachments: false,
// Add extra parameters
parameters: {
employee_id: '1234655', //PK of emp
session_id: "XYZ789", // token
origin: "mobile", // origin
emp_code:"EMP001",
client_id:10,
client_branch_id:12
}
};
// Send a first load request when the chat widget opens
// window.addEventListener("load", function () {
// setTimeout(function () {
// fetch("https://localhost/PHP828APPS/ruc/nhance/chat", {
// method: "POST",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify({ first_load: "true", user_id: "12345" })
// });
// }, 2000); // Slight delay to ensure the widget is ready
// });
window.addEventListener("load", function () {
setTimeout(function () {
if (window.botmanWidget) {
botmanChatWidget.open();
setTimeout(function(){
botmanChatWidget.sayAsBot('hi user '+ uid +' , this is ஆதிரை your Insurance AI Assistant, plz choose the following options')
botmanChatWidget.whisper('hi');
},2000);
}
}, 3000); // Delay to ensure widget is initialized
});
</script>
<!-- <script src="https://cdn.jsdelivr.net/npm/botman-web-widget@latest"></script> -->
<!-- <script id="botmanWidget" src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script> -->
<!-- <script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script> -->
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script>
</body>
</html>

View File

@ -230,7 +230,7 @@ $(document).ready(function() {
paging: true, // Enable pagination
pageLength: 25, // Set default number of rows per page (optional)
ordering: false,
"footerCallback": function(row, data, start, end, display) {
"footerCallback": function(row, data, start, end, display) {
var api = this.api();
// Calculate column totals
@ -238,9 +238,11 @@ $(document).ready(function() {
return parseFloat(a) + parseFloat(b) || 0;
}, 0);
var total_rewards = api.column(26).data().reduce(function(a,b){
var total_rewards = api.column(26).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b) || 0;
})
}, 0); // Add initial value 0 here
console.log('total_rewards - ' + total_rewards);
var totalIrda = api.column(27).data().reduce(function(a, b) {
return parseFloat(a) + parseFloat(b) || 0;
@ -256,7 +258,7 @@ $(document).ready(function() {
// Update the totals in the div above the table
$('#total_premium').text(totalPremium.toFixed(2));
$('#total_rewards').text(total_rewards.toFixed(2))
$('#total_rewards').text(total_rewards.toFixed(2));
$('#total_irda').text(totalIrda.toFixed(2));
$('#total_billed').text(totalBilled.toFixed(2));
$('#total_unbilled').text(totalUnbilled.toFixed(2));

15
app/Views/widget.php Normal file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<title>BotMan Widget</title>
<meta charset="UTF-8">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500,700,800" rel="stylesheet">
<link rel="stylesheet" type="text/css" href=" https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css">
</head>
<body>
<script id="botmanWidget" src=' https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script>
</body>
</html>

View File

@ -14,6 +14,8 @@
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"botman/botman": "^2.8",
"botman/driver-web": "^1.5",
"dompdf/dompdf": "^2.0",
"firebase/php-jwt": "^6.10",
"google/apiclient": "^2.15.0",
@ -25,6 +27,7 @@
"psr/http-message": "^1.0",
"psr/log": "^1.1",
"slim/slim": "^4.13",
"symfony/cache": "^7.2",
"zircote/swagger-php": "^4.8"
},
"require-dev": {