108 lines
4.0 KiB
PHP
108 lines
4.0 KiB
PHP
<?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 MainMenuConversation extends Conversation
|
|
{
|
|
protected $buttonsData = [
|
|
"ecard_download" => ["response_text" => "📄 Ecard Download"],
|
|
"network_hospital" => ["response_text" => "🏥 Network Hospital"],
|
|
"reimbursement_claim" => ["response_text" => "💰 Reimbursement Claim Process"],
|
|
"reimbursement_status" => ["response_text" => "📑 Reimbursement Claim Status"],
|
|
"new_policy" => ["response_text" => "🆕 New Policy"],
|
|
"renew_policy" => ["response_text" => "🔄 Renew Policy"],
|
|
];
|
|
|
|
public function run()
|
|
{
|
|
$this->bot->userStorage()->delete();
|
|
$this->bot->types(); // Typing indicator for the first message
|
|
sleep(0.5); // Delay
|
|
$this->showMainMenu();
|
|
}
|
|
|
|
protected function showMainMenu()
|
|
{
|
|
$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);
|
|
}
|
|
|
|
log_message('error', ('user_reponse before: ' . $user_reponse));
|
|
|
|
|
|
if (!$answer->isInteractiveMessageReply()) {
|
|
$user_reponse = null;
|
|
}
|
|
|
|
log_message('error', ('user_reponse is interactive: ' . $answer->isInteractiveMessageReply()));
|
|
|
|
|
|
// 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
|
|
]);
|
|
|
|
log_message('error', ('user_reponse after: ' . $user_reponse));
|
|
|
|
|
|
switch ($user_reponse) {
|
|
|
|
case "ecard_download":
|
|
$this->bot->startConversation(new EcardDownloadConversation());
|
|
log_message('error', 'ecard_download clicked ');
|
|
|
|
break;
|
|
case "network_hospital":
|
|
$this->bot->startConversation(new NetworkHospitalConversation());
|
|
log_message('error', 'network_hospital clicked ');
|
|
break;
|
|
case "reimbursement_claim":
|
|
$this->bot->startConversation(new ReimbursementClaimProcessConversation());
|
|
log_message('error', 'reimbursement_claim clicked ');
|
|
break;
|
|
case "reimbursement_status":
|
|
$this->bot->startConversation(new ReimbursementClaimStatusConversation());
|
|
log_message('error', 'reimbursement_status clicked ');
|
|
break;
|
|
case "new_policy":
|
|
case "renew_policy":
|
|
$this->bot->startConversation(new policyConversation());
|
|
log_message('error', 'renew_policy || new_policy clicked ');
|
|
break;
|
|
default:
|
|
log_message('error', 'default shown ');
|
|
$this->say("Invalid selection. Please choose an option.");
|
|
$this->bot->startConversation(new MainMenuConversation());
|
|
break;
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
}
|