A powerful and flexible Telegram bot framework built on top of Telegraf. TeleFlex makes it easy to create modular, interactive Telegram bots with dynamic help menus, module management, and more.
- 📚 Dynamic Help Menus: Automatically generate interactive help menus from your modules
- 🧩 Module Management: Organize your bot commands into modular components
- 📱 Interactive Commands: Built-in support for inline keyboards and command pagination
- 🚦 Rate Limiting: Protect your bot with built-in flood control
- 🎨 Customizable: Easy to customize text messages, buttons, and behaviors
- 📸 Media Support: Built-in support for photos, stickers, GIFs, and media albums
- 🎮 Game Support: Create interactive games with state management
- 🛠 Utility Commands: Common utility commands ready to use
npm install teleflex
- Create a new bot with @BotFather and get your bot token
- Create a new project and install TeleFlex:
mkdir my-telegram-bot
cd my-telegram-bot
npm init -y
npm install teleflex dotenv
- Create a basic bot (index.js):
const { Telegraf } = require('telegraf');
const TeleFlex = require('teleflex');
require('dotenv').config();
// Initialize your bot
const bot = new Telegraf(process.env.BOT_TOKEN);
// Initialize TeleFlex
const teleflex = new TeleFlex(bot, {
modulesPath: './modules',
buttonsPerPage: 5,
texts: {
helpMenuTitle: '🤖 Bot Commands',
helpMenuIntro: 'Available modules ({count}):\n{modules}'
}
});
// Set up handlers
teleflex.setupHandlers();
// Add basic commands
bot.command('start', ctx => {
ctx.reply('Welcome! Use /help to see available commands.');
});
// Launch the bot
bot.launch();
// Enable graceful shutdown
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
Create modules in your modules directory. Each module should export MODULE
, HELP
, and commands
:
// modules/utility.js
const MODULE = 'Utility';
const HELP = `
🛠 *Utility Commands*
/calc [expression] - Calculate mathematical expressions
/time [timezone] - Get current time
/weather [city] - Get weather information
`;
const commands = {
calc: async (ctx) => {
const expr = ctx.message.text.split(' ').slice(1).join(' ');
try {
const result = eval(expr);
ctx.reply(`🔢 Result: ${result}`);
} catch (err) {
ctx.reply('❌ Invalid expression');
}
},
// ... other command implementations
};
module.exports = { MODULE, HELP, commands };
TeleFlex provides built-in support for handling media files. Define your media assets in your module:
// modules/media.js
const MEDIA = {
photos: [
{
file: 'welcome.jpg',
caption: '👋 Welcome!'
}
],
stickers: ['sticker_file_id'],
gifs: ['gif_url'],
albumPhotos: [
{
file: 'album1.jpg',
caption: 'Photo 1'
}
]
};
const commands = {
photo: async (ctx) => {
const photo = MEDIA.photos[0];
await ctx.replyWithPhoto(
{ source: photo.file },
{ caption: photo.caption }
);
}
// ... other media commands
};
module.exports = { MODULE, HELP, commands, MEDIA };
const options = {
// Path to modules directory
modulesPath: './modules',
// Number of buttons per page in menus
buttonsPerPage: 6,
// Minimum time between actions (ms)
floodWait: 1000,
// Custom command prefix
commandPrefix: '/',
// Customizable text messages
texts: {
helpMenuTitle: '🤖 Help Menu',
helpMenuIntro: 'Available modules ({count}):\n{modules}',
moduleHelpTitle: '📚 {moduleName} Commands',
moduleHelpIntro: '{helpText}',
noModulesLoaded: '⚠️ No modules available',
backButton: '◀️ Back',
prevButton: '⬅️ Previous',
nextButton: '➡️ Next',
floodMessage: '⏳ Please wait'
}
};
Check out the examples directory for more examples including:
- Basic bot setup
- Utility commands
- Interactive games
- Media handling
- And more!
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
- Create an issue for bug reports and feature requests
- Star ⭐ the repo if you find it useful!
KunalG932 - GitHub