https://github.com/uo1428/grammy-bunjs-telegram-bot
β
Advance & Fully customizable telegram bot telegram build with latest & new tech
https://github.com/uo1428/grammy-bunjs-telegram-bot
bot-telegram bunjs bunjs-telegram-bot grammy-bot grammy-bot-template grammy-telegram-bot tele-bot telegraf-bot telegram-bot telegram-bot-template telegram-forwarder telegram-framework telegram-framework-bot telegram-webapp template-telegram-bot ts-telegram-bot uoaio
Last synced: 3 months ago
JSON representation
β Advance & Fully customizable telegram bot telegram build with latest & new tech
- Host: GitHub
- URL: https://github.com/uo1428/grammy-bunjs-telegram-bot
- Owner: Uo1428
- Created: 2025-03-16T07:24:55.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-16T08:17:30.000Z (3 months ago)
- Last Synced: 2025-03-16T09:22:38.945Z (3 months ago)
- Topics: bot-telegram, bunjs, bunjs-telegram-bot, grammy-bot, grammy-bot-template, grammy-telegram-bot, tele-bot, telegraf-bot, telegram-bot, telegram-bot-template, telegram-forwarder, telegram-framework, telegram-framework-bot, telegram-webapp, template-telegram-bot, ts-telegram-bot, uoaio
- Language: TypeScript
- Homepage: https://patreon.com/uoaio
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Grammy.js Telegram Bot Template with Bun.js
This project provides a robust template for building Telegram bots using Grammy.js and Bun.js with TypeScript support. It offers a structured architecture with conversation management, action handling, and command processing capabilities out of the box.
The template implements a modular design pattern that separates concerns into conversations, actions, and commands. It features built-in support for emoji parsing, markdown formatting, and session management. The project uses Bun.js as the runtime environment for enhanced performance and modern JavaScript features, while leveraging Grammy.js's powerful bot framework capabilities.
### πCredit
- Coded By github.com/uo1428---
Your One Click Can Help Other Users To Find This Repo Quickly: Leave a star β
---
## Repository Structure
```
.
βββ config/
β βββ index.ts # Environment configuration management
βββ src/
β βββ Actions/ # Callback query handlers for bot interactions
β β βββ Main/
β β βββ conversations.ts
β βββ Commands/ # Bot command implementations
β β βββ Main/
β β βββ start.ts # Implementation of /start command
β βββ Conversations/ # Interactive conversation flows
β β βββ Example/
β β βββ new.ts
β βββ Database/ # Database connectivity (placeholder)
β β βββ index.ts
β βββ utils/ # Utility functions and helpers
β β βββ client/ # Bot client setup and loading utilities
β β βββ functions/ # Common helper functions
β β βββ stuff/ # TypeScript type definitions
β βββ index.ts # Main application entry point
βββ package.json # Project dependencies and scripts
βββ tsconfig.json # TypeScript configuration
```## Usage Instructions
### Prerequisites
- Bun.js runtime environment
- Telegram Bot Token (from @BotFather)
- TypeScript 5.0.0 or higher### Installation
1. Clone the repository:
```bash
git clone https://github.com/Uo1428/grammy-bunjs-telegram-bot.git
cd grammy-bunjs-telegram-bot-template
```2. Install dependencies:
```bash
bun install
```3. Configure environment variables:
Create a `.env` file in the root directory:
```env
BOT_TOKEN=your_telegram_bot_token
```### Quick Start
1. Start the bot:
```bash
bun start
```2. Test the bot by sending the `/start` command in Telegram.
### More Detailed Examples
1. Creating a new command:
```typescript
// src/Commands/Main/example.ts
export default {
name: "example",
description: "An example command",
execute: async (ctx) => {
await ctx.reply("This is an example command!");
}
};
```2. Creating a new conversation:
```typescript
// src/Conversations/Example/new.ts
export default {
name: "example",
execute: async (conversation, ctx) => {
await ctx.reply("What is your name?");
const response = await conversation.waitFor(":text");
await ctx.reply(`Hello, ${response.msg.text}!`);
}
};
```### Troubleshooting
Common Issues:
1. Bot Token Invalid
```
Error: 401 Unauthorized
```
Solution: Verify your BOT_TOKEN in the .env file is correct and properly formatted.2. Module Not Found Errors
```
Error: Cannot find module '@config/index'
```
Solution: Ensure all TypeScript path aliases in tsconfig.json are properly configured.Debug Mode:
```typescript
// Enable debug logging
import consola from 'consola';
consola.level = 5;
```## Data Flow
The bot processes messages through a pipeline of middleware and handlers, transforming raw updates into structured responses.```ascii
Input β Parser β Middleware β Handler β Response
β β β
ββββββββββ Session Store βββββββ
```Key component interactions:
- Client initialization loads commands, actions, and conversations dynamically
- Middleware processes updates sequentially (hydration, emoji parsing, session management)
- Commands are triggered by text messages starting with "/"
- Actions handle callback queries from inline keyboards
- Conversations manage multi-step interactions with state management
- Error handler catches and formats all runtime errors## Discord Profile