69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Chatbot;
|
|
|
|
use App\Helpers\ChatbotHelper;
|
|
use BotMan\BotMan\Messages\Conversations\Conversation;
|
|
use BotMan\BotMan\Messages\Outgoing\Question;
|
|
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
|
|
|
|
class serviceExecutiveConversation extends Conversation
|
|
{
|
|
protected $mobile_number;
|
|
|
|
public function run()
|
|
{
|
|
$this->askServiceExecutive();
|
|
}
|
|
|
|
protected function askServiceExecutive()
|
|
{
|
|
$chat_session_info = get_chatbot_session_info();
|
|
$mobile = ChatbotHelper::getPhoneNumber($chat_session_info); // Assuming this fetches the user's phone number
|
|
$question = Question::create("Is this Your Mobile Number: $mobile")
|
|
->addButtons([
|
|
Button::create("✅ Yes")->value("yes"),
|
|
Button::create("❌ No")->value("no"),
|
|
Button::create("◀️ Go Back")->value("go_back"),
|
|
]);
|
|
|
|
$this->bot->ask($question, function ($answer) {
|
|
$path = $this->bot->userStorage()->get('path');
|
|
array_push($path,
|
|
$answer->getValue()
|
|
);
|
|
$this->bot->userStorage()->save([
|
|
'path' => $path
|
|
]);
|
|
switch ($answer->getValue()) {
|
|
case "yes":
|
|
$this->say("Our executive will call you at the earliest.");
|
|
$this->bot->startConversation(new doYouWantToContinueConversation());
|
|
break;
|
|
|
|
case "no":
|
|
$this->ask('Enter Your Mobile Number?', function ($response) {
|
|
$this->mobile_number = $response->getText();
|
|
$this->bot->userStorage()->save([
|
|
'mobile_number' => $this->mobile_number
|
|
]);
|
|
// Use 'use' to bring the class context into the closure
|
|
$this->say("Our executive will call you at the earliest.");
|
|
$this->bot->startConversation(new doYouWantToContinueConversation());
|
|
});
|
|
break;
|
|
|
|
case "go_back":
|
|
$this->bot->startConversation(new MainMenuConversation());
|
|
break;
|
|
|
|
default:
|
|
$this->say("Invalid selection. Please choose an option.");
|
|
$this->askServiceExecutive();
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|