FEAT_CHATBOT_INIATED

This commit is contained in:
Srinivas-Saravanan 2025-02-03 10:26:49 +05:30
parent 581d2a4e92
commit af64affae4
19 changed files with 678 additions and 14 deletions

View File

@ -51,7 +51,7 @@ class EcardDownloadConversation extends Conversation
$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
$this->bot->startConversation(new doYouWantToContinueConversation()); // ✅ Restart the
break;

View File

@ -2,6 +2,7 @@
namespace App\Controllers\Chatbot;
use App\Helpers\ChatbotHelper;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
@ -28,24 +29,30 @@ class MainMenuConversation extends Conversation
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "ecard_download":
$this->say("📄 Ecard Download Menu:");
$this->bot->startConversation(new EcardDownloadConversation());
$message = ChatbotHelper::get_payload_data();
$this->say($message);
// $this->say("📄 Ecard Download Menu:");
// $this->bot->startConversation(new EcardDownloadConversation());
break;
case "network_hospital":
$this->say("🏥 Network Hospital Menu:");
$this->say("🏥 Network Hospital Menu:");log_message('error','Network Hospital clicked');
$this->bot->startConversation(new NetworkHospitalConversation());
break;
case "reimbursement_claim":
$this->say("Reimbursement Claim Process selected. (Dummy Response)");
// $this->say("Reimbursement Claim Process selected. (Dummy Response)");
$this->bot->startConversation(new ReimbursementClaimProcessConversation());
break;
case "reimbursement_status":
$this->say("Reimbursement Claim Status selected. (Dummy Response)");
$this->bot->startConversation(new ReimbursementClaimStatusConversation());
break;
case "new_policy":
$this->say("New Policy selected. (Dummy Response)");
$this->bot->startConversation(new policyConversation());
break;
case "renew_policy":
$this->say("Renew Policy selected. (Dummy Response)");
$this->bot->startConversation(new policyConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
@ -54,4 +61,5 @@ class MainMenuConversation extends Conversation
}
});
}
}

View File

@ -7,8 +7,12 @@ use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use App\Helpers\ChatbotHelper;
class NetworkHospitalConversation extends Conversation
{
public function run()
{
$this->showHospitalMenu();
@ -26,10 +30,20 @@ class NetworkHospitalConversation extends Conversation
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "search_city":
$this->say("Searching by City... (Dummy Response)");
$this->bot->ask("Enter the City Name",function ($response){
// $cityName = $response->getText();
$hospital_link = ChatbotHelper::getHospitalLink();
$this->say("Searching for hospitals in .....");
$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->say("Searching by Pincode... (Dummy Response)");
$this->bot->ask("Enter the Pincode",function ($response){
$pincode = $response->getText();
$this->say("Searching for hospitals in ".$pincode.'.....');
});
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
@ -41,4 +55,5 @@ class NetworkHospitalConversation extends Conversation
}
});
}
}

View File

@ -0,0 +1,47 @@
<?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 ReimbursementClaimProcessConversation extends Conversation
{
public function run()
{
$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"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
$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,47 @@
<?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 ReimbursementClaimStatusConversation extends Conversation
{
public function run()
{
$this->claimStatus();
}
protected function claimStatus()
{
$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"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
$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,50 @@
<?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 commonPolicyOptionConversations extends Conversation
{
public function run()
{
$this->policyOptions();
}
protected function policyOptions()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🔹 Upload Vehicle Details")->value("upload_vehicle_details"),
Button::create("🔹 Talk to our Service Executive")->value("service_executive"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "upload_vehicle_details":
// $cityName = $response->getText();
$this->bot->startConversation(new vehicleFormConversation());
break;
case "service_executive":
$this->bot->startConversation(new serviceExecutiveConversation());
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->policyOptions();
break;
}
});
}
}

View File

@ -0,0 +1,48 @@
<?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 doYouWantToContinueConversation extends Conversation
{
public function run()
{
$this->askQuestion();
}
protected function askQuestion()
{
$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"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
$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,50 @@
<?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 fourWheelerOptionsConversations extends Conversation
{
public function run()
{
$this->show4WOptions();
}
protected function show4WOptions()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🔹 Comprehensive")->value("comp"),
Button::create("🔹 Third-Party Only")->value("3p"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "3p":
// $cityName = $response->getText();
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "comp":
$this->bot->startConversation(new commonPolicyOptionConversations());
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,49 @@
<?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 hospitalPolicyConversation extends Conversation
{
public function run()
{
$this->showMediclaimPolicyOptions();
}
protected function showMediclaimPolicyOptions()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🔹 Individual")->value("individual"),
Button::create("🔹 Floater")->value("floater"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "individual":
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "floater":
$this->bot->startConversation(new commonPolicyOptionConversations());
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,50 @@
<?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 medicalClaimOptionConversations extends Conversation
{
public function run()
{
$this->showMediclaimOptions();
}
protected function showMediclaimOptions()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🔹 Individual")->value("individual"),
Button::create("🔹 Floater")->value("floater"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "individual":
// $cityName = $response->getText();
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "floater":
$this->bot->startConversation(new commonPolicyOptionConversations());
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,55 @@
<?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 policyConversation extends Conversation
{
public function run()
{
$this->showNewPolicy();
}
protected function showNewPolicy()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🏍️ 2 Wheeler")->value("2_wheeler"),
Button::create("🚗 4 Wheeler")->value("4_wheeler"),
Button::create("🩺 Medical Claim")->value("mediclaim"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "2_wheeler":
// $cityName = $response->getText();
$this->bot->startConversation(new twoWheelerOptionsConversations());
break;
case "4_wheeler":
$this->bot->startConversation(new fourWheelerOptionsConversations());
break;
case "mediclaim":
$this->bot->startConversation(new medicalClaimOptionConversations());
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,60 @@
<?php
namespace App\Controllers\Chatbot;
use App\Helpers\ChatbotHelper;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
class serviceExecutiveConversation extends Conversation
{
protected $mobile_number;
public function run()
{
$this->askServiceExecutive();
}
protected function askServiceExecutive()
{
$mobile = ChatbotHelper::getPhoneNumber(); // Assuming this fetches the user's phone number
$question = Question::create("Is this Your Mobile Number: $mobile")
->addButtons([
Button::create("✅ Yes")->value("yes"),
Button::create("❌ No")->value("no"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
$this->say("Our executive will call you at the earliest.");
$this->bot->startConversation(new doYouWantToContinueConversation());
break;
case "no":
$this->ask('Enter Your Mobile Number?', function ($response) {
$this->mobile_number = $response->getText();
$this->bot->userStorage()->save([
'mobile_number' => $this->mobile_number
]);
// Use 'use' to bring the class context into the closure
$this->say("Our executive will call you at the earliest.");
$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->askServiceExecutive();
break;
}
});
}
}

View File

@ -0,0 +1,50 @@
<?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 twoWheelerOptionsConversations extends Conversation
{
public function run()
{
$this->show2WOptions();
}
protected function show2WOptions()
{
$question = Question::create("Choose Policy Type:")
->addButtons([
Button::create("🔹 Third-Party")->value("3p"),
Button::create("🔹 Comprehensive")->value("comp"),
Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "3p":
// $cityName = $response->getText();
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "comp":
$this->bot->startConversation(new commonPolicyOptionConversations());
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,83 @@
<?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 vehicleFormConversation extends Conversation
{
protected $vehicleName;
protected $vehicleYOM;
protected $vehicleEngineNo;
protected $vehicleInvoiceNo;
public function run()
{
$this->askVehicleName();
}
protected function askVehicleName()
{
$this->ask('Enter Vehicle Name ?', function ($response) {
$this->vehicleName = $response->getText();
if (empty($this->vehicleName)) {
$this->say('Vehicle Name Cannot be Empty');
return $this->askVehicleName(); // Re-ask if empty
}
$this->askVehicleYOM(); // Ask next question
});
}
protected function askVehicleYOM()
{
$this->ask('Enter Vehicle Year of Manufacture ?', function ($response) {
$this->vehicleYOM = $response->getText();
if (empty($this->vehicleYOM)) {
$this->say('Vehicle Year of Manufacture Cannot be Empty');
return $this->askVehicleYOM(); // Re-ask if empty
}
$this->askVehicleEngineNo(); // Ask next question
});
}
protected function askVehicleEngineNo()
{
$this->ask('Enter Vehicle Engine Number ?', function ($response) {
$this->vehicleEngineNo = $response->getText();
if (empty($this->vehicleEngineNo)) {
$this->say('Vehicle Engine Number Cannot be Empty');
return $this->askVehicleEngineNo(); // Re-ask if empty
}
$this->askVehicleInvoiceNo(); // Ask next question
});
}
protected function askVehicleInvoiceNo()
{
$this->ask('Enter Vehicle Invoice Number ?', function ($response) {
$this->vehicleInvoiceNo = $response->getText();
if (empty($this->vehicleInvoiceNo)) {
$this->say('Vehicle Invoice Number Cannot be Empty');
return $this->askVehicleInvoiceNo(); // Re-ask if empty
}
$this->storeVehicleData(); // Proceed to store the data
});
}
protected function storeVehicleData()
{
// Save all collected data to user storage
$this->bot->userStorage()->save([
'vehicle_name' => $this->vehicleName,
'vehicle_yom' => $this->vehicleYOM,
'vehicle_engine_no' => $this->vehicleEngineNo,
'vehicle_invoice_no' => $this->vehicleInvoiceNo
]);
$this->say('Vehicle Information Saved!');
$this->bot->startConversation(new doYouWantToContinueConversation());
}
}

View File

@ -54,10 +54,12 @@ class ChatbotControllerNew extends BaseController
{
// 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->reply('Hi how can i assit?');
$bot->startConversation(new MainMenuConversation());
});
// $this->botman->hears('main_menu', function (BotMan $bot) {
// BotService::sendMainOptions($bot);
// });

View File

@ -5,6 +5,8 @@ namespace App\Helpers;
use App\Models\EmployeeModel;
use App\Models\CDMasterModel;
use App\Models\EmployeePolicyModel;
use App\Models\TPAModel;
class ChatbotHelper
{
@ -19,9 +21,44 @@ class ChatbotHelper
$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]);
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;
$EmployeePolicyModel = new EmployeePolicyModel();
return $EmployeePolicyModel->getHospitalLinkByPolicyandEmp(336,12288);
}
public static function getPhoneNumber(){
$emp_id = 12288;
$EmployeeModel = new EmployeeModel();
return $EmployeeModel->select('mobile')->where('id',$emp_id)->first()['mobile'];
}
public static function get_payload_data(string $key = null)
{
// Get the request object using the service helper
$request = service('request');
// Get the raw input (JSON or other data)
$rawInput = $request->getBody();
// Check if the raw input is valid JSON
$payload = json_decode($rawInput, true);
if (json_last_error() === JSON_ERROR_NONE) {
// JSON is valid, return the requested key or the entire payload
return $key ? ($payload[$key] ?? null) : $payload;
} else {
// JSON is invalid, fallback to raw input or POST data
$payload = $request->getRawInput() ?: $request->getPost();
return $key ? ($payload[$key] ?? null) : $payload;
}
}
}

View File

@ -1744,4 +1744,17 @@ class EmployeePolicyModel extends Model
return $result[0];
}
public function getHospitalLinkByPolicyandEmp($client_policy_id,$emp_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];
// var_dump($this->db->getLastQuery());
return $data;
}
}

View File

@ -24,8 +24,8 @@
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
chatServer: `<?=base_url('chat')?>`, // Make sure this URL is correct
frameEndpoint: `<?=base_url('widget')?>`, // This should match your CI4
title: "Ask ஆதிரை",
introMessage: "",
bubbleBackground: "#007bff",

View File

@ -27,7 +27,7 @@
"psr/http-message": "^1.0",
"psr/log": "^1.1",
"slim/slim": "^4.13",
"symfony/cache": "^7.2",
"symfony/cache": "^6.0",
"zircote/swagger-php": "^4.8"
},
"require-dev": {