90 lines
3.0 KiB
PHP
90 lines
3.0 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
|
|
{
|
|
protected $buttonsData = [
|
|
"yes" => ["response_text" => "🔹 Yes I need some more Help"],
|
|
"no" => ["response_text" => "🔹 No, Thank You"]
|
|
];
|
|
|
|
|
|
public function run()
|
|
{
|
|
$this->bot->types(); // Typing indicator for the first message
|
|
sleep(3); // Delay
|
|
$this->askQuestion();
|
|
}
|
|
|
|
protected function askQuestion()
|
|
{
|
|
$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 "yes":
|
|
|
|
// $this->say("Sure, How can I help you ");
|
|
$this->bot->startConversation(new MainMenuConversation());
|
|
break;
|
|
case "no":
|
|
// $user = $this->bot->getUser();
|
|
// $userID = $user->getId();
|
|
$dataBefore = $this->bot->userStorage()->all();
|
|
// log_message('info','Before Deletion: ' . json_encode($dataBefore));
|
|
|
|
$this->bot->userStorage()->delete();
|
|
$this->bot->userStorage()->save([]);
|
|
|
|
|
|
// Cache::flush();
|
|
|
|
$dataAfter = $this->bot->userStorage()->all();
|
|
// log_message('info','After Deletion: ' . json_encode($dataAfter));
|
|
|
|
|
|
$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;
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|