nhance/app/Controllers/Chatbot/hospitalPolicyConversation.php
2025-02-10 12:37:36 +05:30

73 lines
2.5 KiB
PHP

<?php
// namespace App\Conversations;
namespace App\Controllers\Chatbot;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Outgoing\Question;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
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()
{
$this->showMediclaimPolicyOptions();
}
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("🔹 ".$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) use ($value, $text){
$path = $this->bot->userStorage()->get('path');
array_push($path,
$answer->getValue()
);
$this->bot->userStorage()->save([
'path' => $path
]);
switch ($answer->getValue()) {
case $value:
$this->say("you have chosen ".$text);
$this->bot->startConversation(new medicalClaimFormConversations());
break;
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 medicalClaimOptionConversations());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->showHospitalMenu();
break;
}
});
}
}