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
  • Start bot using webhook
  • Webhook config
  • Webhook/polling config
  • Run config
  1. Config

Webhooks and run config

You can run bot using webhooks

PreviousCLINextApi class

Last updated 2 years ago

Start bot using webhook

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

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
}

Webhook/polling config

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

You can read more about webhook 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 and this config is required (url field). If you're using long polling to run a bot (by default) your config is (config optional)

âš™ī¸
webhooks
ngrok
here
https://core.telegram.org/bots/api#setwebhook
https://core.telegram.org/bots/api#getupdates