Build interactive Telegram bots using React components! This monorepo contains packages for creating Telegram bots with familiar React patterns, state management, and full TypeScript support.
Core React reconciler for building Telegram bot interfaces. Translates React components into Telegram message structures.
MTCute adapter that connects the React reconciler with the Telegram Bot API.
Complete example bots demonstrating various features and patterns.
# Using bun (recommended)
bun add @react-telegram/core @react-telegram/mtcute-adapter
# Using npm
npm install @react-telegram/core @react-telegram/mtcute-adapter
# Using yarn
yarn add @react-telegram/core @react-telegram/mtcute-adapter- React Components: Write bot interfaces using familiar React syntax
- State Management: Full React state with
useState,useEffect, and hooks - Interactive Elements: Buttons with onClick handlers, text inputs
- Rich Formatting: Bold, italic, code blocks, spoilers, links, and more
- Message Updates: Automatic message editing when state changes
- TypeScript Support: Full type safety with autocompletion
- Line Breaks: Use
<br />tags for clean formatting
Counter Bot - Interactive counter with increase/decrease buttons
Text Formatter - Demonstrates all text formatting capabilities
Calculator - Fully functional calculator with button grid
Tetris - Playable Tetris game with controls
React Router - Navigation example with MemoryRouter
import React, { useState } from 'react';
import { MtcuteAdapter } from '@react-telegram/mtcute-adapter';
const CounterBot = () => {
const [count, setCount] = useState(0);
return (
<>
<b>Counter Bot π€</b>
<br />
<br />
Current count: <b>{count}</b>
<br />
<br />
<row>
<button onClick={() => setCount(count - 1)}>β Decrease</button>
<button onClick={() => setCount(count + 1)}>β Increase</button>
</row>
</>
);
};
// Initialize the bot
async function main() {
const adapter = new MtcuteAdapter({
apiId: parseInt(process.env.API_ID!),
apiHash: process.env.API_HASH!,
botToken: process.env.BOT_TOKEN!
});
adapter.onCommand('start', () => <CounterBot />);
await adapter.start(process.env.BOT_TOKEN!);
console.log('Bot is running!');
}
main().catch(console.error);This project uses Bun workspaces for managing multiple packages.
# Clone the repository
git clone https://github.com/lockin-bot/react-telegram.git
cd react-telegram
# Install dependencies
bun install
# Run examples
cd packages/examples
bun run startCreate a .env file in the examples package:
API_ID=your_telegram_api_id
API_HASH=your_telegram_api_hash
BOT_TOKEN=your_bot_token_from_botfatherGet your credentials from:
- Bot token: @BotFather
- API credentials: my.telegram.org
<b>,<strong>- Bold text<i>,<em>- Italic text<u>,<ins>- Underlined text<s>,<strike>,<del>- Strikethrough<code>- Inline code<pre>- Code blocks<br />- Line breaks
<tg-spoiler>- Hidden spoiler text<tg-emoji emojiId="">- Custom emoji<blockquote expandable>- Quotes<a href="">- Links
<button onClick={}>- Inline keyboard buttons<row>- Button row container<input onSubmit={} autoDelete>- Text input handler
const TodoBot = () => {
const [todos, setTodos] = useState<string[]>([]);
return (
<>
<b>π Todo List</b>
<br />
<br />
{todos.length === 0 ? (
<i>No todos yet!</i>
) : (
todos.map((todo, i) => (
<>
{i + 1}. {todo}
<br />
</>
))
)}
<br />
<row>
<button onClick={() => setTodos([...todos, `Task ${todos.length + 1}`])}>
β Add Task
</button>
<button onClick={() => setTodos(todos.slice(0, -1))}>
β Remove Last
</button>
</row>
</>
);
};const InputBot = () => {
const [name, setName] = useState('');
return (
<>
<b>What's your name?</b>
<br />
<br />
{name && <>Hello, {name}!</>}
<input
onSubmit={(text) => setName(text)}
autoDelete // Automatically delete user's message
/>
</>
);
};react-telegram/
βββ packages/
β βββ core/ # Core React reconciler
β β βββ src/
β β β βββ reconciler.ts
β β β βββ jsx.d.ts
β β β βββ index.ts
β β βββ package.json
β β
β βββ mtcute-adapter/ # MTCute Telegram adapter
β β βββ src/
β β β βββ mtcute-adapter.ts
β β β βββ index.ts
β β βββ package.json
β β
β βββ examples/ # Example bots
β βββ src/
β β βββ example-bot.tsx
β β βββ quiz-bot.tsx
β β βββ ...
β βββ package.json
β
βββ package.json # Root workspace configuration
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature 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
This project is licensed under the MIT License - see the LICENSE file for details.
β Star this repo if you find it useful!
Built with β€οΈ and React