Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
3a31a89f79
@ -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
|
|
||||||
])
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
26
app/Controllers/Chatbot/LoginToContiueConversation.php
Normal file
26
app/Controllers/Chatbot/LoginToContiueConversation.php
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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"))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Controllers;
|
namespace App\Controllers;
|
||||||
|
|
||||||
|
use App\Controllers\Chatbot\LoginToContiueConversation;
|
||||||
use BotMan\BotMan\BotMan;
|
use BotMan\BotMan\BotMan;
|
||||||
use BotMan\BotMan\BotManFactory;
|
use BotMan\BotMan\BotManFactory;
|
||||||
use BotMan\BotMan\Drivers\DriverManager;
|
use BotMan\BotMan\Drivers\DriverManager;
|
||||||
@ -19,6 +20,7 @@ class ChatbotControllerNew extends BaseController
|
|||||||
protected $myLogger;
|
protected $myLogger;
|
||||||
protected $session;
|
protected $session;
|
||||||
protected $botman;
|
protected $botman;
|
||||||
|
protected $isMemberLoggedIn;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@ -91,6 +93,12 @@ class ChatbotControllerNew extends BaseController
|
|||||||
$this->session->set('CHATBOT_RANDOM_USER_ID', $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) {
|
$this->botman->hears('.*', function ($bot) {
|
||||||
|
|
||||||
$bot->types(); // Typing indicator for the first message
|
$bot->types(); // Typing indicator for the first message
|
||||||
@ -98,8 +106,13 @@ class ChatbotControllerNew extends BaseController
|
|||||||
});
|
});
|
||||||
// Start the Main Menu when user says "hi" or "start"
|
// Start the Main Menu when user says "hi" or "start"
|
||||||
$this->botman->hears('start|hi|hello', function (BotMan $bot) {
|
$this->botman->hears('start|hi|hello', function (BotMan $bot) {
|
||||||
$bot->reply('Hi how can i assist?');
|
if ($this->isMemberLoggedIn){
|
||||||
$bot->startConversation(new MainMenuConversation());
|
$bot->reply('Hi how can i assist?');
|
||||||
|
$bot->startConversation(new MainMenuConversation());
|
||||||
|
}else {
|
||||||
|
$bot->startConversation(new LoginToContiueConversation());
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
if (window.botmanWidget) {
|
if (window.botmanWidget) {
|
||||||
botmanChatWidget.open();
|
botmanChatWidget.open();
|
||||||
setTimeout(function(){
|
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');
|
botmanChatWidget.whisper('Hi');
|
||||||
},3000);
|
},3000);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user