Giter VIP home page Giter VIP logo

airgram-core's Introduction

Airgram

This is a wrapper for Telegram Database library written in TypeScript.

Airgram

  • 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 TDLib js-standard-style NPM

Installation

Node.js

  1. Build TDLib library according the instruction.
  2. Install node-gyp
  3. Install Airgram:
# TDLib 1.8.0:
npm install airgram

# TDLib 1.7.2:
npm install [email protected]

Web

# TDLib 1.8.0:
npm install @airgram/web

# TDLib 1.7.2:
npm install @airgram/[email protected]

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.

airgram-core's People

Contributors

esindger avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.