Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nestjs-airgram

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-airgram

Airgram module for NestJS

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
increased by183.33%
Maintainers
1
Weekly downloads
 
Created
Source

Nest Logo

NPM Version Package License NPM Downloads

Description

Airgram module for Nest.

Installation

NPM

$ npm i -s nestjs-airgram

Yarn

$ yarn add nestjs-airgram

Quick Start

Once the installation process is complete, now we need TDLib 1.7 binaries, how to get them you need to build them by this guide, or you can found here, then place binaries somewhere in your project workspace. Then we can import the module TdlModule either synchronously or asynchronosly into the root AppModule.

It is important to specify the correct path to the TDLib binaries in the command field. It is directly passed to dlopen / LoadLibrary. Check your OS documentation to see where it searches for the library.

 

Synchronous configuration

import { Module } from '@nestjs/common';
import { AirgramModule } from 'nestjs-airgram';

@Module({
  imports: [
    AirgramModule.forRoot({
      apiId: 'YOUR_APP_ID',
      apiHash: 'YOUR_API_HASH',
      command: path.resolve('tdjson.dll'), // Path to tdlib
      auth: {
        // ...
      },
    }),
  ],
})
export class AppModule {}

Then we can inject Airgram into our services. And use decorators for events.

import { Injectable, OnModuleInit } from '@nestjs/common';
import {
  Airgram,
  Context,
  GetMeMiddleware,
  UpdateNewMessageMiddleware,
} from 'airgram';
import {
  ExtractMiddlewareContext,
  InjectAirgram,
  OnEvent,
  OnRequest,
  OnUpdate,
} from 'nestjs-airgram';

@Injectable()
export class AppService implements OnModuleInit {
  constructor(@InjectAirgram() private airgram: Airgram) {
    setTimeout(() => this.onModuleInit(), 4000);
  }

  async onModuleInit(): Promise<void> {
    const me = await this.airgram.api.getMe();
    console.log('[Me]', me);
  }

  @OnEvent()
  onAnyEvent(ctx: Context): void {
    // This code will be invoked before every request and after all updates.
  }

  @OnUpdate()
  async onUpdate(update: unknown): Promise<void> {
    // This code will be invoked after update.
  }

  @OnRequest()
  async onRequest(): Promise<void> {
    // This code will be invoked before request.
  }

  @OnEvent('getMe')
  onGetMe(ctx: ExtractMiddlewareContext<GetMeMiddleware>): void {
    console.log('"GetMe" request triggered', ctx);
    // This code will be invoked before "Get me" request.
  }

  @OnEvent('updateNewMessage')
  onNewMessage(
    ctx: ExtractMiddlewareContext<UpdateNewMessageMiddleware>,
  ): void {
    console.log('"NewMessage" update triggered', ctx);
    // This code will be invoked after "New message" update.
  }
}

Keywords

FAQs

Package last updated on 06 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc