I finally made a scalable and maintainable coding structure for the Telegraf.js project #2073
Unanswered
SwapnilSoni1999
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
🧠 Structuring a Scalable Telegram Bot using Telegraf.js (like Express)
If you've ever built an Express.js application, you're probably familiar with its clean and modular structure. You split your logic into:
...and so on.
Recently, I’ve been building bots using
telegraf.js— a fantastic Node.js framework for Telegram bot development. And what surprised me was how similar yet more powerful the architecture can be.🤔 Why Structure Matters
Like Express, Telegraf supports:
bot.command,bot.action)But it also supports Telegram-specific features like:
/start,/help)However, the type system in Telegraf can feel overwhelming. For example, hovering over
ctx(the context object) gives you a wall of types that can make your head spin. 😵Let’s break this down and create a clean, scalable Telegraf bot structure — similar to what we’d do with Express.
📁 Project Structure
🔍 Understanding Telegraf Context Types
Let’s tame the
ctxmonster.Now we can use these specialized context types for our commands and actions 💪
🧠 Your
bot.ts= Express'sapp.tsJust like
app.use(...)in Express!🧱 Middleware
🧾 Commands
🔘 Actions
✅ Final Thoughts
🔗 Let’s Connect
If you found this helpful, follow me for more posts on Node.js, bots, and TypeScript wizardry!
All reactions