diff --git a/app/Controllers/Chatbot/EcardDownloadConversation.php b/app/Controllers/Chatbot/EcardDownloadConversation.php
index 19fad42f..b0cb78ae 100644
--- a/app/Controllers/Chatbot/EcardDownloadConversation.php
+++ b/app/Controllers/Chatbot/EcardDownloadConversation.php
@@ -17,7 +17,8 @@ class EcardDownloadConversation extends Conversation
protected function showEcardMenu()
{
- $policy_list = ChatbotHelper::getListOfPolicies();
+ $chat_session_info = get_chatbot_session_info();
+ $policy_list = ChatbotHelper::getListOfPolicies($chat_session_info);
$buttons = [];
$question = 'Choose Policy to Download Ecard:';
if(is_array($policy_list) && count($policy_list))
@@ -41,7 +42,8 @@ class EcardDownloadConversation extends Conversation
->addButtons($buttons);
$this->bot->ask($question, function ($answer) {
- // print_r($answer->getValue());die();
+ $selectedOption = $answer->getText();
+ $this->say("You have selected {$selectedOption}");
switch ($answer->getValue()) {
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
diff --git a/app/Controllers/Chatbot/MainMenuConversation.php b/app/Controllers/Chatbot/MainMenuConversation.php
index 5a857002..87d9a4ef 100644
--- a/app/Controllers/Chatbot/MainMenuConversation.php
+++ b/app/Controllers/Chatbot/MainMenuConversation.php
@@ -21,6 +21,7 @@ class MainMenuConversation extends Conversation
public function run()
{
+ $this->bot->userStorage()->delete();
$this->bot->types(); // Typing indicator for the first message
sleep(0.5); // Delay
$this->showMainMenu();
@@ -32,7 +33,9 @@ class MainMenuConversation extends Conversation
foreach ($this->buttonsData as $key => $data) {
$buttons[] = Button::create($data['response_text'])->value($key);
}
-
+ $this->bot->userStorage()->save([
+ 'path' => []
+ ]);
$question = Question::create("Please choose an option:")->addButtons($buttons);
$temp = $this->buttonsData;
$this->bot->ask($question, function ($answer) use( $temp ){
@@ -46,13 +49,23 @@ class MainMenuConversation extends Conversation
if (!$answer->isInteractiveMessageReply()) {
$user_reponse = null;
}
+ // Get just the existing path array
+ $path = $this->bot->userStorage()->get('path') ?? [];
+
+ // Add new value
+ array_push($path, $answer->getValue());
+
+ // Save ONLY the path back
+ $this->bot->userStorage()->save([
+ 'path' => $path
+ ]);
switch ($user_reponse) {
+
case "ecard_download":
$this->bot->startConversation(new EcardDownloadConversation());
break;
case "network_hospital":
- log_message('error', 'Network Hospital clicked');
$this->bot->startConversation(new NetworkHospitalConversation());
break;
case "reimbursement_claim":
@@ -63,7 +76,7 @@ class MainMenuConversation extends Conversation
break;
case "new_policy":
case "renew_policy":
- $this->bot->startConversation(new PolicyConversation());
+ $this->bot->startConversation(new policyConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
diff --git a/app/Controllers/Chatbot/NetworkHospitalConversation.php b/app/Controllers/Chatbot/NetworkHospitalConversation.php
index 28d8f0e6..2e59f896 100644
--- a/app/Controllers/Chatbot/NetworkHospitalConversation.php
+++ b/app/Controllers/Chatbot/NetworkHospitalConversation.php
@@ -52,6 +52,13 @@ class NetworkHospitalConversation extends Conversation
// });
$this->bot->ask($question, function ($answer) {
+ $path = $this->bot->userStorage()->get('path');
+ array_push($path,
+ $answer->getValue()
+ );
+ $this->bot->userStorage()->save([
+ 'path' => $path
+ ]);
switch ($answer->getValue()) {
case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2:
@@ -74,7 +81,7 @@ class NetworkHospitalConversation extends Conversation
break;
default:
$this->say("Invalid selection. Please choose an option.");
- $this->bot->startConversation(new EcardDownloadConversation());
+ $this->bot->startConversation(new NetworkHospitalConversation());
break;
}
});
diff --git a/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php b/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php
index ca3bf60a..14602974 100644
--- a/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php
+++ b/app/Controllers/Chatbot/ReimbursementClaimProcessConversation.php
@@ -20,7 +20,8 @@ class ReimbursementClaimProcessConversation extends Conversation
protected function claimProcess()
{
- $res = ChatbotHelper::sendReimbursementProcessOverMail();
+ $chat_session_info = get_chatbot_session_info();
+ $res = ChatbotHelper::sendReimbursementProcessOverMail($chat_session_info);
if($res == true)
{
$this->say("Reimbursement process shared over your registered mail...!");
diff --git a/app/Controllers/Chatbot/ReimbursementClaimStatusConversation.php b/app/Controllers/Chatbot/ReimbursementClaimStatusConversation.php
index 4c6b58dc..db8831bc 100644
--- a/app/Controllers/Chatbot/ReimbursementClaimStatusConversation.php
+++ b/app/Controllers/Chatbot/ReimbursementClaimStatusConversation.php
@@ -2,6 +2,7 @@
// namespace App\Conversations;
namespace App\Controllers\Chatbot;
+use App\Helpers\ChatbotHelper;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
@@ -19,29 +20,19 @@ class ReimbursementClaimStatusConversation extends Conversation
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->say("Fetching Status please wait ...");
- $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;
- }
- });
+ $chat_session_info = get_chatbot_session_info();
+ $data = ChatbotHelper::getReimbursementClaimStatus($chat_session_info);
+
+ $this->bot->types();
+ if ($data){
+ $this->say("The claim status for the claim Number {$data['claim_number']} is currently in {$data['claim_status']} status.
More Detailed Information is sent to your mail");
+ $this->bot->startConversation(new doYouWantToContinueConversation());
+ }else{
+ $this->say("No Claim Raised against the user.");
+ $this->bot->startConversation(new doYouWantToContinueConversation());
+ }
}
}
diff --git a/app/Controllers/Chatbot/commonPolicyOptionConversations.php b/app/Controllers/Chatbot/commonPolicyOptionConversations.php
index e32c318b..c6eb8eae 100644
--- a/app/Controllers/Chatbot/commonPolicyOptionConversations.php
+++ b/app/Controllers/Chatbot/commonPolicyOptionConversations.php
@@ -11,7 +11,11 @@ use App\Helpers\ChatbotHelper;
class commonPolicyOptionConversations extends Conversation
{
-
+ protected $buttonsData = [
+ "upload_vehicle_details" => ["response_text" => "🔹 Upload Vehicle Details"],
+ "service_executive" => ["response_text" => "🔹 Talk to our Service Executive"],
+ "go_back" => ["response_text" => "◀️ Go Back"],
+ ];
public function run()
{
@@ -20,15 +24,36 @@ class commonPolicyOptionConversations extends Conversation
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"),
- ]);
+ $buttons = [];
+ foreach ($this->buttonsData as $key => $data) {
+ $buttons[] = Button::create($data['response_text'])->value($key);
+ }
+ // $this->bot->userStorage()->save([
+ // 'path' => []
+ // ]);
+ $question = Question::create("Please choose an option:")->addButtons($buttons);
+ $temp = $this->buttonsData;
+ $this->bot->ask($question, function ($answer) use( $temp ){
+ $user_reponse = $answer->getValue();
+ if (isset($temp[$user_reponse])) {
+ $message = "You've chosen " . $temp[$user_reponse]['response_text'];
+ // $this->bot->say($message,,WebDriver::class);
+ $this->bot->reply($message);
+ }
- $this->bot->ask($question, function ($answer) {
- switch ($answer->getValue()) {
+ if (!$answer->isInteractiveMessageReply()) {
+ $user_reponse = null;
+ }
+ $path = $this->bot->userStorage()->get('path');
+ array_push($path,
+ $answer->getValue()
+ );
+ $this->bot->userStorage()->save([
+ 'path' => $path
+ ]);
+ $path = $this->bot->userStorage()->get('path');
+ // $this->say(json_encode($path));
+ switch ($user_reponse) {
case "upload_vehicle_details":
// $cityName = $response->getText();
$this->bot->startConversation(new vehicleFormConversation());
@@ -48,3 +73,5 @@ class commonPolicyOptionConversations extends Conversation
}
}
+
+
diff --git a/app/Controllers/Chatbot/doYouWantToContinueConversation.php b/app/Controllers/Chatbot/doYouWantToContinueConversation.php
index ba5c1864..31bcf174 100644
--- a/app/Controllers/Chatbot/doYouWantToContinueConversation.php
+++ b/app/Controllers/Chatbot/doYouWantToContinueConversation.php
@@ -11,6 +11,10 @@ use App\Helpers\ChatbotHelper;
class doYouWantToContinueConversation extends Conversation
{
+ protected $buttonsData = [
+ "yes" => ["response_text" => "🔹 Yes I need some more Help"],
+ "no" => ["response_text" => "🔹 No, Thank You"]
+ ];
public function run()
@@ -22,21 +26,56 @@ class doYouWantToContinueConversation extends Conversation
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"),
+ $buttons = [];
+ foreach ($this->buttonsData as $key => $data) {
+ $buttons[] = Button::create($data['response_text'])->value($key);
+ }
+ // $this->bot->userStorage()->save([
+ // 'path' => []
+ // ]);
+ $question = Question::create("Please choose an option:")->addButtons($buttons);
+ $temp = $this->buttonsData;
+ $this->bot->ask($question, function ($answer) use( $temp ){
+ $user_reponse = $answer->getValue();
+ if (isset($temp[$user_reponse])) {
+ $message = "You've chosen " . $temp[$user_reponse]['response_text'];
+ // $this->bot->say($message,,WebDriver::class);
+ $this->bot->reply($message);
+ }
+
+ if (!$answer->isInteractiveMessageReply()) {
+ $user_reponse = null;
+ }
+ $path = $this->bot->userStorage()->get('path');
+ array_push($path,
+ $answer->getValue()
+ );
+ $this->bot->userStorage()->save([
+ 'path' => $path
]);
- $this->bot->ask($question, function ($answer) {
- switch ($answer->getValue()) {
+ switch ($user_reponse) {
case "yes":
// $this->say("Sure, How can I help you ");
$this->bot->startConversation(new MainMenuConversation());
break;
case "no":
+ // $user = $this->bot->getUser();
+ // $userID = $user->getId();
+ $dataBefore = $this->bot->userStorage()->all();
+ // log_message('info','Before Deletion: ' . json_encode($dataBefore));
+
+ $this->bot->userStorage()->delete();
+ $this->bot->userStorage()->save([]);
+
+
+ // Cache::flush();
+
+ $dataAfter = $this->bot->userStorage()->all();
+ // log_message('info','After Deletion: ' . json_encode($dataAfter));
+
+
$this->say("Thank you for your time! If you need anything else, feel free to reach out. Goodbye!");
break;
default:
diff --git a/app/Controllers/Chatbot/fourWheelerOptionsConversations.php b/app/Controllers/Chatbot/fourWheelerOptionsConversations.php
index 6c850c03..b2753566 100644
--- a/app/Controllers/Chatbot/fourWheelerOptionsConversations.php
+++ b/app/Controllers/Chatbot/fourWheelerOptionsConversations.php
@@ -11,7 +11,11 @@ use App\Helpers\ChatbotHelper;
class fourWheelerOptionsConversations extends Conversation
{
-
+ protected $buttonsData = [
+ "comp" => ["response_text" => "🔹 Comprehensive"],
+ "3p" => ["response_text" => "🔹 Third-Party Only"],
+ "go_back" => ["response_text" => "◀️ Go Back"],
+ ];
public function run()
{
@@ -20,15 +24,36 @@ class fourWheelerOptionsConversations extends Conversation
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"),
- ]);
+ $buttons = [];
+ foreach ($this->buttonsData as $key => $data) {
+ $buttons[] = Button::create($data['response_text'])->value($key);
+ }
+ // $this->bot->userStorage()->save([
+ // 'path' => []
+ // ]);
+ $question = Question::create("Please choose an option:")->addButtons($buttons);
+ $temp = $this->buttonsData;
+ $this->bot->ask($question, function ($answer) use( $temp ){
+ $user_reponse = $answer->getValue();
+ if (isset($temp[$user_reponse])) {
+ $message = "You've chosen " . $temp[$user_reponse]['response_text'];
+ // $this->bot->say($message,,WebDriver::class);
+ $this->bot->reply($message);
+ }
- $this->bot->ask($question, function ($answer) {
- switch ($answer->getValue()) {
+ if (!$answer->isInteractiveMessageReply()) {
+ $user_reponse = null;
+ }
+ $path = $this->bot->userStorage()->get('path');
+ array_push($path,
+ $answer->getValue()
+ );
+ $this->bot->userStorage()->save([
+ 'path' => $path
+ ]);
+ $path = $this->bot->userStorage()->get('path');
+ // $this->say(json_encode($path));
+ switch ($user_reponse) {
case "3p":
// $cityName = $response->getText();
$this->bot->startConversation(new commonPolicyOptionConversations());
diff --git a/app/Controllers/Chatbot/hospitalPolicyConversation.php b/app/Controllers/Chatbot/hospitalPolicyConversation.php
index 4a29c918..a171c005 100644
--- a/app/Controllers/Chatbot/hospitalPolicyConversation.php
+++ b/app/Controllers/Chatbot/hospitalPolicyConversation.php
@@ -11,7 +11,11 @@ use App\Helpers\ChatbotHelper;
class hospitalPolicyConversation extends Conversation
{
-
+ protected $buttonsData = [
+ "individual" => ["response_text" => "🔹 Individual"],
+ "floater" => ["response_text" => "🔹 Floater"],
+ "go_back" => ["response_text" => "◀️ Go Back"],
+ ];
public function run()
{
@@ -20,23 +24,42 @@ class hospitalPolicyConversation extends Conversation
protected function showMediclaimPolicyOptions()
{
+ $path = $this->bot->userStorage()->get('path');
+
+ if (in_array('individual',$path)){
+ $text = 'Upload Policy Copy and Individual Details';
+ $value = 'individual_upload';
+ }else{
+ $text = 'Upload Policy Copy and Family Details';
+ $value = 'family_upload';
+ }
$question = Question::create("Choose Policy Type:")
->addButtons([
- Button::create("🔹 Individual")->value("individual"),
- Button::create("🔹 Floater")->value("floater"),
+ Button::create("🔹 ".$text)->value($value),
+ Button::create("🔹 Talk to our Service Executive")->value("service_executive"),
Button::create("◀️ Go Back")->value("go_back"),
]);
- $this->bot->ask($question, function ($answer) {
+ $this->bot->ask($question, function ($answer) use ($value, $text){
+ $path = $this->bot->userStorage()->get('path');
+ array_push($path,
+ $answer->getValue()
+ );
+ $this->bot->userStorage()->save([
+ 'path' => $path
+ ]);
switch ($answer->getValue()) {
- case "individual":
- $this->bot->startConversation(new commonPolicyOptionConversations());
+ case $value:
+ $this->say("you have chosen ".$text);
+
+ $this->bot->startConversation(new medicalClaimFormConversations());
break;
- case "floater":
- $this->bot->startConversation(new commonPolicyOptionConversations());
+ case "service_executive":
+ $this->say('You have chosen to speak with our Service Executive');
+ $this->bot->startConversation(new serviceExecutiveConversation());
break;
case "go_back":
- $this->bot->startConversation(new MainMenuConversation());
+ $this->bot->startConversation(new medicalClaimOptionConversations());
break;
default:
$this->say("Invalid selection. Please choose an option.");
diff --git a/app/Controllers/Chatbot/medicalClaimFormConversations.php b/app/Controllers/Chatbot/medicalClaimFormConversations.php
new file mode 100644
index 00000000..d0d21e7e
--- /dev/null
+++ b/app/Controllers/Chatbot/medicalClaimFormConversations.php
@@ -0,0 +1,313 @@
+ null,
+ 'dob' => null,
+ 'si' => null,
+ 'pre_existing_disease' => null
+ ];
+
+ public function run()
+ {
+ // Initialize state if not exists
+ if (!$this->bot->userStorage()->get('claim_form_state')) {
+ $this->bot->userStorage()->save([
+ 'claim_form_state' => [
+ 'dependency_count' => 0,
+ 'current_member' => 'primary',
+ 'dependencies' => [],
+ 'primary_insurer' => null
+ ]
+ ]);
+ }
+
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ $memberType = ($state['current_member'] === 'primary') ? 'primary insured person' : 'dependency';
+
+ $this->askName($memberType);
+ }
+
+ private function askName($memberType)
+ {
+ $this->ask("Enter the Name of the $memberType?", function($answer) {
+ $name = $answer->getText();
+
+ if (empty($name)) {
+ $this->say('Name Cannot be Empty');
+ return $this->run();
+ }
+
+ // Get existing state and update only the name
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ if ($state['current_member'] === 'primary') {
+ if (!isset($state['primary_insurer'])) {
+ $state['primary_insurer'] = [];
+ }
+ $state['primary_insurer']['name'] = $name;
+ } else {
+ if (!isset($state['temp_dependency'])) {
+ $state['temp_dependency'] = [];
+ }
+ $state['temp_dependency']['name'] = $name;
+ }
+
+ $this->bot->userStorage()->save(['claim_form_state' => $state]);
+ $this->askDOB();
+ });
+ }
+
+ private function askDOB()
+ {
+ $this->ask('Enter Date of Birth (DD/MM/YYYY)?', function($answer) {
+ $dob = $answer->getText();
+
+ if (empty($dob)) {
+ $this->say('Date of Birth Cannot be Empty');
+ return $this->askDOB();
+ }
+
+ // Get existing state and update only the DOB
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ if ($state['current_member'] === 'primary') {
+ $state['primary_insurer']['dob'] = $dob;
+ } else {
+ $state['temp_dependency']['dob'] = $dob;
+ }
+
+ $this->bot->userStorage()->save(['claim_form_state' => $state]);
+ $this->askSumInsured();
+ });
+ }
+
+ private function askSumInsured()
+ {
+ $this->ask('Enter Sum Insured Amount?', function($answer) {
+ $sum_insured = $answer->getText();
+
+ if (empty($sum_insured)) {
+ $this->say('Sum Insured Cannot be Empty');
+ return $this->askSumInsured();
+ }
+
+ // Get existing state and update only the sum insured
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ if ($state['current_member'] === 'primary') {
+ $state['primary_insurer']['si'] = $sum_insured;
+ } else {
+ $state['temp_dependency']['si'] = $sum_insured;
+ }
+
+ $this->bot->userStorage()->save(['claim_form_state' => $state]);
+ $this->askPreExistingDisease();
+ });
+ }
+
+ private function askPreExistingDisease()
+ {
+ $this->ask('Enter Pre-Existing Disease if any (type "none" if none)?', function($answer) {
+ $pre_existing_disease = $answer->getText();
+
+ if (empty($pre_existing_disease)) {
+ $this->say('Please enter none if no pre-existing conditions');
+ return $this->askPreExistingDisease();
+ }
+
+ // Get existing state and update the disease info
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ if ($state['current_member'] === 'primary') {
+ $state['primary_insurer']['pre_existing_disease'] = $pre_existing_disease;
+ $state['primary_insurer']['type'] = 'primary';
+ } else {
+ $state['temp_dependency']['pre_existing_disease'] = $pre_existing_disease;
+ $state['temp_dependency']['type'] = 'dependency';
+
+ // Move completed dependency to dependencies array
+ if (!isset($state['dependencies'])) {
+ $state['dependencies'] = [];
+ }
+ $state['dependencies'][] = $state['temp_dependency'];
+ $state['temp_dependency'] = null; // Clear temporary dependency
+ }
+
+ $this->bot->userStorage()->save(['claim_form_state' => $state]);
+
+ // For debugging
+ log_message('debug', 'Final state after all data collection: ' . json_encode($state));
+
+ $this->saveMemberAndContinue();
+ });
+ }
+
+ private function saveMemberAndContinue()
+ {
+ $state = $this->bot->userStorage()->get('claim_form_state');
+ $memberData = $state['current_member'] === 'primary'
+ ? $state['primary_insurer']
+ : end($state['dependencies']);
+
+ // Show current member info
+ $memberInfo = "👤 **" . ucfirst($memberData['type']) . " Member Details:**\n";
+ $memberInfo .= "🔹 Name: " . $memberData['name'] . "\n";
+ $memberInfo .= "🔹 Date of Birth: " . $memberData['dob'] . "\n";
+ $memberInfo .= "🔹 Sum Insured: " . $memberData['si'] . "\n";
+ $memberInfo .= "🔹 Pre Existing Disease: " . $memberData['pre_existing_disease'] . "\n";
+
+ $this->say($memberInfo);
+
+ $path = $this->bot->userStorage()->get('path');
+
+ if (in_array('floater', $path)) {
+ $this->askAboutDependencies();
+ } else {
+ $this->showSummary();
+ }
+ }
+
+ private function askAboutDependencies()
+ {
+ $question = Question::create("Do you want to add a dependency? ")
+ ->addButtons([
+ Button::create("✅ Yes")->value("yes"),
+ Button::create("❌ No")->value("no"),
+ Button::create("◀️ Go Back")->value("go_back"),
+ ]);
+
+ $this->ask($question, function($answer) {
+ $state = $this->bot->userStorage()->get('claim_form_state');
+
+ switch ($answer->getValue()) {
+ case "yes":
+ $state['dependency_count']++;
+ $state['current_member'] = 'dependency';
+ $this->bot->userStorage()->save(['claim_form_state' => $state]);
+
+ // Reset currentMemberData for new dependency
+ $this->currentMemberData = [
+ 'name' => null,
+ 'dob' => null,
+ 'si' => null,
+ 'pre_existing_disease' => null
+ ];
+
+ $this->run();
+ break;
+
+ case "no":
+ $this->showSummary();
+ break;
+
+ case "go_back":
+ $this->bot->startConversation(new hospitalPolicyConversation());
+ break;
+
+ default:
+ $this->say("Invalid selection. Please choose an option.");
+ $this->askAboutDependencies();
+ break;
+ }
+ });
+ }
+
+ private function showSummary()
+ {
+ $state = $this->bot->userStorage()->get('claim_form_state');
+
+ $finalSummary = '
Directory access is forbidden.
- - -