Webhooks and run config

You can run bot using webhooks

Start bot using webhook

You can start a bot using webhooks. If you want to use webhooks in development, we recommend to using ngrok

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

async function bootstrap(): Promise<void> {
  const bot = new NestGram(
    'TOKEN', // bot token
    AppModule, // app module
    { url: 'https://mywebhook.com/' }, // webhook config
    { runType: 'webhook', logging: true }, // bot run config
  );
  
  await bot.start();
}

bootstrap();

Webhook config

{
  url: 'https://mywebhook.com/', // Required. Webhook url. If you want to run webhook locally, use ngrok for it. HTTPS only
  port: 80, // Optional. Webhook port. 80 by default. Supports 443, 80, 88, 8443 only
  secret_token: 'my_secret', // Optional. Webhook secret token
}

You can read more about webhook config here

Webhook/polling config

When you create the bot (NestGram class) you can pass config as 3rd argument. If you're using webhook to run a bot, your config is https://core.telegram.org/bots/api#setwebhook and this config is required (url field). If you're using long polling to run a bot (by default) your config is https://core.telegram.org/bots/api#getupdates (config optional)

Run config

You can also pass run config (NestGram options) as 4th argument

Option
Type
Default value
Description

runType

'webhook' | 'polling'

'polling'

How you want to run a bot: webhook or long polling

logging

boolean

true

If true, you will get logs about bot starting and getting updates in console

port

number

80

Port you want to run server using a webhook

fileLogging

boolean

true

If true, you will receive logs of received updates in nestgram/logs.md file

fileLoggingLimit

number

20

Log limit in nestgram/logs.md file

Last updated