Nestgram
  • ⭐About Nestgram
  • 📄Guide
  • 📰News
  • 🔞Handling updates
    • Handling commands
    • Handling text messages
    • Handling other updates
    • Entities: url, email and other
    • Other arguments in handler
    • Handling media files and download it
  • ðŸŠķNestgram Features
    • Services
    • Middlewares and Params
    • Sending messages correctly
    • Answer class
    • Scopes
    • States
    • Views
  • 💎Messages
    • Sending a photo, video and other media
    • Sending a media group
    • Send location (live) or venue
    • Send contact
    • Send poll
    • Send dice
    • Edit/delete messages
    • Copy or Forward a message
  • âŒĻïļKeyboards
    • Keyboard types, building keyboard
    • Handle underTheMessage keyboard button click by Alert or Toast
    • Keyboard layouts
  • ⚙ïļConfig
    • CLI
    • Webhooks and run config
    • Api class
    • Modules
      • Mongo module
    • Controller Helper class
  • ðŸĪ–API Reference
    • Set chat action
    • Save user profile photo
    • Ban, unban user or chat
    • Restrict or Promote user
    • Set chat permissions
    • Set chat admin custom title
    • Chat invite links
    • Join requests
    • Update chat info, photo, title, description and more
    • Pin or unpin messages
    • Get chat info, leave chat
    • Check user subscription
    • Chat sticker set
    • My commands
    • My default admin rights
    • Menu button
Powered by GitBook
On this page
  • Install Nestgram
  • Create main file
  • Create app.module.ts
  • Create app.controller.ts
  • Create app.service.ts
  • Run project
  • What's next?

Guide

A guide how to get started with Nestgram

PreviousAbout NestgramNextNews

Last updated 2 years ago

You can read the guide here or on the

Install Nestgram

You need to install nestgram at first. You can do this using yarn or npm

yarn add nestgram@1.9.0
// or
npm i nestgram@1.9.0

Create main file

Our next step is creating the main file, so let's create the main.ts file

main.ts
import { NestGram } from 'nestgram';
import { AppModule } from './app/app.module';

async function bootstrap(): Promise<void> {
  const bot = new NestGram('TOKEN', AppModule);
  await bot.start();
}

bootstrap();

Nestgram class take arguments:

Argument
Name
Required
1

Required

2

Required

3

Optional

4

Optional

Create app.module.ts

Let's create the app.module.ts file. In it, we will describe all available controllers and services

app.module.ts
import { Module } from 'nestgram';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  services: [AppService],
})
export class AppModule {}

At first, we imported Module class from nestgram, AppController and AppService also, that we will create later. Then we described our controllers and services in @Module decorator

Create app.controller.ts

Let's create the app.controller.ts file. In it, we will describe updates, that we want to handle

app.controller.ts
import { OnCommand, Controller } from 'nestgram';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService?: AppService) {}

  @OnCommand('start')
  start(): string {
    return 'Hello, world!';
  }
}

We have created a controller where we describe an update when the user writes /start, and we handle it by sending a message "Hello, world!"

Create app.service.ts

Let's create the app.service.ts file. In it, we will describe methods with working with db, that we will call in controller

app.service.ts
import { Service } from 'nestgram';

@Service()
export class AppService {}

We can describe methods in AppService class, and call it in controller by this.appService

Run project

To run the project, open a terminal in the project directory and type:

npm run dev

Or build and run production:

npm run build && npm run prod

What's next?

At first, we imported nestgram and our AppModule, later we will create it. In the next step, we created a bootstrap function, in which we set up and run the project. The NestGram class gets bot token as 1st parameter (you can get it via ), app module as 2nd parameter, options as 3rd parameter, and as 4th parameter

Bot token. You can get it

Config. or

Now you know about the syntax and structure of the Nestgram project, but if you want to write your own pro bot, you can check out the

📄
BotFather
run config
Nestgram documentation
here
IPollingConfig
IWebhookConfig
App module
Medium
Run config
Nestgram