Skip to content

Flow & Interactive Screen Ecosystem ​

Multi-step dialogues and interactive bot screens (such as user onboarding wizards, settings panels, catalogs, e-commerce checkouts, surveys, and support ticket flows) are notoriously difficult to maintain when managed through scattered database flags, nested if/else statements, or naive polling handlers.

tueen/telegram provides a unified, two-tier architecture for conversational and interactive bot applications:

  1. Flow: A linear, step-by-step state machine designed for text questionnaires, registration wizards, and multi-prompt dialogues.
  2. InteractiveFlow: A screen-oriented, component-based engine featuring in-place message editing (zero-flicker UI updates), comprehensive lifecycle hooks, hierarchical navigation stacks (push/pop), and declarative action routing (#[Action]).

🏛️ Two-Tier Architecture Comparison ​

FeatureStandard FlowInteractiveFlow
Primary ParadigmLinear Step-by-StepScreen & Menu Component
Message UpdatesSends new messages on each stepEdits existing message in-place (editMessageText)
Flicker-Free UINo (new messages each turn)Yes (zero-flicker in-place transitions)
Button HandlingManual step matchingDeclarative #[Action('pattern')] attributes
Navigation BarCustom reply buttonsBuilt-in language-neutral buttons (🔙 Back, 🏠 Home)
Navigation ModelLinear History StackHierarchical Stack (push child flow / pop with results)
Lifecycle HooksonExitonCreate, onStart, onResume, onPause, beforeRender, afterRender, onUnhandled
Global InterruptionChecked via exitCommandsIntercepted via canInterrupt($update)

🧭 Flow Documentation Sitemap ​

Explore each section of the Flow ecosystem in detail:


⚡ Quickstart: Interactive Menu ​

php
use Tueen\Telegram\Flow\InteractiveFlow;
use Tueen\Telegram\Flow\Screen;
use Tueen\Telegram\Flow\Attributes\Action;
use Tueen\Telegram\Keyboards\InlineKeyboard;

class DashboardFlow extends InteractiveFlow
{
    public function render(): Screen
    {
        $status = $this->get('status', 'Active');

        return Screen::make("📊 User Dashboard\n\nCurrent Status: {$status}")
            ->inline(fn (InlineKeyboard $k) => $k
                ->action('Toggle Status', 'toggle')
                ->action('Open Settings', 'settings')
            )
            ->withNavigation(back: true, home: true);
    }

    #[Action('toggle')]
    public function toggleStatus(): void
    {
        $next = $this->get('status', 'Active') === 'Active' ? 'Paused' : 'Active';
        $this->set('status', $next);
        $this->refresh();
    }

    #[Action('settings')]
    public function openSettings(): void
    {
        $this->push(SettingsFlow::class);
    }
}

Released under the MIT License.