nhance/app/Controllers/Chatbot/doYouWantToContinueConversation.php
2025-02-04 15:51:39 +05:30

51 lines
1.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 doYouWantToContinueConversation extends Conversation
{
public function run()
{
$this->bot->types(); // Typing indicator for the first message
sleep(3); // Delay
$this->askQuestion();
}
protected function askQuestion()
{
$question = Question::create("Do you Need Anything Else ?")
->addButtons([
Button::create("🔹 Yes I need some more Help")->value("yes"),
Button::create("🔹 No, Thank You")->value("no"),
// Button::create("◀️ Go Back")->value("go_back"),
]);
$this->bot->ask($question, function ($answer) {
switch ($answer->getValue()) {
case "yes":
// $this->say("Sure, How can I help you ");
$this->bot->startConversation(new MainMenuConversation());
break;
case "no":
$this->say("Thank you for your time! If you need anything else, feel free to reach out. Goodbye!");
break;
default:
$this->say("Invalid selection. Please choose an option.");
$this->askQuestion();
break;
}
});
}
}