NxCreateDocs

The Bot Object

The bot global is a pre-initialized Telegraf instance. Never import or recreate it.

Available methods

bot.command(trigger, handler)   // responds to /commands
bot.hears(pattern, handler)     // text match — string or RegExp
bot.on(event, handler)          // any Telegram update type
bot.action(data, handler)       // inline keyboard callbacks

Context object

Every handler receives a Telegraf ctx:

ctx.from.id            // Telegram user ID (number)
ctx.from.first_name    // user's first name
ctx.chat.id            // chat ID
ctx.message.text       // raw text content

Working with the bot object

Think of NxCreator as a managed Telegraf environment. The bot variable is already set up for you — never call new Telegraf() or import Telegraf yourself. Your job is simply to register handlers on the bot object that already exists.

When you need to remember something between messages — like what step a user is on — store it in the database or use a scene. Avoid keeping mutable data in plain JavaScript variables, since that state is not shared across restarts or multiple instances.

Last updated March 22, 2026
Was this page helpful?