Bot Development
Build handlers, middleware, and runtime flows using NxCreator's Telegraf-based execution model.
NxCreator follows Telegraf's event-driven model, but removes the boilerplate around runtime setup, connection handling, and deployment.
How bot development works
Everything starts with one simple idea: your code describes what the bot should do when something happens. A user sends /start? Run this function. A user sends a message? Run that one. This pattern is called event-driven programming, and it is the foundation of every bot you will build here.
You do not manage webhook plumbing, polling lifecycle, or server process orchestration. The platform handles the runtime so your code can stay focused on bot behavior.
Handler model
Use the pre-initialized bot object to register handlers such as bot.command(), bot.hears(), bot.on(), and bot.action(). These behave like their Telegraf equivalents for the common Telegram update types.
For unmatched text input, a trailing bot.on('text') can act as a global fallback. Place it late in your code so it does not preempt more specific text handlers.
Middleware
Use bot.use() for cross-cutting logic that should run before the rest of your handlers. Common examples include ban checks, logging, rate-limiting, and request shaping.
Put middleware near the top of your bot logic so it wraps the handlers that follow.
Error handling
Use bot.catch() as the global error boundary for your bot code. Define your commands, scenes, and middleware first, then register the catch handler near the end of setup.
bot.on('text') fallback or misplaced middleware can change the behavior of everything beneath it. Order matters.