2023-11-01 01:04:29 +03:00
|
|
|
<p align="center">
|
|
|
|
<a href="https://github.com/mtcute/mtcute/">
|
2024-07-18 23:56:32 +03:00
|
|
|
<img src="https://raw.githubusercontent.com/mtcute/mtcute/master/.github/logo.svg?new" alt="mtcute logo" title="mtcute" width="480" /><br/>
|
2023-11-01 01:04:29 +03:00
|
|
|
</a><br/>
|
|
|
|
<b>modern typescript library for mtproto</b>
|
|
|
|
<br>
|
|
|
|
<a href="https://mtcute.dev">documentation</a>
|
|
|
|
•
|
|
|
|
<a href="https://ref.mtcute.dev">api reference</a>
|
|
|
|
•
|
2023-11-13 10:44:49 +03:00
|
|
|
<a href="https://t.me/mt_cute">telegram chat</a>
|
2023-11-01 01:04:29 +03:00
|
|
|
<br/><br/>
|
|
|
|
<img src="https://github.com/mtcute/mtcute/actions/workflows/test.yaml/badge.svg" alt="NodeJS CI" />
|
|
|
|
<img src="https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fmtcute%2Fmtcute%2Fmaster%2Fpackages%2Ftl%2Fapi-schema.json&query=l&label=tl%20layer" alt="tl layer" />
|
|
|
|
<a href="https://www.npmjs.com/search?q=%40mtcute">
|
2024-04-02 01:16:14 +03:00
|
|
|
<img src="https://img.shields.io/npm/v/@mtcute/node" alt="npm" />
|
2023-11-01 01:04:29 +03:00
|
|
|
</a>
|
|
|
|
<img src="https://img.shields.io/badge/-alpha-orange" alt="alpha version" />
|
|
|
|
</p>
|
|
|
|
|
2023-11-13 10:44:49 +03:00
|
|
|
> [!WARNING]
|
2023-12-18 15:22:15 +03:00
|
|
|
> mtcute is currently in alpha stage: the api is not very stable yet, and there may be a lot of bugs
|
2023-11-01 01:04:29 +03:00
|
|
|
> feel free to try it out, though, any feedback is appreciated!
|
2023-11-12 19:42:04 +03:00
|
|
|
>
|
|
|
|
> releases may not follow semver just yet, so please pin the versions for now
|
2023-11-01 01:04:29 +03:00
|
|
|
|
|
|
|
```ts
|
2024-03-07 04:13:18 +03:00
|
|
|
import { TelegramClient } from '@mtcute/node'
|
2023-11-01 01:04:29 +03:00
|
|
|
import { Dispatcher, filters } from '@mtcute/dispatcher'
|
|
|
|
|
2024-03-07 04:13:18 +03:00
|
|
|
const tg = new TelegramClient({
|
2023-11-01 01:04:29 +03:00
|
|
|
apiId: parseInt(process.env.API_ID),
|
|
|
|
apiHash: process.env.API_HASH,
|
|
|
|
storage: 'my-account'
|
|
|
|
})
|
|
|
|
const dp = Dispatcher.for(tg)
|
|
|
|
|
|
|
|
dp.onNewMessage(filters.chat('private'), async (msg) => {
|
|
|
|
await msg.replyText('hiiii from mtcute! 🌸')
|
|
|
|
})
|
|
|
|
|
2023-12-13 21:43:46 +03:00
|
|
|
tg.run({ /* optional params */ }, async (self) => {
|
|
|
|
console.log(`✨ logged in as ${self.displayName}`)
|
2023-11-01 01:04:29 +03:00
|
|
|
})
|
|
|
|
```
|
2023-06-08 01:27:54 +03:00
|
|
|
|
2023-11-13 10:44:49 +03:00
|
|
|
mtcute is a modern, performant and *✨ cute ✨* [mtproto](https://mtcute.dev/guide/intro/mtproto-vs-bot-api.html) library and bot framework,
|
|
|
|
supporting both web and nodejs.
|
2023-06-08 01:27:54 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
## quick start
|
2023-06-08 01:27:54 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
🤖 just starting a (user)bot? use the scaffolding tool:
|
2023-06-08 01:27:54 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
```bash
|
|
|
|
pnpm create @mtcute/bot
|
|
|
|
```
|
2023-06-08 01:27:54 +03:00
|
|
|
|
2024-05-10 05:48:27 +03:00
|
|
|
🏭 want to integrate it into your existing nodejs app? use the nodejs package:
|
2023-11-01 01:04:29 +03:00
|
|
|
```bash
|
|
|
|
pnpm add @mtcute/node
|
2024-05-10 05:48:27 +03:00
|
|
|
# optional, for faster crypto
|
2023-11-01 01:04:29 +03:00
|
|
|
pnpm add @mtcute/crypto-node
|
|
|
|
```
|
2021-04-08 13:12:31 +03:00
|
|
|
|
2024-03-07 04:13:18 +03:00
|
|
|
✨ building something for web? use the web package:
|
2023-11-01 01:04:29 +03:00
|
|
|
```bash
|
2024-03-07 04:13:18 +03:00
|
|
|
pnpm add @mtcute/web
|
2023-11-01 01:04:29 +03:00
|
|
|
```
|
2022-05-06 13:23:29 +03:00
|
|
|
|
2024-05-10 05:48:27 +03:00
|
|
|
🚀 using the newfangled runtimes? we've got you covered:
|
|
|
|
- bun: `bun add @mtcute/bun`
|
|
|
|
- deno: `import { TelegramClient } from 'jsr:@mtcute/deno'`
|
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
learn more: [guide](https://mtcute.dev/guide/)
|
2023-06-04 20:00:33 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
## features
|
2022-05-06 13:23:29 +03:00
|
|
|
|
2024-03-07 13:07:08 +03:00
|
|
|
- 🍰 **simple**: mtcute hides all the complexity and provides a clean and modern api
|
|
|
|
- ✨ **compatible**: mtcute supports almost everything bot api does, and even more!
|
|
|
|
- 🍡 **lightweight**: running instance uses less than 50 mb of ram
|
|
|
|
- 🛡️ **type-safe**: most of the apis (including mtproto) are strictly typed to help your workflow
|
|
|
|
- ⚙️ **hackable**: almost every aspect of the library is customizable, including networking and storage
|
2023-11-01 01:04:29 +03:00
|
|
|
- 🕙 **up-to-date**: mtcute uses the latest TL schema to provide the newest features as soon as possible
|
2022-05-06 13:23:29 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
## cat in the readme 🐈
|
2022-05-06 13:23:29 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
<p align="center">
|
|
|
|
<img src="https://cataas.com/cat" align="center" width="480" />
|
|
|
|
</p>
|
2022-05-06 13:23:29 +03:00
|
|
|
|
2024-03-07 13:07:08 +03:00
|
|
|
## project goals
|
|
|
|
|
|
|
|
mtcute strives to:
|
|
|
|
- be customizable enough to fit most of the possible use-cases
|
|
|
|
- be lightweight, both in terms of runtime and bundle size
|
|
|
|
- support (theoretically) any environment without much hassle
|
|
|
|
- provide a solid foundation for all kinds of applications on telegram platform
|
|
|
|
- provide a convenient high-level api for the most commonly used features
|
|
|
|
|
|
|
|
mtcute is **NOT** and will never be:
|
|
|
|
- a library for spam/flood or otherwise malicious activities
|
|
|
|
- a fully feature-complete library - highlevel apis will never cover the entirety of the apis. feel free to contribute, though!
|
|
|
|
- a drop-in replacement for (insert library name)
|
|
|
|
- a teapot
|
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
## setting up for development
|
2021-04-08 12:19:38 +03:00
|
|
|
|
|
|
|
```bash
|
2021-08-05 20:38:24 +03:00
|
|
|
git clone https://github.com/mtcute/mtcute
|
2023-09-21 00:47:57 +03:00
|
|
|
fnm use # or `nvm use`
|
2021-08-05 20:38:24 +03:00
|
|
|
cd mtcute
|
2023-06-04 20:00:33 +03:00
|
|
|
pnpm install --frozen-lockfile
|
2021-04-14 23:06:10 +03:00
|
|
|
|
|
|
|
# generate code from tl schema
|
2023-09-21 00:47:57 +03:00
|
|
|
pnpm -C packages/tl run gen-code
|
2021-04-08 12:19:38 +03:00
|
|
|
```
|
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
## acknowledgements
|
2021-04-08 12:19:38 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
some parts were based on or greatly inspired by these projects:
|
2021-04-08 12:19:38 +03:00
|
|
|
|
2023-11-01 01:04:29 +03:00
|
|
|
- [TDLib](https://github.com/tdlib/td) - the official mtproto client library
|
|
|
|
- [TDesktop](https://github.com/telegramdesktop/tdesktop) - the official desktop client
|
|
|
|
- [Pyrogram](https://github.com/pyrogram/pyrogram), [Telethon](https://github.com/LonamiWebs/Telethon) - popular python libraries
|
2024-07-18 23:56:32 +03:00
|
|
|
|
|
|
|
thanks [@dotvhs](//t.me/AboutTheDot) for the logo <3
|