showEcardMenu(); } protected function showEcardMenu() { $chat_session_info = get_chatbot_session_info(); $policy_list = ChatbotHelper::getListOfPolicies($chat_session_info); $buttons = []; $question = 'Choose Policy to Download Ecard:'; if(is_array($policy_list) && count($policy_list)) { foreach($policy_list as $policy) { // $question = Question::create("Choose Policy to Download Ecard:") // ->addButtons([ // Button::create("🔹 $policy['policy_name']")->value("$policy['emp_policy_id']"), // Button::create("◀️ Go Back")->value("go_back"), // ]); $buttons[] = Button::create("🔹 {$policy['policy_name']}")->value($policy['emp_policy_id'].'#'.$policy['rand_string']); } } else { $question = 'No policy found'; } $buttons = array_merge($buttons,[Button::create("◀️ Go Back")->value("go_back")]); $question = Question::create($question) ->addButtons($buttons); $this->bot->ask($question, function ($answer) { $selectedOption = $answer->getText(); $this->say("You have selected {$selectedOption}"); switch ($answer->getValue()) { case "go_back": $this->bot->startConversation(new MainMenuConversation()); break; case is_string($answer->getValue()) && is_array(explode('#',$answer->getValue())) && count((explode('#',$answer->getValue()))) == 2: $link = base_url().'/download-e-card/' . explode('#',$answer->getValue())[1].'/1'; $this->say('Click here to downlad: Ecard'); $this->bot->startConversation(new doYouWantToContinueConversation()); // ✅ Restart the break; default: $this->say("Invalid selection. Please choose an option."); $this->bot->startConversation(new EcardDownloadConversation()); // ✅ Restart the conversation break; } }); } }