diff --git a/app/Controllers/Chatbot/BotService.php b/app/Controllers/Chatbot/BotService.php deleted file mode 100644 index ee3b57ad..00000000 --- a/app/Controllers/Chatbot/BotService.php +++ /dev/null @@ -1,110 +0,0 @@ -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 - ]) - ]); - } -} \ No newline at end of file diff --git a/app/Controllers/Chatbot/ClaimHandler.php b/app/Controllers/Chatbot/ClaimHandler.php deleted file mode 100644 index b1839734..00000000 --- a/app/Controllers/Chatbot/ClaimHandler.php +++ /dev/null @@ -1,34 +0,0 @@ - "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")) - ); - } -} diff --git a/app/Controllers/Chatbot/LoginToContiueConversation.php b/app/Controllers/Chatbot/LoginToContiueConversation.php new file mode 100644 index 00000000..74a28a6c --- /dev/null +++ b/app/Controllers/Chatbot/LoginToContiueConversation.php @@ -0,0 +1,26 @@ +bot->userStorage()->delete(); + $this->bot->types(); // Typing indicator for the first message + sleep(0.5); // Delay + $this->showLoginMessage(); + } + + protected function showLoginMessage() + { + $this->say("Kindly Login to use the chatbot"); + } +} diff --git a/app/Controllers/Chatbot/PolicyHandler.php b/app/Controllers/Chatbot/PolicyHandler.php deleted file mode 100644 index 9491ef9d..00000000 --- a/app/Controllers/Chatbot/PolicyHandler.php +++ /dev/null @@ -1,36 +0,0 @@ - "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")) - ); - } -} diff --git a/app/Controllers/Chatbot/TypingMiddleware.php b/app/Controllers/Chatbot/TypingMiddleware.php deleted file mode 100644 index 047d246b..00000000 --- a/app/Controllers/Chatbot/TypingMiddleware.php +++ /dev/null @@ -1,27 +0,0 @@ -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/ChatbotControllerNew.php b/app/Controllers/ChatbotControllerNew.php index b68a9581..610f2bda 100644 --- a/app/Controllers/ChatbotControllerNew.php +++ b/app/Controllers/ChatbotControllerNew.php @@ -2,6 +2,7 @@ namespace App\Controllers; +use App\Controllers\Chatbot\LoginToContiueConversation; use BotMan\BotMan\BotMan; use BotMan\BotMan\BotManFactory; use BotMan\BotMan\Drivers\DriverManager; @@ -19,6 +20,7 @@ class ChatbotControllerNew extends BaseController protected $myLogger; protected $session; protected $botman; + protected $isMemberLoggedIn; public function __construct() { @@ -90,6 +92,12 @@ class ChatbotControllerNew extends BaseController // $this->myLogger->logme('error', ('TEST' . $id)); $this->session->set('CHATBOT_RANDOM_USER_ID', $id); } + + $this->isMemberLoggedIn = false; + $chat_session_info = get_chatbot_session_info(); + if (!empty($chat_session_info['emp_id']) && !empty($chat_session_info['emp_code'] )){ + $this->isMemberLoggedIn = true; + } $this->botman->hears('.*', function ($bot) { @@ -98,8 +106,13 @@ 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('Hi how can i assist?'); - $bot->startConversation(new MainMenuConversation()); + if ($this->isMemberLoggedIn){ + $bot->reply('Hi how can i assist?'); + $bot->startConversation(new MainMenuConversation()); + }else { + $bot->startConversation(new LoginToContiueConversation()); + } + }); diff --git a/app/Views/chatbot.php b/app/Views/chatbot.php index 14a5f652..94373196 100644 --- a/app/Views/chatbot.php +++ b/app/Views/chatbot.php @@ -63,7 +63,7 @@ if (window.botmanWidget) { botmanChatWidget.open(); setTimeout(function(){ - botmanChatWidget.sayAsBot('Hi '+ emp_name +',This is ILA your Insurance Assistant, plz choose the following options') + botmanChatWidget.sayAsBot('Hi '+ (typeof emp_name !== "undefined" && emp_name !== null && emp_name !== "" ? emp_name : "Guest User") +',This is ILA your Insurance Assistant, plz choose the following options') botmanChatWidget.whisper('Hi'); },3000);