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

This commit is contained in:
VENKATESHWARAN 2025-03-01 17:46:31 +05:30
commit 3a31a89f79
7 changed files with 42 additions and 210 deletions

View File

@ -1,110 +0,0 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
class BotService
{
public static function sendMainOptions(BotMan $bot)
{
$bot->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
])
]);
}
}

View File

@ -1,34 +0,0 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Outgoing\Actions\ButtonTemplate;
use BotMan\BotMan\Messages\Outgoing\Actions\ElementButton;
class ClaimHandler
{
public static function handle(BotMan $bot, $option)
{
$responses = [
'reimbursement_claim_process' => "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"))
);
}
}

View File

@ -0,0 +1,26 @@
<?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;
use BotMan\Drivers\Web\WebDriver;
class LoginToContiueConversation extends Conversation
{
public function run()
{
$this->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");
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace App\Controllers\Chatbot;
use BotMan\BotMan\BotMan;
use BotMan\BotMan\Messages\Outgoing\Actions\ButtonTemplate;
use BotMan\BotMan\Messages\Outgoing\Actions\ElementButton;
class PolicyHandler
{
public static function handle(BotMan $bot, $option)
{
$responses = [
'ecard_download' => "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"))
);
}
}

View File

@ -1,27 +0,0 @@
<?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

@ -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());
}
});

View File

@ -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);