> For the complete documentation index, see [llms.txt](https://degreetpro.gitbook.io/nestgram/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://degreetpro.gitbook.io/nestgram/config/webhooks-and-run-config.md).

# Webhooks and run config

## Start bot using webhook

You can start a bot using [webhooks](https://core.telegram.org/bots/api#setwebhook). If you want to use webhooks in development, we recommend to using [ngrok](https://ngrok.com/)

{% code title="main.ts" %}

```typescript
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();
```

{% endcode %}

## Webhook config

```typescript
{
  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](https://core.telegram.org/bots/api#setwebhook)

## 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

<table><thead><tr><th width="184.58136007759995">Option</th><th width="192.99555501631306">Type</th><th width="150">Default value</th><th>Description</th></tr></thead><tbody><tr><td>runType</td><td>'webhook' | 'polling'</td><td>'polling'</td><td>How you want to run a bot: webhook or long polling</td></tr><tr><td>logging</td><td>boolean</td><td>true</td><td>If true, you will get logs about bot starting and getting updates in console</td></tr><tr><td>port</td><td>number</td><td>80</td><td>Port you want to run server using a webhook</td></tr><tr><td>fileLogging</td><td>boolean</td><td>true</td><td>If true, you will receive logs of received updates in nestgram/logs.md file</td></tr><tr><td>fileLoggingLimit</td><td>number</td><td>20</td><td>Log limit in nestgram/logs.md file</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://degreetpro.gitbook.io/nestgram/config/webhooks-and-run-config.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
