Airgram
Strict typed library to create Telegram apps with Typescript/JavaScript (based on TDLib 1.8)
Install / Use
/learn @airgram/AirgramREADME
Airgram
This is a wrapper for Telegram Database library written in TypeScript.
- 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.
<!-- [](https://www.npmjs.com/package/airgram) -->
Installation
Node.js
- Build TDLib library according the instruction.
- Install node-gyp
- Install Airgram:
# TDLib 1.8.0:
npm install airgram
# TDLib 1.7.2:
npm install airgram@tdlib-1.7.2
Web
# TDLib 1.8.0:
npm install @airgram/web
# TDLib 1.7.2:
npm install @airgram/web@tdlib-1.7.2
Check out webpack config example.
Getting started
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.
Old version
If you are interested in v1.*, follow to corresponding branch.
License
The source code is licensed under GPL v3. License is available here.
Related Skills
node-connect
346.8kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
107.6kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.1kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
