๐Ÿšจ Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis โ†’
Socket
Book a DemoInstallSign in
Socket

@xbibzlibrary/xbibz-team-telegram-bot

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xbibzlibrary/xbibz-team-telegram-bot

A powerful and comprehensive Telegram bot library for TypeScript that exceeds Telegraf in functionality and ease of use

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
6
-25%
Maintainers
1
Weekly downloads
ย 
Created
Source

๐Ÿš€ Xbibz Team Telegram Bot Library

xbibztelebot

TypeScript Node.js Telegram NPM Version License

โšก A powerful and comprehensive Telegram bot library for TypeScript

Built with โค๏ธ by Xbibz Official

๐ŸŒŸ Features โ€ข ๐Ÿ“ฆ Installation โ€ข ๐ŸŽฏ Quick Start โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿ’ก Examples

๐ŸŽจ Why Choose Xbibz?

๐ŸŽฏ Easy to Use

Simple and intuitive API that makes bot development a breeze

๐Ÿš€ High Performance

Optimized for speed and efficiency with minimal overhead

Complete Telegram Bot API support with advanced features

๐Ÿ“ TypeScript First

Built with TypeScript for excellent type safety and IntelliSense

๐Ÿ”ง Flexible

Highly customizable with middleware and plugin support

๐Ÿ“š Well Documented

Comprehensive documentation with plenty of examples

โœจ Features

๐ŸŽฎ Command Handling

  • โœ… Easy command registration
  • โœ… Multi-command support
  • โœ… Command arguments parsing
  • โœ… Bot name filtering

๐Ÿ’ฌ Message Processing

  • โœ… Text, Photo, Video, Audio
  • โœ… Documents, Stickers, Voice
  • โœ… Location, Contact, Poll
  • โœ… Custom filters

๐Ÿ”„ Session Management

  • โœ… Built-in session support
  • โœ… Memory storage (default)
  • โœ… File/Redis/MongoDB support
  • โœ… Custom session handlers

๐ŸŽญ Middleware System

  • โœ… Powerful middleware chain
  • โœ… Easy to create custom middleware
  • โœ… Async/await support
  • โœ… Error handling

๐ŸŽฏ Inline & Callback Queries

  • โœ… Inline query handling
  • โœ… Callback query support
  • โœ… Regex pattern matching
  • โœ… Data-based routing

๐Ÿ› ๏ธ Advanced Features

  • โœ… Complete API coverage
  • โœ… File upload support
  • โœ… Payment handling
  • โœ… Webhook support

๐Ÿ“ฆ Installation

# Using npm
npm install @xbibzlibrary/xbibz-team-telegram-bot

# Using yarn
yarn add @xbibzlibrary/xbibz-team-telegram-bot

# Using pnpm
pnpm add @xbibzlibrary/xbibz-team-telegram-bot

๐ŸŽฏ Quick Start

Create your first bot in just a few lines of code!

import { XbibzTelegramBot } from '@xbibzlibrary/xbibz-team-telegram-bot';

// Initialize the bot
const bot = new XbibzTelegramBot('YOUR_BOT_TOKEN', {
  polling: true,
  logLevel: 'info'
});

// Handle /start command
bot.command('start', async (ctx) => {
  await ctx.reply('Hello! ๐Ÿ‘‹ Welcome to Xbibz Bot!');
});

// Handle text messages
bot.onMessage(async (ctx) => {
  if (ctx.text) {
    await ctx.reply(`You said: ${ctx.text}`);
  }
});

// Launch the bot
bot.launch();
console.log('๐Ÿค– Bot is running!');

๐ŸŽ‰ That's it! Your bot is now live!

Get your bot token from @BotFather and replace YOUR_BOT_TOKEN with it.

๐Ÿ“– Documentation

๐ŸŽฎ Command Handling

Commands are the backbone of Telegram bots. Xbibz makes it incredibly easy!

// Single command
bot.command('help', async (ctx) => {
  await ctx.reply('Need help? Contact @XbibzOfficial');
});

// Multiple commands
bot.command(['hello', 'hi', 'hey'], async (ctx) => {
  await ctx.reply('Hello there! ๐Ÿ‘‹');
});

// Access command arguments
bot.command('echo', async (ctx) => {
  const args = ctx.stateData.args; // Array of arguments
  await ctx.reply(args.join(' '));
});

๐Ÿ’ฌ Message Handling

Handle different types of messages with ease!

// Text messages
bot.onMessage(async (ctx) => {
  if (ctx.text) {
    console.log('Received text:', ctx.text);
  }
});

// Photo messages
bot.messageHandler.onPhoto(async (ctx) => {
  await ctx.reply('Nice photo! ๐Ÿ“ธ');
});

// Video messages
bot.messageHandler.onVideo(async (ctx) => {
  await ctx.reply('Cool video! ๐ŸŽฅ');
});

// Document messages
bot.messageHandler.onDocument(async (ctx) => {
  await ctx.reply('Got your document! ๐Ÿ“„');
});

// Location messages
bot.messageHandler.onLocation(async (ctx) => {
  const { latitude, longitude } = ctx.message.location;
  await ctx.reply(`Your location: ${latitude}, ${longitude} ๐Ÿ“`);
});

๐ŸŽฏ Inline Keyboards & Callback Queries

Create interactive buttons for your bot!

// Send message with inline keyboard
bot.command('menu', async (ctx) => {
  const keyboard = {
    inline_keyboard: [
      [
        { text: '๐Ÿ“Š Stats', callback_data: 'stats' },
        { text: 'โš™๏ธ Settings', callback_data: 'settings' }
      ],
      [
        { text: 'โ“ Help', callback_data: 'help' }
      ]
    ]
  };
  
  await ctx.reply('Choose an option:', { reply_markup: keyboard });
});

// Handle callback queries
bot.callbackQueryHandler.onData('stats', async (ctx) => {
  await ctx.answerCallbackQuery({ text: 'Loading stats...' });
  await ctx.editMessage('Here are your stats! ๐Ÿ“Š');
});

bot.callbackQueryHandler.onData('settings', async (ctx) => {
  await ctx.answerCallbackQuery();
  await ctx.editMessage('Settings menu โš™๏ธ');
});

// Use regex for callback data
bot.callbackQueryHandler.onRegex(/^page_(\d+)$/, async (ctx) => {
  const match = ctx.stateData.callbackMatch;
  const page = match[1];
  await ctx.editMessage(`Showing page ${page}`);
});

๐Ÿ”„ Session Management

Keep track of user data across conversations!

const bot = new XbibzTelegramBot('YOUR_BOT_TOKEN', {
  session: {
    enabled: true,
    storage: 'memory', // or 'file', 'redis', 'mongodb'
    defaultSession: { count: 0 }
  }
});

bot.command('count', async (ctx) => {
  ctx.session.count = (ctx.session.count || 0) + 1;
  await ctx.reply(`Button pressed ${ctx.session.count} times!`);
});

bot.command('reset', async (ctx) => {
  ctx.session.count = 0;
  await ctx.reply('Counter reset! ๐Ÿ”„');
});

๐ŸŽญ Custom Middleware

Create powerful middleware for your bot!

// Logging middleware
bot.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  console.log(`Processing took ${ms}ms`);
});

// Admin-only middleware
async function adminOnly(ctx, next) {
  const adminIds = [123456789, 987654321];
  
  if (adminIds.includes(ctx.fromId)) {
    return next();
  }
  
  await ctx.reply('โŒ Admin only command!');
}

bot.command('admin', adminOnly, async (ctx) => {
  await ctx.reply('โœ… Admin access granted!');
});

// Rate limiting middleware
const userLastMessage = new Map();

bot.use(async (ctx, next) => {
  const userId = ctx.fromId;
  const now = Date.now();
  const lastMsg = userLastMessage.get(userId) || 0;
  
  if (now - lastMsg < 1000) { // 1 second cooldown
    await ctx.reply('โฐ Please wait before sending another message!');
    return;
  }
  
  userLastMessage.set(userId, now);
  await next();
});

๐ŸŽจ Filters

Use filters to handle specific types of messages!

import { Filter } from '@xbibzlibrary/xbibz-team-telegram-bot';

// Private chat only
bot.use(async (ctx, next) => {
  if (Filter.private(ctx)) {
    return next();
  }
  await ctx.reply('This command works only in private chats!');
});

// Photo in private chat
bot.use(async (ctx, next) => {
  if (Filter.and(Filter.private, Filter.photo)(ctx)) {
    await ctx.reply('Private photo received! ๐Ÿ“ธ');
  }
  await next();
});

// Text containing "hello"
bot.use(async (ctx, next) => {
  if (Filter.contains('hello')(ctx)) {
    await ctx.reply('Hello! ๐Ÿ‘‹');
  }
  await next();
});

// Regex pattern
bot.use(async (ctx, next) => {
  if (Filter.regex(/\d{4}/)(ctx)) { // 4 digits
    await ctx.reply('Found a 4-digit number!');
  }
  await next();
});

๐Ÿ“ค Sending Messages

Multiple ways to send messages!

// Simple text
await ctx.reply('Hello World!');

// With formatting
await ctx.reply('*Bold* _italic_ `code`', { 
  parse_mode: 'Markdown' 
});

// With HTML
await ctx.reply('<b>Bold</b> <i>italic</i>', { 
  parse_mode: 'HTML' 
});

// Reply to message
await ctx.reply('This is a reply!', {
  reply_to_message_id: ctx.messageId
});

// Send photo
await ctx.replyWithPhoto('https://example.com/photo.jpg', 'Photo caption');

// Send video
await ctx.replyWithVideo('https://example.com/video.mp4', 'Video caption');

// Send document
await ctx.replyWithDocument('https://example.com/doc.pdf', 'Document caption');

// Send location
await ctx.replyWithLocation(51.5074, -0.1278); // London coordinates

// Send poll
await ctx.replyWithPoll('What is your favorite color?', [
  'Red', 'Blue', 'Green', 'Yellow'
]);

๐ŸŽฏ Context (ctx) Methods

The context object gives you access to everything!

bot.onMessage(async (ctx) => {
  // Message info
  const text = ctx.text;
  const messageId = ctx.messageId;
  const chatId = ctx.chatId;
  const userId = ctx.fromId;
  
  // User info
  const user = ctx.from;
  console.log(user.first_name, user.username);
  
  // Chat info
  const chat = ctx.chat;
  console.log(chat.type); // private, group, supergroup, channel
  
  // Session
  ctx.session.userData = 'some data';
  
  // Typing action
  await ctx.sendTyping();
  
  // Edit message
  await ctx.editMessage('New text');
  
  // Delete message
  await ctx.deleteMessage();
  
  // Forward message
  await ctx.forwardMessage(fromChatId, messageId);
  
  // Chat actions
  await ctx.banChatMember(userId);
  await ctx.unbanChatMember(userId);
  await ctx.pinChatMessage(messageId);
});

๐Ÿ’ก Examples

๐Ÿ“Š Example 1: Simple Echo Bot

import { XbibzTelegramBot } from '@xbibzlibrary/xbibz-team-telegram-bot';

const bot = new XbibzTelegramBot('YOUR_BOT_TOKEN');

bot.command('start', async (ctx) => {
  await ctx.reply('Echo bot started! Send me any message.');
});

bot.onMessage(async (ctx) => {
  if (ctx.text && !ctx.text.startsWith('/')) {
    await ctx.reply(ctx.text);
  }
});

bot.launch();

๐ŸŽฎ Example 2: Quiz Bot

const bot = new XbibzTelegramBot('YOUR_BOT_TOKEN', {
  session: { enabled: true }
});

const questions = [
  { q: 'What is 2+2?', a: '4' },
  { q: 'Capital of France?', a: 'Paris' },
  { q: 'Largest planet?', a: 'Jupiter' }
];

bot.command('quiz', async (ctx) => {
  ctx.session.score = 0;
  ctx.session.questionIndex = 0;
  
  const q = questions[0];
  await ctx.reply(`Question 1: ${q.q}`);
});

bot.onMessage(async (ctx) => {
  if (ctx.session.questionIndex !== undefined) {
    const currentQ = questions[ctx.session.questionIndex];
    
    if (ctx.text?.toLowerCase() === currentQ.a.toLowerCase()) {
      ctx.session.score++;
      await ctx.reply('โœ… Correct!');
    } else {
      await ctx.reply(`โŒ Wrong! Answer: ${currentQ.a}`);
    }
    
    ctx.session.questionIndex++;
    
    if (ctx.session.questionIndex < questions.length) {
      const nextQ = questions[ctx.session.questionIndex];
      await ctx.reply(`Question ${ctx.session.questionIndex + 1}: ${nextQ.q}`);
    } else {
      await ctx.reply(`๐ŸŽ‰ Quiz finished! Score: ${ctx.session.score}/${questions.length}`);
      delete ctx.session.questionIndex;
    }
  }
});

bot.launch();

๐Ÿ›’ Example 3: Shopping Bot

const bot = new XbibzTelegramBot('YOUR_BOT_TOKEN', {
  session: { enabled: true, defaultSession: { cart: [] } }
});

const products = {
  'apple': { name: 'Apple', price: 1.5 },
  'banana': { name: 'Banana', price: 0.8 },
  'orange': { name: 'Orange', price: 1.2 }
};

bot.command('shop', async (ctx) => {
  const keyboard = {
    inline_keyboard: Object.keys(products).map(key => ([
      { text: `${products[key].name} - $${products[key].price}`, callback_data: `buy_${key}` }
    ]))
  };
  
  await ctx.reply('๐Ÿ›’ Welcome to our shop!', { reply_markup: keyboard });
});

bot.callbackQueryHandler.onRegex(/^buy_(.+)$/, async (ctx) => {
  const productKey = ctx.stateData.callbackMatch[1];
  const product = products[productKey];
  
  ctx.session.cart.push(product);
  await ctx.answerCallbackQuery({ text: `Added ${product.name} to cart!` });
});

bot.command('cart', async (ctx) => {
  if (ctx.session.cart.length === 0) {
    await ctx.reply('๐Ÿ›’ Your cart is empty!');
    return;
  }
  
  const total = ctx.session.cart.reduce((sum, item) => sum + item.price, 0);
  const items = ctx.session.cart.map(item => `${item.name} - $${item.price}`).join('\n');
  
  await ctx.reply(`๐Ÿ›’ Your cart:\n${items}\n\nTotal: $${total.toFixed(2)}`);
});

bot.command('clear', async (ctx) => {
  ctx.session.cart = [];
  await ctx.reply('๐Ÿ—‘๏ธ Cart cleared!');
});

bot.launch();

๐Ÿ—๏ธ Project Structure

xbibz-team-telegram-bot/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/
โ”‚   โ”‚   โ”œโ”€โ”€ bot.ts           # Main bot class
โ”‚   โ”‚   โ””โ”€โ”€ context.ts       # Context class
โ”‚   โ”œโ”€โ”€ api/
โ”‚   โ”‚   โ””โ”€โ”€ api-client.ts    # Telegram API client
โ”‚   โ”œโ”€โ”€ handlers/
โ”‚   โ”‚   โ”œโ”€โ”€ command-handler.ts
โ”‚   โ”‚   โ”œโ”€โ”€ message-handler.ts
โ”‚   โ”‚   โ”œโ”€โ”€ callback-query-handler.ts
โ”‚   โ”‚   โ””โ”€โ”€ inline-query-handler.ts
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ””โ”€โ”€ middleware.ts    # Middleware system
โ”‚   โ”œโ”€โ”€ session/
โ”‚   โ”‚   โ””โ”€โ”€ session-manager.ts
โ”‚   โ”œโ”€โ”€ filters/
โ”‚   โ”‚   โ””โ”€โ”€ filter.ts        # Message filters
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”‚   โ”œโ”€โ”€ logger.ts
โ”‚   โ”‚   โ””โ”€โ”€ error-handler.ts
โ”‚   โ”œโ”€โ”€ types/
โ”‚   โ”‚   โ””โ”€โ”€ index.ts         # TypeScript types
โ”‚   โ””โ”€โ”€ index.ts             # Main export
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic/
โ”‚   โ”œโ”€โ”€ advanced/
โ”‚   โ””โ”€โ”€ custom-middleware/
โ”œโ”€โ”€ tests/
โ”œโ”€โ”€ dist/                    # Compiled output
โ””โ”€โ”€ package.json

๐Ÿš€ Building & Development

# Install dependencies
npm install

# Build the project
npm run build

# Development mode (watch)
npm run dev

# Run tests
npm test

# Lint code
npm run lint

# Clean build
npm run clean

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  • ๐Ÿด Fork the repository
  • ๐ŸŒฟ Create a new branch (git checkout -b feature/amazing-feature)
  • ๐Ÿ’พ Commit your changes (git commit -m 'Add amazing feature')
  • ๐Ÿ“ค Push to the branch (git push origin feature/amazing-feature)
  • ๐ŸŽ‰ Open a Pull Request

๐Ÿ“ž Support & Community

๐Ÿ’ฌ Get in Touch

๐Ÿ“ฑ Telegram

@XbibzOfficial

๐ŸŽต TikTok

@xbibzofficiall

โ˜• Donate

Ko-fi

Found this helpful? Consider supporting the project! โค๏ธ

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Author ๐Ÿ‘ฟ

authornya pacalnya seya

๐ŸŒŸ Star History

If you like this project, please give it a โญ on GitHub!

Made with โค๏ธ by Xbibz Official

Happy Botting! ๐Ÿค–โœจ

TypeScript Node.js Telegram

Keywords

telegram

FAQs

Package last updated on 21 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts