Skip to content

Latest commit

 

History

History
1177 lines (896 loc) · 37.1 KB

File metadata and controls

1177 lines (896 loc) · 37.1 KB

⚡ HYPER-DX: WHY KRUBOT IS BORN UNMATCHED ⚡

Prepare to unlearn everything you know about bot development. Below are selected examples from the KrubiK grimoire that best represent what “Hyper-DX” actually means in practice.

Here are just a few of the 101 artifacts [NoxiousSamples] hidden within KrubiK's core.

Words are cheap. Let the code prove the architecture.

1) Reverse Routing Instead of Callback Fragility

Hardcoded callback strings break silently over time.
KrubiK lets you name routes and resolve them safely.

<?php

// 📂 File: app/Nexus/ECommerce/ProductNexus.php

namespace App\Nexus\ECommerce;

use KrubiK\Attributes\Name;
use KrubiK\Attributes\OnCommand;
use KrubiK\Keyboard\Keyboard;
use KrubiK\Keyboard\PowerButton;
use KrubiK\Krubot;

class ProductNexus
{
    #[Name('shop.item.view')]
    #[OnCommand('item {sku}')]
    public function viewProduct(Krubot $bot, string $sku): int
    {
        // The SKU is injected directly from the command pattern.
        $bot->reply("📦 Fetching SKU: {$sku}...")->send();
        return strlen($sku); // return some value to test `go()` returnability
    }
    // Now This Function has a Name(), so It's Callable from Any Nexuses In This Application.

    #[OnCommand('catalog')]
    public function showCatalog(Krubot $bot): void
    {

        // Resolve the route dynamically instead of hardcoding callback_data.
        $cmdMacbookString = $bot->resolvePattern('shop.item.view', [
            'sku' => 'MAC-M3',
        ]); // => /item MAC-M3

        // The "Fluent Symphony"
        $bot
            ->reply("🛍️ Select product:")
            ->attachKeyboard(fn (Keyboard $kb) => $kb
                ->row(function($row) {
                    $row->simple("start_game", "🎮 Enter Arena")
                        ->simple("support_desk", "🆘 Support");
                    $row->add(
                        PowerButton::simple('btn1', '💻 Mac')->action($cmdMacbookString)
                    );
                })
            )
        ->send();
    }

    #[OnCommand('random')]
    public function showRandomProduct(Krubot $bot): void
    {
        $yourSKU = findRandomSKU(); // eg: 'MAC-M3'

        // Executes subroute dynamically instead of hardcoding callback_data.

        $bot->reply("We've Found a Good Product For You")->send();
        // write any code here, you are in `/random` area

        // after $bot->go() context changed to adpot Krubot to target method.
        $skuLength = $bot->go('shop.item.view', [
            'sku' => $yourSKU,
        ]);
        // GOSUB done.
        // we back here! (unless code died or crashed in `shop.item.view`())

        AmethystMatrix::debug('viewProduct() run status => ' . (
            $skuLength === strlen($yourSKU) ? 'Done' : 'Failed'
        ), [$yourSKU]);

        // write any code here, you are in `/random` area Again
        $bot->reply("Hope You've Liked that Product")->send();
    }
}

Why this matters: route refactors stop breaking UI wiring.

Route Groups

<?php

// 📂 File: app/Providers/RouteServiceProvider.php

namespace App\Providers;

use App\Nexus\Admin\ManageUsersNexus;
use Illuminate\Support\ServiceProvider;
use KrubiK\Krubot;

class RouteServiceProvider extends ServiceProvider
{
    public function boot(Krubot $bot): void
    {
        // Group admin commands under a shared prefix and middleware stack.
        $bot->group([
            'prefix' => 'sudo_',
            'middleware' => ['auth', 'god_mode'], // define/map middleware aliases via config.
        ], function (Krubot $router) {
             // Acts On `/sudo_ban {.+}`
            $router->onCommand('ban {user_id}', [ManageUsersNexus::class, 'executeBan']);

            // Acts On `/sudo_nuke`
            $router->onCommand('nuke', [ManageUsersNexus::class, 'systemWipe']);

            // Acts On `sudo_hello s!ystem`
            $router->onText('hello s!ystem', [ManageUsersNexus::class, 'systemWipe']);
        });
    }
}

Deep Link Portal — route directly from a referral universe

Instead of manually decoding /start payloads and scattering logic across handlers, capture deep-link parameters and move straight into a domain flow.

<?php

// File: app/Nexus/Marketing/ReferralNexus.php

namespace App\Nexus\Marketing;

use App\Conversations\OnboardingConversation;
use KrubiK\Attributes\OnRegEx;
use KrubiK\Krubot;

class ReferralNexus
{
    #[OnRegEx('/^\/start ref_(\d+)$/')]
    public function handleDeepLink(Krubot $bot, array $matches): void
    {
        // Extract the referrer ID directly from the deep-link payload.
        $referrerId = $matches[1];

        $bot->reply("🎉 Invited by User #{$referrerId}!")->send();

        // Start a conversation with injected domain context.
        $bot->startConversation(new OnboardingConversation($referrerId));
    }
}

Why it matters:
Deep links become first-class routing inputs, not awkward transport leftovers.


2) The Bootstrap "12" Grid System in Bots
"Pro Gaming Dashboard" Scenario

Use-Case: A comprehensive account management panel tailored for gamers.

This interface requires responsive buttons of varying dimensions (e.g., Primary Call-to-Actions like "Top-Up" and "Gems" demand larger real estate, whereas "Server Selection" buttons can be compactly aligned).

Under the Hood: Harnessing the underlying col(1) through col(6) grid architecture to dynamically distribute row space
(It's Maximum Row Capacity is 6 Units).

namespace KrubiK\Nexus;

use KrubiK\Keyboard\Keyboard;
use KrubiK\Keyboard\PowerButton;
use KrubiK\Krubot;
use KrubiK\Attributes\OnCommand;
use KrubiK\Attributes\Action;
use App\Models\Product; // Laravel Model reference

class GamePanelNexus
{
    #[OnCommand('panel')]
    public function showDashboard(Krubot $bot): void
    {
        $bot->reply("🎮 **Commander, Welcome back!**\nAccount Status: Active ✅")
            ->attachKeyboard(function($kb) {
                
                // 🟡 Row 1: Primary Action Buttons (3 columns each = 50% width distribution)
                $kb->row(fn($row) => $row
                    ->add(PowerButton::make('💎 Buy Gems')->col(3)->action('buy_gem'))
                    ->add(PowerButton::make('💰 Top-up Wallet')->col(3)->action('wallet'))
                );

                // 🔵 Row 2: Server Selection Matrix
                // This demonstrates the raw power of the col() method; strictly aligning 3 elements side-by-side (2 columns each = 33.33% viewport width).
                $kb->row(fn($row) => $row
                    ->add(PowerButton::simple('srv_1', 'IR 🇮🇷')->col(2))
                    ->add(PowerButton::simple('srv_2', 'US 🇺🇸')->col(2))
                    ->add(PowerButton::simple('srv_3', 'EU 🇪🇺')->col(2))
                );

                // 🔴 Row 3: Full-width Support / Fallback Button (6 columns = 100% viewport width)
                $kb->row(fn($row) => $row
                    ->add(PowerButton::make('🆘 Online Support')->col(6)->action('support'))
                );
            })
            ->send();
    }

    #[Action('buy_gem')]
    public function buy_gem(Krubot $bot): void 
    {
        // Business logic for purchasing gems...
    }
    
    #[Action('wallet')]
    public function show_wallet(Krubot $bot): void 
    {
        // Business logic for wallet top-up...
    }
}

📊 Payload Dispatched to the Rubika Server in showDashboard()

The underlying engine compiles the aforementioned chain into the following optimal JSON payload for the reply_markup parameter:

{
  "inline_keyboard": [
    [
      { "text": "💎 Buy Gems", "callback_data": "buy_gem", "width": 0.5 },
      { "text": "💰 Top-up Wallet", "callback_data": "wallet", "width": 0.5 }
    ],
    [
      { "text": "EU 🇪🇺", "callback_data": "srv_1", "width": 0.33333333333333 },
      { "text": "IR 🇮🇷", "callback_data": "srv_2", "width": 0.33333333333333 },
      { "text": "US 🇺🇸", "callback_data": "srv_3", "width": 0.33333333333333 }
    ],
    [
      { "text": "🆘 Online Support", "callback_data": "support", "width": 1.0 }
    ]
  ]
}

Chunk-Oriented Commerce UI — convert live product collections into native keyboard grids

This is where KrubiK turns database results into ready-to-render layout without forcing developers piece the grid together by hand.

class GamePanelNexus
{
    #[OnCommand('menu')]
    public function showGamesMenu(Krubot $bot): void
    {
        // 1. Fetching VIP products from the database.
        // Retrieving only the necessary columns ensures absolute memory optimization.
        $products = Product::query()
            ->where('is_vip', true)
            ->get(['id', 'name', 'price']); // Returns an Eloquent Collection
        
        // 2. Rapid Transformation via Laravel Collections.
        // Mapping the Products directly into the PowerButton actionable architecture.
        $buttons = $products->map(function (Product $product) {
            $label = "{$product->name} (💰 {$product->price}T)";
            return PowerButton::make($label)->action('order', ['id' => $product->id]);
        })->toArray();

        // 3. The Magic of Chunking: Automatically grouping elements into a pristine matrix.
        // Changing chunk(2) to chunk(3) effortlessly switches the grid layout to a 3-column UI.
        $bot->reply("📋 Today's Exclusive VIP Games:")
            ->keyboard(
                Keyboard::make()
                    ->buttons($buttons)
                    ->chunk(2) // <--- Ultimate DX: Zero manual row calculation!
            )
            ->send();
    }

    #[Action('order')]
    public function orderGame(Krubot $bot, int $id): void 
    {
        // Business logic for $product Order
    }
}

Why this is Hyper-DX:
You shape the data once; KrubiK deterministically shapes the layout.
No manual slicing, no UI formality, no grid bookkeeping.


3) Native Forms Instead of State-Machine Suffering

Collecting structured user input should not require a small tragedy
But This is where ordinary bot libraries starts becoming painful n cognitive loops...
KrubiK turns it back into design.

<?php

// 📂 File: app/Nexus/Features/JobNexus.php

namespace App\Nexus\Features;

use KrubiK\Attributes\OnCommand;
use KrubiK\Keyboard\PowerButton;
use KrubiK\Krubot;

use App\Rules\NationalCodeValidator;

class JobNexus
{
    #[OnCommand('apply')]
    public function startApplication(Krubot $bot): void
    {
        // Build a multi-step form without hand-writing state transitions.
        $bot->form('job_app_form')
            ->field('fullname', '👤 Enter your full name:')
                ->rules('required|min:3')
            ->field('birth_year', PowerButton::calendar('b_year', '📅 Select Birth Year', PowerButton::JalaliCalendar))
            ->field('mobile', '📱 Enter mobile:')
                ->rules('required|regex:/^09\d{9}$/')
            ->field('n_code', 'Enter your 10-digit National ID:')
                ->rules(['required', 'digits:10', new NationalCodeValidator()]) // DX: Object-based validation, merged with other modes
            ->then(function (array $data, Krubot $bot) {
                $bot->reply("🎉 Application received, {$data['fullname']}!")->send();
            })
        ->run();
    }
}

// Custom Laravel Rule Object Example
use Illuminate\Contracts\Validation\Rule;
class NationalCodeValidator implements Rule
{
    // #Rule Logic Place
    public function passes($attribute, $value): bool
    {
        if (!preg_match('/^\d{10}$/', (string)$value) || preg_match('/^(\d)\1{9}$/', (string)$value))
            return false;

        for ($sum = 0, $i = 0; $i < 9; $i++)
            $sum += (int)$value[$i] * (10 - $i);

        $remainder = $sum % 11;
        return (int)$value[9] === ($remainder < 2 ? $remainder : 11 - $remainder);
    }

    // #Rule Error Place
    public function message(): string
    {
        return 'The provided National ID is not valid.';
    }
}

And when you want richer native UI:

<?php

// 📂 File: app/Forms/CarRentalForm.php

namespace App\Forms;

use KrubiK\Conversations\Form;
use KrubiK\Keyboard\PowerButton;

class CarRentalForm extends Form
{
    protected function setup(): void
    {
        // Give the form a stable identity for persistence and recovery.
        $this->setName('premium_car_rental');

        // Native selection UI.
        $this->field('car_type', PowerButton::selection('c_type', '🚗 Select Class', [
            ['id' => 'suv', 'text' => 'SUV'],
            ['id' => 'sedan', 'text' => 'Luxury Sedan'],
        ], multi: false, columns: 2));

        // Native number picker.
        $this->field('days', PowerButton::numberPicker('days', '⏳ Rental Days', min: 1, max: 30));

        // Native calendar.
        $this->field('start_date', PowerButton::calendar('cal', '📅 Pickup Date', PowerButton::GregorianCalendar));
    }

    protected function submit(array $data): void
    {
        $this->bot->reply("✅ Booking confirmed for {$data['start_date']}")->send();
    }
}

// 📂 File: app/Nexus/RentalNexus.php
class RentalNexus
{
    #[OnText('Rent A Car')]
    public function startRentForm(Krubot $bot): void
    {
        $form = new CarRentalForm();
        $form->setContext($bot);
        $form->run();
    }
}

Why this matters: complex data collection feels native, not improvised.


4) Multi-Verse Messaging Instead of Telegram-Only Thinking

KrubiK was not designed with a one-platform domination imagination.

<?php

// 📂 File: app/Nexus/Admin/WarlordNexus.php

namespace App\Nexus\Admin;

use KrubiK\Attributes\OnCommand;
use KrubiK\Helpers\AmethystMatrix;
use KrubiK\Krubot;

class WarlordNexus
{
    #[OnCommand('nuke_all')]
    public function launchGlobalStrike(Krubot $bot): void
    {
        // 💎 LEGION COMMAND:
        // Instead of hardcoding via(['tg', 'instagram', 'x']), 
        // we use the pre-defined squads from config/krubot.php
        
        // This targets 'social_platforms' defined in config.
        $bot->legion('social_platforms')
            ->say("🔥 Summer sale has started! Link in bio.");

        // This targets 'internal_messengers' (bale, eitaa, rubika).
        $bot->legion('internal_messengers')
            ->say("🎁 کد تخفیف اختصاصی برای کاربران ایرانی: IRAN2026");


        // Assemble multiple messenger drivers into one council.
        $council = $bot->assembleCouncil(['tg', 'r', 'bale']);

        $report = $council->broadcast('sendMessage', [
            'chat_id' => config('marketing.global_channel'),
            'text'    => "🔥 Core upgrade is LIVE!",
        ])->getReport();

        if ($council->hasFailures()) {
            $failed = implode(', ', $council->getFailedAliases());
            $bot->reply("⚠️ Partial failure on nodes: {$failed}")->send();
            return;
        }

        AmethystMatrix::gaze($report, 'Global Broadcast Report');
        // Original Famous dd() but send to logfile.


        // Scoped Driver Switching        
        $bot->reply("🔄 Initiating backup...")->send();
        // Switch to Telegram only inside this closure.

        $bot->via('tg', function (Krubot $telegramBot) {
            $telegramBot->to(config('admin_tg'), "📥 Secure backup received.");
        });
        // The original driver context is restored after the closure.
        $bot->reply("✅ Backup transmitted.")->send();
        
        // OR instead of via, run this line from anywhere on your laravel app::
        warlord('tg')->to(config('admin_tg'), "📥 Secure Inline backup received.");
        // Direct-Invocation AutoWakesUp Krubot, If he hasn't woken up yet in your app.
        // warlord() === krubot()

        $bot->reply("✅ Message delivered across all dimensions.")->send();
    }
}

Why this matters: your Business Logic should not be imprisoned inside one messenger.


5) Cross-Verse Memory — read state from another messenger

This is where KrubiK becomes truly unusual.

<?php

// File: app/Nexus/RPG/SyncNexus.php

namespace App\Nexus\RPG;

use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;

class SyncNexus
{
    #[OnCommand('sync_xp')]
    public function syncExperience(Krubot $bot): void
    {
        // Keep a handle to the current platform's user storage.
        $rubikaStore = $bot->userStorage();

        // Temporarily point state resolution to Telegram.
        $bot->setWorkingVerse('tg'); // hate hard-coding ? `Platform::Telegram()` || `Platform::TG()` also filled from config.

        $tgXP = $bot->userStorage()->get('xp', 0);

        // Return to the current platform context.
        $bot->setWorkingVerse(null);

        // again:: $rubikaStore === $bot->userStorage();

        // Mirror Telegram progress into the active platform's storage.
        $rubikaStore->put('xp', $tgXP);

        $bot->reply("✅ Cross-Verse Sync Complete! EXP: {$tgXP}")->send();
    }
}

Why this is Hyper-DX:
Most frameworks barely abstract one platform well.
KrubiK lets state become multi-reality aware.


6) Storage, State and Memory

KrubiK gives you persistence primitives that match how bots actually work.

User Storage and Global Storage

<?php

// 📂 File: app/Nexus/Features/SettingsNexus.php

namespace App\Nexus\Features;

use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;

class SettingsNexus
{
    #[OnCommand('theme_dark')]
    public function setDark(Krubot $bot): void
    {
        // User storage is isolated to the current user.
        $bot->userStorage()->put('theme', 'dark');

        $bot->reply("🌙 UI is now Dark.")->send();
    }

    #[OnCommand('status')]
    public function checkStatus(Krubot $bot): void
    {
        // Read a per-user preference.
        $theme = $bot->userStorage()->get('theme', 'light');

        // Read and update global storage shared by the whole bot.
        $hits = $bot->globalStorage()->get('system_hits', 0) + 1;

        $bot->globalStorage()->put('system_hits', $hits);

        $bot->reply("Theme: {$theme}\nTotal Hits: {$hits}")->send();
    }
}

Contextual Storage

<?php

// 📂 File: app/Nexus/Moderation/WarnNexus.php

namespace App\Nexus\Moderation;

use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;

class WarnNexus
{
    #[OnCommand('strike')]
    public function warnUser(Krubot $bot): void
    {
        if (! $bot->isReply()) {
            return;
        }

        // Contextual storage is scoped by user_id and chat_id at the same time.
        $context = $bot->contextStorage();

        $strikes = $context->get('strikes', 0) + 1;

        if ($strikes >= 3) {
            $bot->banChatMember($bot->chatId(), $bot->getReplySenderId())->send();

            // Reset the strike history for this specific realm.
            $context->forget('strikes');

            $bot->reply("🔨 Entity removed from this realm.")->send();

            // Update Chat Stats
            $chat_data = $bot->chatStorage();
            $chat_data->put('strike_fireds',
                $chat_data->get('strike_fireds', 0) + 1
            );

            return;
        }

        $context->put('strikes', $strikes);

        $bot->reply("⚠️ Warning #{$strikes}/3 issued.")->send();
    }
}

7) Telemetry That Respects Runtime Reality

Traditional dd()-style debugging is destructive in bots and breaks async webhooks.

KrubiK introduces Amethyst Matrix so you can inspect, trace, or emit telepathic emergency wails directly to your BotAdmins, all without killing your flow:

<?php
// 📂 File: app/Nexus/Dev/InspectionNexus.php

namespace App\Nexus\Dev;

use KrubiK\Attributes\OnCommand;
use KrubiK\Helpers\AmethystMatrix;
use KrubiK\Krubot;

class InspectionNexus
{
    #[OnCommand('inspect_payload')]
    public function inspect(Krubot $bot): void
    {
        $payload = $bot->getUpdate();
        // Inspect complex payloads without killing or breaking the response lifecycle.
        AmethystMatrix::gaze($payload, 'Incoming Webhook Payload');

        $bot->reply("✅ Payload inspected by the Oracle.")->send();
    }
}

And when the system suffers a critical failure:

<?php
// 📂 File: app/Nexus/Finance/CoreBankingNexus.php

namespace App\Nexus\Finance;

use KrubiK\Attributes\OnCommand;
use KrubiK\Helpers\AmethystMatrix;
use KrubiK\Krubot;

class CoreBankingNexus
{
    #[OnCommand('transfer')]
    public function transferMoney(Krubot $bot): void
    {
        try {
            // Replace with real production logic.
            throw new \RuntimeException("DB node unavailable.");
        } catch (\Throwable $exception) {

            // 🚨✨️🚨✨️🚨
            // Crash Telepathy: Traces error, Log it and pings the Admins natively
            AmethystMatrix::wail('CORE BANKING FAILURE', $exception);

            $bot->reply("⚠️ Banking grid anomaly. Engineers notified.")->send();
        }
    }
}

8) Amethyst Vault — temporary memory with self-destruct behavior

For OTPs, one-time flows, and transient secrets:

<?php

// File: app/Nexus/Auth/FastLoginNexus.php

namespace App\Nexus\Auth;

use KrubiK\Attributes\OnCommand;
use KrubiK\Helpers\AmethystMatrix;
use KrubiK\Krubot;

class FastLoginNexus
{
    #[OnCommand('get_code')]
    public function generateFlashCode(Krubot $bot): void
    {
        // Generate and store an OTP with a 60-second lifetime.
        $secret = rand(1000, 9999);

        AmethystMatrix::vault("otp_{$bot->userId()}", $secret, 60);

        $bot->reply("🔑 OTP: {$secret}\nValid for 60 seconds.")->send();
    }

    #[OnCommand('verify {code}')]
    public function verifyCode(Krubot $bot, string $code): void
    {
        // Pull the OTP atomically: fetch it and delete it in one move.
        $savedCode = AmethystMatrix::pullData("otp_{$bot->userId()}");

        if ((string) $savedCode === $code) {
            $bot->reply("🔓 Access Granted.")->send();
            return;
        }

        $bot->reply("⛔️ Code expired or invalid.")->send();
    }
}

Why this is Hyper-DX:
You get ephemeral, purpose-built memory semantics without hand-rolling cache workflows everywhere.

AmethystMatrix
AmethystMatrix - Krubot's Assistant (KrubiK Oracle)
{ KrubiK Tracing Module }

9) Async-Like Fluent Outcomes

KrubiK allows response outcomes to be chained in a clean, espromise-like style.

<?php

namespace App\Nexus;

use KrubiK\Krubot;
use App\Models\User;
use Throwable;
use KrubiK\WarLording\CommandOutcomeShifter;
use KrubiK\Helpers\AmethystMatrix;

class PromiserNexus
{
    /**
     * Executes the ultimate Deep Pipeline utilizing then, onError, finally, and throw.
     * Engineered with ECMA2026 Philosophy running on PHP 8.2 & Laravel 12.
    */
    #[OnCommand('pipeline')]
    public function executeDeepPipeline(Krubot $bot): void
    {
        // ⚡️ INITIATING THE ES-PROMISE PARADIGM
        // Wrapping the universe in our localized reality field.
        $bot->EnableESPromiseMode();
        // "ES-PROMISE CODING PARADIGM" can be toggled on the fly, bot by bot ~!~

        $user = User::findByRUID($bot->userId());
        $msg = $bot->thisMessage();

        try {
        // try/catch block needed yet ?! not actually, but it's needed only for ->throw()

        // =====================================================================
            // SCENARIO: The Quantum Ascension (Multi-Stage Chain of Destiny)
            // Flow: Send Init Msg -> Lock DB -> Generate Quantum Key -> Update DB -> Finalize
            // =====================================================================
            
            $bot->reply("🌌 Initiating the Quantum Ascension Sequence...")
                ->send() // 💥 THE CRITICAL LINK! Pulls the ES trigger.
                
                // STEP 1: Process the Aura via Laravel DI (Dependency Injection)
                ->then(function ($initialReply, UniversalAuraManager $auraManager) use ($bot, $user) {
                    // Because of App::call() in CommandOutcomeShifter, we injected $auraManager seamlessly!
                    $auraLevel = $auraManager->calculateFrequency($user->guid);
                    
                    if ($auraLevel < 100) {
                        // Throwing an exception here triggers the onError() down the chain.
                        throw new \Exception("Insufficient spiritual frequency. Found: {$auraLevel}Hz");
                    }

                    // Proceed to send the verification challenge
                    return $bot->sendMessage($user->chat_id, "Frequency verified. Generating singularity token...");

                    // This next call also MUST be terminated with ->send(), cause send() delegates to the driver via CommandOutcomeShifter::execute() in __call
                    // but sendMessage do it by himself
                })

                // STEP 2: Database Transaction & Multi-driver Broadcast
                ->then(function ($msgResult, QuantumLedgerService $ledger) use ($bot, $user) {
                    // We lock the row and update using modern Laravel logic
                    $token = DB::transaction(fn() => $ledger->mintAscensionToken($user));
                    
                    // Cross-driver strike: Notify the Supreme Warlord (Admin) via Telegram
                    $bot->via('tg')->sendMessage(
                        env('WARLORD_HQ_ID'),
                        "⚡️ Singularity Token Minted for Node: {$user->guid}"
                    );

                    // Return the final successful payload to pass forward
                    return $bot->reply("✅ Ascension Complete. Your Token: " . $token->hash);
                })

                // 🛡️ THE CONTINGENCY PROTOCOL (Handling Failure)
                // If ANY exception was thrown in execute() or ANY then(), execution jumps here.
                ->catch(function (Throwable $e, UniversalAuraManager $auraManager) use ($bot, $user) {
                    // We log the exact failure
                    AmethystMatrix::error("Ascension Failed for {$user->guid}: " . $e->getMessage());

                    // We attempt a graceful fallback notification to the user
                    $bot->reply("⚠️ The Matrix rejected the sequence: " . $e->getMessage() . "\nMay God illuminate your next attempt.");
                    
                    // We can also trigger compensatory actions (Saga Pattern) via injected services
                    $auraManager->resetFrequencyCooldown($user->guid);
                })

                // ⚖️ THE FINAL JUDGEMENT (Cleanup)
                // Runs regardless of success or failure. Perfect for releasing locks.
                ->finally(function (CommandOutcomeShifter $outcome) use ($user) {
                    // Inspecting the outcome state using the passed instance
                    $state = $outcome->isSuccessful() ? 'GLORIOUS VICTORY' : 'DEFEAT';
                    AmethystMatrix::debug("Pipeline Finalized for {$user->id} with state: {$state}");

                    // e.g., Cache::forget("ascension_lock_{$user->id}");
                })

                // 💥 UNLEASH THE FATE (Terminal Operator)
                // Breaks the silent chain. If the state is a failure, it re-throws the exception 
                // so Laravel's global Exception Handler (or the outer try-catch) can process it.
                // If successful, it returns the final result.
                ->throw(); 

        } catch (Throwable $e) {
            // Because we used ->throw() at the end of the chain, the exception bubbles up here.
            // This is the absolute final safety net for the Warlord.
            AmethystMatrix::critical("Systemic Collapse in Ascension Pipeline: " . $e->getMessage());
        }

        // 🛑 HALTING THE ES-PROMISE PARADIGM
        // Restoring the universal timeline to its synchronous state.
        $bot->DisableESPromiseMode();
    }
}

10) Attribute-Based Laravel Validation

Bot conversations are usually where clean code goes to die.
KrubiK keeps that alive.

<?php

// 📂 File: app/Conversations/SecuritySetupConversation.php

namespace App\Conversations;

use KrubiK\Attributes\Rule;
use KrubiK\Conversations\Answer;
use KrubiK\Conversations\Conversation;

class SecuritySetupConversation extends Conversation
{
    public function start(): void
    {
        $this->ask("🔑 Set your 4-digit PIN:", 'savePin');
    }

    #[Rule('required|numeric|digits:4')]
    public function savePin(Answer $answer): void
    {
        // The value has already passed Laravel validation.
        $pin = $answer->getValue();

        $this->bot->reply("✅ PIN securely saved: {$pin}")->send();

        $this->end();
    }
}

Inline Validation

<?php

// 📂 File: app/Conversations/VaultConversation.php

namespace App\Conversations;

use KrubiK\Conversations\Answer;
use KrubiK\Conversations\Conversation;

class VaultConversation extends Conversation
{
    public function start(): void
    {
        // The validator closure returns true or an error message.
        $this->ask("🔐 Master Password:", 'openVault', function (Answer $answer) {
            return $answer->getText() === 'DOOM_2026'
                ? true
                : '⛔ Access Denied.';
        });
    }

    public function openVault(Answer $answer): void
    {
        // This method is called only after the answer passes validation.
        $this->bot->reply("🔓 Welcome to the Core.")->send();

        $this->end();
    }
}

11) Divine Time Weaver — schedule future messages like a first-class feature

Not a side utility.
A native part of the experience.

<?php

// File: app/Nexus/Features/SubscribeNexus.php

namespace App\Nexus\Features;

use Carbon\Carbon;
use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;
use KrubiK\DivineMessageSender\Models\DivineMessage;

class SubscribeNexus
{
    #[OnCommand('subscribe')]
    public function optIn(Krubot $bot): void
    {
        $bot->reply("✅ Subscribed.")->send();

        // Schedule a message for a precise future time without hand-built cron logic.
        DivineMessage::schedule($bot->userId())
            ->content("🌸 Reminder: Subscription expires tomorrow.")
            ->at(Carbon::now()->addDays(29))
            ->save();
    }
}

Why this is Hyper-DX:
This takes a common operational need and makes it feel native instead of infrastructural.


12) Smart Grid UI

<?php

// 📂 File: app/Nexus/UI/DashboardNexus.php

namespace App\Nexus\UI;

use KrubiK\Attributes\OnCommand;
use KrubiK\Keyboard\Keyboard;
use KrubiK\Krubot;

class DashboardNexus
{
    #[OnCommand('app')]
    public function render(Krubot $bot): void
    {
        // Use width() instead of col() for fine-grained dimension control.

        // Compose a responsive keyboard using width ratios.
        $ui = Keyboard::make()->rightToLeft()
            ->button('🔥 Sale')->action('promo')->width(1.0)
            ->button('👕 Men')->action('men')->width(0.5)
            ->button('👗 Women')->action('women')->width(0.5)
            ->button('🥇 VIP')->action('vip')->width(0.33)
            ->button('🎁 Gift')->action('gift')->width(0.33)
            ->button('⚙️ Panel')->action('panel')->width(0.34);

        $bot->reply("📱 Smart Dashboard:")
            ->attachKeyboard($ui)
            ->send();
    }
}

13) Driver Escape Hatches for Senior-Level Control

Abstraction is powerful.
But good abstraction also -must- know: when to get out of the way.

<?php

// 📂 File: app/Nexus/Media/AgentNexus.php

namespace App\Nexus\Media;

use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;
use KrubiK\WarLording\PrimeAgent;

class AgentNexus
{
    #[OnCommand('test_prime')]
    public function createPack(Krubot $bot): void
    {
        // Engage the native Telegram SDK when platform-specific power is needed;
        // `Telegram\Bot\Api`-like instance will returned, as irazasyed's chosen best for TG Core.
        $tgAgent = PrimeAgent::engage(target: 'tg', legalMode: true, warlord: $bot);

        $tgAgent('sendMessage', ['text' => 'Boom!', 'chat_id' =>, User::getTelChatId($bot->user())]); // Let's Redefine The D.X.

        // Or summon a PrimeAgent through her warlord
        $strMediaType = $bot->prime('r', false)('detectFileType', ['mime_type' => 'application/msword']);
        // to Call a Private Function on our Rubika Core ;)

        /**
         * Injecting a custom mutation into the PrimeAgent at runtime (e.g., in AppServiceProvider).
        */
        if(!PrimeAgent::hasMacro('broadcastToAll'))
            PrimeAgent::macro('broadcastToAll', function ($message) {
                // Note: $this refers to the active PrimeAgent instance
                return $this->driver->sendToMass($message);
            });

        // Macro added After PrimeAgent construct ? Who cares...
        // Usage in nexus:
        $tgAgent->broadcastToAll('Hello Multiverse!');

        try {
            $tgAgent->createNewStickerSet([
                'user_id' => $bot->userId(),
                'name'    => 'elite_pack_by_bot',
                'title'   => 'Elite Matrix',
                'emojis'  => ['💀'],
            ]);

            $bot->reply("✅ Native Telegram pack generated.")->send();

            // Or Cheat the world via::
            $taskId = $tgAgent->async('createNewStickerSet', [
                'user_id' => $bot->userId(),
                'name'    => 'elite_pack_by_bot',
                'title'   => 'Elite Matrix',
                'emojis'  => ['💀'],
            ]);
            // to Perfome an Async / Non-blocking Request to Driver

            // Get Result with await(), But you should not do do this here cause it makes your code actualy blocking.
            // Not so important, cause most of our subjects does not need platform returned result
            
            // just put await() as long as later you can, so maybe the job done.
            $createStickerSetResult = $tgAgent->await($taskId);

            // Define Custom Funcs to Async-Run Easily
            PrimeAgent::macro('buildHeavyReport', function (int $userId, string $range = '30d'): array {
                // Simulate a relatively heavy and long-running operation.
                sleep(4);

                return [
                    'report_id' => (string) Str::uuid(),
                    'user_id'   => $userId,
                    'range'     => $range,
                    'rows'      => 0,
                    'file'      => "reports/{$userId}-{$range}.zip",
                    'status'    => 'ready',
                ];
            });
            $taskId = $tgAgent->async('buildHeavyReport', [
                $bot->userId(),
                '90d',
            ]);
            $bot->reply("🚀 Task launched: {$taskId}")->send(); // Reply in Rubika in the sametime!

            // with awaitWithTimeout() set max timeout / waiting-time for this func
            $export = $tgAgent->awaitWithTimeout($taskId, 7000);
            if($export !== null) {
                $bot->reply("{$export['file']} | {$export['rows']} rows")->send();
            }
            
        } catch (\Throwable $exception) {
            // Avoid exposing raw exception details to end-user in production.
            // Log the real reason for engineering diagnostics.
            report($e);

            $bot->reply("❌ Native platform constraint triggered.")->send();
        }
    }

    #[OnCommand('resilience_test')]
    public function krubot_resilience(Krubot $bot): void
    {
        $serviceResult =
            $bot
                // Let the resilientRun() resolve it's operational params via `Laravel IoC Container`, for-example consider `CosmicService` is binded/registered somewhere in your application.
                ->resilientIoC()

                // disables auto-amethyst in resilientRun() +&> `resilientLog()` === `resilientLog(true)`
                ->resilientLog(false)

                // safe executes a callable, returns value of `def` if there was any error/expection when running this callable.
                ->resilientRun(
                    op: fn(CosmicService $service, Krubot $bot) => $service->synchronizeAndReturnData($bot),
                    def: -4
                );

        if($serviceResult === -4) {
            $bot->reply("CosmicService denied to response... ❌")->send();
            return;
        }

        // it seemes `synchronizeAndReturnData()` returned it's correct result and it doesn't thrown any exception
        // use `$serviceResult` super-safely.

    }
}

Why this matters: KrubiK gives you abstraction without trapping you inside it.


14) Hot Discovery Without Rebooting the World

Dynamic integration is a serious operational advantage.

<?php

// 📂 File: app/Nexus/Admin/DevNexus.php

namespace App\Nexus\Admin;

use KrubiK\Attributes\OnCommand;
use KrubiK\Krubot;

class DevNexus
{
    #[OnCommand('sys:reload')]
    public function reloadSystem(Krubot $bot): void
    {
        // Scan a directory and integrate new Nexus modules at runtime.
        $count = $bot->discoverAndIntegrateNexuses(app_path('Nexus/Plugins'));

        $bot->reply("{$count} new routing modules integrated seamlessly.")->send();
    }
}

Why this matters: deployment and extension become far more fluid.