Files
Kyle Fang 457f933273 refactor: reorganize into monorepo with Bun workspaces
- Split project into three packages:
  - @react-telegram/core: Core React reconciler
  - @react-telegram/mtcute-adapter: MTCute Telegram adapter
  - @react-telegram/examples: Example bots (private)
- Add <br /> tag support for line breaks
- Update all examples to use <br /> instead of {'\n'}
- Configure Bun workspaces for better package management
- Update imports to use package names instead of relative paths
- Update README with new installation instructions
- Remove test files (moved to separate testing setup)

BREAKING CHANGE: Package names changed from react-telegram to @react-telegram/*

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-01 09:58:46 +08:00

1.7 KiB

@react-telegram/mtcute-adapter

MTCute adapter for React Telegram bots. This package provides the integration between React Telegram's core reconciler and the MTCute Telegram client library.

Installation

bun add @react-telegram/mtcute-adapter @react-telegram/core react

Usage

import React from 'react';
import { MtcuteAdapter } from '@react-telegram/mtcute-adapter';

const Bot = () => (
  <>
    <b>Hello from React Telegram!</b>
    <br />
    <br />
    <row>
      <button onClick={() => console.log('clicked!')}>Click me</button>
    </row>
  </>
);

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', () => <Bot />);
  
  await adapter.start(process.env.BOT_TOKEN!);
  console.log('Bot is running!');
}

main().catch(console.error);

Features

  • Full React component support for Telegram messages
  • Automatic message updates when state changes
  • Button click handling
  • Text input support with auto-delete option
  • Command handling
  • TypeScript support

API

MtcuteAdapter

const adapter = new MtcuteAdapter({
  apiId: number,
  apiHash: string,
  botToken: string,
  storage?: string // Default: '.mtcute'
});

Methods

  • onCommand(command: string, handler: (ctx) => ReactElement) - Register a command handler
  • start(botToken: string) - Start the bot
  • sendReactMessage(chatId: number | string, app: ReactElement) - Send a React-powered message
  • getClient() - Get the underlying MTCute client
  • getDispatcher() - Get the MTCute dispatcher

License

MIT