nhance/app/Controllers/Chatbot/policyConversation.php
Srinivas-Saravanan 27817789ad DEBUG_CHATBOT
2025-04-04 14:25:21 +05:30

83 lines
2.8 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 policyConversation extends Conversation
{
protected $buttonsData = [
"2_wheeler" => ["response_text" => "🏍️ 2 Wheeler"],
"4_wheeler" => ["response_text" => "🚗 4 Wheeler"],
"mediclaim" => ["response_text" => "🩺 Medical Claim"],
"go_back" => ["response_text" => "◀️ Go Back"],
];
public function run()
{
$this->showNewPolicy();
}
protected function showNewPolicy()
{
$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);
}
if (!$answer->isInteractiveMessageReply()) {
$user_reponse = null;
}
log_message('error', ('user_reponse : ' . $answer->getValue()));
$path = $this->bot->userStorage()->get('path');
array_push($path,
$answer->getValue()
);
$this->bot->userStorage()->save([
'path' => $path
]);
switch ($user_reponse) {
case "2_wheeler":
// $cityName = $response->getText();
$this->bot->startConversation(new twoWheelerOptionsConversations());
break;
case "4_wheeler":
$this->bot->startConversation(new fourWheelerOptionsConversations());
break;
case "mediclaim":
$this->bot->startConversation(new medicalClaimOptionConversations());
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->showHospitalMenu();
break;
}
});
}
}