Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/airgram/airgram
Strict typed library to create Telegram apps with Typescript/JavaScript (based on TDLib 1.8)
https://github.com/airgram/airgram
javascript tdlib tdweb telegram typescript
Last synced: 3 days ago
JSON representation
Strict typed library to create Telegram apps with Typescript/JavaScript (based on TDLib 1.8)
- Host: GitHub
- URL: https://github.com/airgram/airgram
- Owner: airgram
- License: gpl-3.0
- Created: 2018-10-14T10:40:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-14T19:13:58.000Z (almost 2 years ago)
- Last Synced: 2024-12-15T10:02:24.876Z (10 days ago)
- Topics: javascript, tdlib, tdweb, telegram, typescript
- Language: TypeScript
- Homepage: https://airgram.netlify.app
- Size: 4.51 MB
- Stars: 566
- Watchers: 13
- Forks: 48
- Open Issues: 82
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Airgram
This is a wrapper for [Telegram Database library](https://github.com/tdlib/td) written in TypeScript.
![Airgram](readme-banner.svg)
- **Code style.** TDLib follows a different coding convention than best practices in TypeScript or JavaScript. Airgram fixes it.
- **Methods.** Each API method has convenient wrapper with description and JSDoc documentation.
- **Type checking.** Airgram is a true TypeScript library. Everything has strict typings, so take full advantage of type checking and code completion.
- **Flexibility.** Airgram relies on middleware. This gives a high degree of freedom. You can modify requests, save responses, perform any actions in the data flow.
- **Data models.** You can extend standard TDLib objects and add some computed properties or whatever you want.
- **Use everywhere.** Airgram is an environment agnostic library. It will work in the browser as well as in Node.js. You can write Telegram client or use it for a Telegram bot backend.___
[![NPM Version](https://img.shields.io/npm/v/airgram.svg?style=flat-square)](https://www.npmjs.com/package/airgram)
[![TDLib](https://img.shields.io/badge/tdlib-v1.8.0-%2335ADE1)](https://github.com/tdlib/td)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)
[![NPM](https://img.shields.io/npm/l/airgram)](https://github.com/airgram/airgram/blob/master/LICENSE)## Installation
**Node.js**
1. Build TDLib library according the [instruction](https://github.com/tdlib/td#building).
2. Install [node-gyp](https://github.com/nodejs/node-gyp#installation)
3. Install Airgram:
```bash
# TDLib 1.8.0:
npm install airgram# TDLib 1.7.2:
npm install [email protected]
```
**Web**
```bash
# TDLib 1.8.0:
npm install @airgram/web# TDLib 1.7.2:
npm install @airgram/[email protected]
```Check out [webpack config](https://github.com/airgram/airgram/tree/master/examples/webpack-config) example.
## Getting started
```typescript
import { Airgram, Auth, prompt, toObject } from 'airgram'const airgram = new Airgram({
apiId: process.env.APP_ID,
apiHash: process.env.APP_HASH
})airgram.use(new Auth({
code: () => prompt(`Please enter the secret code:\n`),
phoneNumber: () => prompt(`Please enter your phone number:\n`)
}))void (async () => {
const me = toObject(await airgram.api.getMe())
console.log(`[me]`, me)
})// Getting all updates
airgram.use((ctx, next) => {
if ('update' in ctx) {
console.log(`[all updates][${ctx._}]`, JSON.stringify(ctx.update))
}
return next()
})// Getting new messages
airgram.on('updateNewMessage', async ({ update }, next) => {
const { message } = update
console.log('[new message]', message)
return next()
})
```## Documentation
Guides and API-reference are available [here](https://airgram.netlify.app).## Old version
If you are interested in `v1.*`, follow to corresponding [branch](https://github.com/airgram/airgram/tree/v1).## License
The source code is licensed under GPL v3. License is available [here](/LICENSE).