From 6fc54650de48ce6557d9a8625d19f0b97f8b008d Mon Sep 17 00:00:00 2001 From: velz Date: Tue, 4 Feb 2025 15:51:39 +0530 Subject: [PATCH] FEAT_CHAT_CONTD --- .../Chatbot/MainMenuConversation.php | 9 +- .../Chatbot/NetworkHospitalConversation.php | 65 +++++--- .../ReimbursementClaimProcessConversation.php | 37 ++--- app/Controllers/Chatbot/TypingMiddleware.php | 27 ++++ .../doYouWantToContinueConversation.php | 4 +- app/Controllers/ChatbotControllerNew.php | 13 ++ app/Helpers/ChatbotHelper.php | 152 +++++++++++++++++- app/Models/EmployeePolicyModel.php | 6 +- app/Views/chatbot.php | 6 +- 9 files changed, 260 insertions(+), 59 deletions(-) create mode 100644 app/Controllers/Chatbot/TypingMiddleware.php diff --git a/app/Controllers/Chatbot/MainMenuConversation.php b/app/Controllers/Chatbot/MainMenuConversation.php index 011806f0..2c9059f9 100644 --- a/app/Controllers/Chatbot/MainMenuConversation.php +++ b/app/Controllers/Chatbot/MainMenuConversation.php @@ -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'); diff --git a/app/Controllers/Chatbot/NetworkHospitalConversation.php b/app/Controllers/Chatbot/NetworkHospitalConversation.php index 004b6ef6..10bc3b7d 100644 --- a/app/Controllers/Chatbot/NetworkHospitalConversation.php +++ b/app/Controllers/Chatbot/NetworkHospitalConversation.php @@ -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('Click here for hospital details'); - $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('Click here for hospital details'); + } + 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; } }); diff --git a/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php b/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php index b1cf1ec0..ca3bf60a 100644 --- a/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php +++ b/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php @@ -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; - } - }); } - } diff --git a/app/Controllers/Chatbot/TypingMiddleware.php b/app/Controllers/Chatbot/TypingMiddleware.php new file mode 100644 index 00000000..047d246b --- /dev/null +++ b/app/Controllers/Chatbot/TypingMiddleware.php @@ -0,0 +1,27 @@ +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); + } +} diff --git a/app/Controllers/Chatbot/doYouWantToContinueConversation.php b/app/Controllers/Chatbot/doYouWantToContinueConversation.php index 4da9aed7..ba5c1864 100644 --- a/app/Controllers/Chatbot/doYouWantToContinueConversation.php +++ b/app/Controllers/Chatbot/doYouWantToContinueConversation.php @@ -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": diff --git a/app/Controllers/ChatbotControllerNew.php b/app/Controllers/ChatbotControllerNew.php index a43111eb..4311a9bb 100644 --- a/app/Controllers/ChatbotControllerNew.php +++ b/app/Controllers/ChatbotControllerNew.php @@ -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?'); diff --git a/app/Helpers/ChatbotHelper.php b/app/Helpers/ChatbotHelper.php index 03abeeeb..9fc63f25 100644 --- a/app/Helpers/ChatbotHelper.php +++ b/app/Helpers/ChatbotHelper.php @@ -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 = ' + + + + + How to Claim Your Insurance Reimbursement + + + + +
+

How to Claim Your Insurance Reimbursement

+

Dear [Customer Name],

+

We are here to assist you in claiming your insurance reimbursement smoothly. Please follow the steps below:

+ +
+
    +
  1. Gather Documents: Collect all required documents such as bills, invoices, and medical reports.
  2. +
  3. Complete the Claim Form: Fill out the insurance claim form accurately.
  4. +
  5. Attach Supporting Documents: Attach all necessary documents to support your claim.
  6. +
  7. Submit Your Claim: Send the completed form and documents via email or through our online portal.
  8. +
  9. Track Your Claim: Use our tracking system to monitor the status of your claim.
  10. +
  11. Receive Reimbursement: Once approved, the reimbursement will be processed to your registered account.
  12. +
+
+ + Submit Your Claim + +

If you have any questions, feel free to contact our support team.

+ + +
+ + + + '; + + return $template; + } + } diff --git a/app/Models/EmployeePolicyModel.php b/app/Models/EmployeePolicyModel.php index 1d989b80..d23b315e 100755 --- a/app/Models/EmployeePolicyModel.php +++ b/app/Models/EmployeePolicyModel.php @@ -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; diff --git a/app/Views/chatbot.php b/app/Views/chatbot.php index adbeb587..359b4ce0 100644 --- a/app/Views/chatbot.php +++ b/app/Views/chatbot.php @@ -26,12 +26,12 @@ var botmanWidget = { chatServer: ``, // Make sure this URL is correct frameEndpoint: ``, // 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);