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

76 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 twoWheelerOptionsConversations extends Conversation
{
protected $buttonsData = [
"3p" => ["response_text" => "🔹 Third-Party"],
"comp" => ["response_text" => "🔹 Comprehensive"],
"go_back" => ["response_text" => "◀️ Go Back"]
];
public function run()
{
$this->show2WOptions();
}
protected function show2WOptions()
{
$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;
}
$path = $this->bot->userStorage()->get('path');
array_push($path,
$answer->getValue()
);
$this->bot->userStorage()->save([
'path' => $path
]);
switch ($user_reponse) {
case "3p":
// $cityName = $response->getText();
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "comp":
$this->bot->startConversation(new commonPolicyOptionConversations());
break;
case "go_back":
$this->bot->startConversation(new MainMenuConversation());
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->showHospitalMenu();
break;
}
});
}
}