📄Guide

A guide how to get started with Nestgram

Nestgram

You can read the guide here or on the Medium

Install Nestgram

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

Create main file

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

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 BotFather), app module as 2nd parameter, options as 3rd parameter, and run config as 4th parameter

Nestgram class take arguments:

Argument
Name
Required
1

Bot token. You can get it here

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

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

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

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:

Or build and run production:

What's next?

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 Nestgram documentation

Last updated