An open API service indexing awesome lists of open source software.

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

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