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; } }); } }