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

This commit is contained in:
VENKATESHWARAN 2025-02-04 16:15:03 +05:30
commit 85423bc341
9 changed files with 260 additions and 59 deletions

View File

@ -11,6 +11,9 @@ class MainMenuConversation extends Conversation
{
public function run()
{
$this->bot->types(); // Typing indicator for the first message
sleep(0.5); // Delay
$this->showMainMenu();
}
@ -30,10 +33,10 @@ class MainMenuConversation extends Conversation
switch ($answer->getValue()) {
case "ecard_download":
$message = ChatbotHelper::get_payload_data();
$this->say($message);
// $message = ChatbotHelper::get_payload_data();
// $this->say($message);
// $this->say("📄 Ecard Download Menu:");
// $this->bot->startConversation(new EcardDownloadConversation());
$this->bot->startConversation(new EcardDownloadConversation());
break;
case "network_hospital":
$this->say("🏥 Network Hospital Menu:");log_message('error','Network Hospital clicked');

View File

@ -15,42 +15,65 @@ class NetworkHospitalConversation extends Conversation
public function run()
{
$this->bot->types(); // Typing indicator for the first message
sleep(0.5); // Delay
$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"),
]);
$policy_list = ChatbotHelper::getListOfPolicies();
$buttons = [];
$question = 'Choose Policy:';
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->hears('.*', function ($bot) {
// $this->bot->types(); // Typing indicator for the first message
// sleep(0.5); // Delay
// });
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "search_city":
$this->bot->ask("Enter the City Name",function ($response){
// $cityName = $response->getText();
$hospital_link = ChatbotHelper::getHospitalLink();
$this->say("Searching for hospitals in .....");
case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2:
$client_poilicy_id = explode('#',$answer->getValue())[1];
$hospital_link = ChatbotHelper::getHospitalLink($client_poilicy_id);
$this->say('<a href="' . $hospital_link['network_hospitals'] . '" target="_blank">Click here for hospital details</a>');
$this->bot->startConversation(new doYouWantToContinueConversation());
});
break;
case "search_pincode":
$this->bot->ask("Enter the Pincode",function ($response){
$pincode = $response->getText();
$this->say("Searching for hospitals in ".$pincode.'.....');
});
if($hospital_link)
{
$this->say('<a href="' . $hospital_link['network_hospitals'] . '" target="_blank">Click here for hospital details</a>');
}
else
{
$this->say('No Data found, please contact support team');
}
$this->bot->startConversation(new doYouWantToContinueConversation());
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->showHospitalMenu();
$this->bot->startConversation(new EcardDownloadConversation());
break;
}
});

View File

@ -7,41 +7,30 @@ use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use App\Helpers\ChatbotHelper;
class ReimbursementClaimProcessConversation extends Conversation
{
public function run()
{
$this->bot->types(); // Typing indicator for the first message
sleep(0.5); // Delay
$this->claimProcess();
}
protected function claimProcess()
{
$question = Question::create("Do you Need Anything Else ?")
->addButtons([
Button::create("🔹 Yes I need some more Help")->value("yes"),
Button::create("🔹 No, Thank You")->value("no"),
// Button::create("◀️ Go Back")->value("go_back"),
]);
$res = ChatbotHelper::sendReimbursementProcessOverMail();
if($res == true)
{
$this->say("Reimbursement process shared over your registered mail...!");
}
else
{
$this->say("No email found in your profile / Please contact support team");
}
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
$this->bot->startConversation(new doYouWantToContinueConversation());
$this->say("Sure, How can I help you ");
$this->bot->startConversation(new MainMenuConversation());
break;
case "no":
$this->say("Thank you for your time! If you need anything else, feel free to reach out. Goodbye!");
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->askQuestion();
break;
}
});
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
class TypingMiddleware
{
/**
* Handle the middleware logic.
*
* @param BotMan $bot
* @param callable $next
* @return mixed
*/
public function handle($bot, $next)
{
$this->myLogger = \Config\Services::mylogger();
$this->myLogger->logme('error', 'MIDDLEWARE');
// Simulate typing indicator
$bot->types();
sleep(0.1); // Cap delay at 5 seconds (convert to microseconds)
// Proceed to the next middleware or response
return $next($bot);
}
}

View File

@ -15,6 +15,8 @@ class doYouWantToContinueConversation extends Conversation
public function run()
{
$this->bot->types(); // Typing indicator for the first message
sleep(3); // Delay
$this->askQuestion();
}
@ -31,7 +33,7 @@ class doYouWantToContinueConversation extends Conversation
switch ($answer->getValue()) {
case "yes":
$this->say("Sure, How can I help you ");
// $this->say("Sure, How can I help you ");
$this->bot->startConversation(new MainMenuConversation());
break;
case "no":

View File

@ -8,7 +8,9 @@ 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\Controllers\Chatbot\TypingMiddleware;
use App\Helpers\ChatbotHelper;
@ -32,6 +34,12 @@ class ChatbotControllerNew extends BaseController
// Setup BotMan with cache
$cache = new SymfonyCache(new FilesystemAdapter());
$this->botman = BotManFactory::create([], $cache);
// Create a new instance of BotMan
// $botman = resolve('botman');
// Attach the TypingMiddleware
// $this->botman->middleware->received(new TypingMiddleware());
// Retrieve user ID from session or request
$extras = request()->getGet('conf');
@ -52,6 +60,11 @@ class ChatbotControllerNew extends BaseController
public function index()
{
$this->botman->hears('.*', function ($bot) {
$bot->types(); // Typing indicator for the first message
sleep(0.5); // Delay
});
// Start the Main Menu when user says "hi" or "start"
$this->botman->hears('start|hi|hello', function (BotMan $bot) {
$bot->reply('Hi how can i assit?');

View File

@ -8,6 +8,8 @@ use App\Models\CDMasterModel;
use App\Models\EmployeePolicyModel;
use App\Models\TPAModel;
use App\Helpers\MailHelper;
class ChatbotHelper
{
//get list of policies againest an employee_id
@ -24,11 +26,13 @@ class ChatbotHelper
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]);
}
public static function getHospitalLink(){
$client_policy_id = 336;
$emp_id = 12288;
public static function getHospitalLink($client_policy_id){
// $client_policy_id = 336;
// $emp_id = 12288;
$EmployeePolicyModel = new EmployeePolicyModel();
return $EmployeePolicyModel->getHospitalLinkByPolicyandEmp(336,12288);
$res = $EmployeePolicyModel->getHospitalLinkByPolicyandEmp($client_policy_id);
return is_array($res) && count($res) ? $res[0]['network_hospitals'] : null;
}
public static function getPhoneNumber(){
@ -58,6 +62,146 @@ class ChatbotHelper
}
}
public static function sendReimbursementProcessOverMail()
{
$emp_id = 12288;
$emp_code = 'HTL-007';
$client_id = 159;
$policy_id = 0;
$client_branch_id = 126;
$relationship ='Father';
$EmployeeModel = new EmployeeModel();
$data = $EmployeeModel->find($emp_id);
if(isset($data) && isset($data['email_corporate']))
{
$message = SELF::ReimbursementProcessMailTemplate();
$attachments = [
["filePath" => ROOTPATH."public/sample_excel/sample_addition.xls","fileName" => "sample_addition.xls"],
["filePath" => ROOTPATH."public/sample_excel/sample_inception.xls","fileName" => "sample_inception.xls"],
["filePath" => ROOTPATH."public/assets/images/login_bg.jpg","fileName" => "login_bg.jpg"]
];
$common = ['mail_type'=>'reimbursement_mail_process_bot'];
$email_id = $data['email_corporate'];
$res = MailHelper::send_email(['mail' => $email_id, 'subject' => 'Mail Via CLI', 'message' => $message,'attachments' => $attachments,'common'=>$common]);
$res = json_decode($res);
if($res->status == 'success')
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
public static function ReimbursementProcessMailTemplate()
{
$template = '<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to Claim Your Insurance Reimbursement</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 20px auto;
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
color: #2c3e50;
text-align: center;
}
p {
font-size: 16px;
color: #555;
line-height: 1.5;
}
.steps {
padding: 10px;
background-color: #ecf0f1;
border-radius: 5px;
margin-bottom: 20px;
}
.steps ol {
padding-left: 20px;
}
.btn {
display: block;
width: 200px;
margin: 20px auto;
padding: 12px;
text-align: center;
background-color: #3498db;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
font-size: 16px;
}
.btn:hover {
background-color: #2980b9;
}
.footer {
text-align: center;
font-size: 14px;
color: #777;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>How to Claim Your Insurance Reimbursement</h2>
<p>Dear [Customer Name],</p>
<p>We are here to assist you in claiming your insurance reimbursement smoothly. Please follow the steps below:</p>
<div class="steps">
<ol>
<li><strong>Gather Documents:</strong> Collect all required documents such as bills, invoices, and medical reports.</li>
<li><strong>Complete the Claim Form:</strong> Fill out the insurance claim form accurately.</li>
<li><strong>Attach Supporting Documents:</strong> Attach all necessary documents to support your claim.</li>
<li><strong>Submit Your Claim:</strong> Send the completed form and documents via email or through our online portal.</li>
<li><strong>Track Your Claim:</strong> Use our tracking system to monitor the status of your claim.</li>
<li><strong>Receive Reimbursement:</strong> Once approved, the reimbursement will be processed to your registered account.</li>
</ol>
</div>
<a href="[CLAIM_PORTAL_URL]" class="btn">Submit Your Claim</a>
<p>If you have any questions, feel free to contact our support team.</p>
<div class="footer">
<p>Best Regards,<br><strong>Insurance Support Team</strong><br><a href="mailto:support@example.com">support@example.com</a></p>
</div>
</div>
</body>
</html>
';
return $template;
}
}

View File

@ -1746,14 +1746,14 @@ class EmployeePolicyModel extends Model
return $result[0];
}
public function getHospitalLinkByPolicyandEmp($client_policy_id,$emp_id){
public function getHospitalLinkByPolicyandEmp($client_policy_id){
$data = $this->db->table('employee_polices')
->select('tpa.network_hospitals')
->where('client_policy_id', $client_policy_id)
->where('employee_polices.is_active', 1)
->join('tpa', 'tpa.id = employee_polices.tpa_id AND tpa.is_active = 1')
->join('employees', 'employees.id = employee_polices.employee_id AND employees.id = ' . (int) $emp_id)
->get()->getResultArray()[0];
// ->join('employees', 'employees.id = employee_polices.employee_id AND employees.id = ' . (int) $emp_id)
->get()->getResultArray();
// var_dump($this->db->getLastQuery());
return $data;

View File

@ -26,12 +26,12 @@
var botmanWidget = {
chatServer: `<?=base_url('chat')?>`, // Make sure this URL is correct
frameEndpoint: `<?=base_url('widget')?>`, // This should match your CI4
title: "Ask ஆதிரை",
title: "Ask ILA",
introMessage: "",
bubbleBackground: "#007bff",
mainColor: "#007bff",
placeholderText: "Type your message here...",
aboutText: "Insurance AI Assistant ஆதிரை",
aboutText: "Insurance Assistant ILA",
enableAttachments: false,
// Add extra parameters
parameters: {
@ -62,7 +62,7 @@
if (window.botmanWidget) {
botmanChatWidget.open();
setTimeout(function(){
botmanChatWidget.sayAsBot('hi user '+ uid +' , this is ஆதிரை your Insurance AI Assistant, plz choose the following options')
botmanChatWidget.sayAsBot('Hi user '+ uid +' ,This is ILA your Insurance AI Assistant, plz choose the following options')
botmanChatWidget.whisper('hi');
},2000);