Skip to content

Commit 8c6adc2

Browse files
committed
chore: --fetch-preconnect
1 parent bc490bd commit 8c6adc2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

docs/bot-api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,17 @@ And logs will looks like:
187187
[fetch] < Server: EOS (vny/044F)
188188
[fetch] < Content-Length: 1256
189189
```
190+
191+
### Bun startup optimization: --fetch-preconnect
192+
193+
If you are running your bot with Bun, you can use the CLI flag `--fetch-preconnect=<url>` to speed up the first network request to Telegram servers. This flag tells Bun to start establishing the connection (DNS, TCP, TLS) to the specified host before your code runs, so the first API call is faster.
194+
195+
Example:
196+
197+
```bash
198+
bun --fetch-preconnect=https://api.telegram.org:443/ ./src/bot.ts
199+
```
200+
201+
This is especially useful for bots where the first thing you do is call the Telegram API. With this flag, Bun will "warm up" the connection at startup, so your bot will be ready to send requests with less delay. The overall startup time may increase slightly, but the time to first successful API call will decrease. In most cases this is not an issue, but the benefit is less noticeable if the first request is sent immediately after the process starts.
202+
203+
See more in the [Bun documentation](https://bun.sh/docs/api/fetch#preconnect-to-a-host).

docs/bot-class.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ head:
99
- - meta
1010
- name: "keywords"
1111
content: telegram bot, framework, how to create a bot, Telegram, Telegram Bot API, GramIO, TypeScript, JavaScript, Node.JS, Nodejs, Deno, Bun, Bot class, bot instance, bot configuration, bot initialization, bot token, bot methods, update handling, bot middleware, event listeners, on method, command method, webhook setup, bot polling, bot lifecycle
12-
1312
---
1413

1514
# Main bot class

docs/ru/bot-api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,17 @@ BUN_CONFIG_VERBOSE_FETCH=curl bun src/index.ts
191191
[fetch] < Server: EOS (vny/044F)
192192
[fetch] < Content-Length: 1256
193193
```
194+
195+
### Оптимизация старта вместе с Bun: --fetch-preconnect
196+
197+
Если вы запускаете своего бота с помощью Bun, вы можете использовать CLI-флаг `--fetch-preconnect=<url>`, чтобы ускорить первый сетевой запрос к серверам Telegram. Этот флаг сообщает Bun начать устанавливать соединение (DNS, TCP, TLS) с указанным хостом до запуска вашего кода, чтобы первый API-запрос был быстрее.
198+
199+
Пример:
200+
201+
```bash
202+
bun --fetch-preconnect=https://api.telegram.org:443/ ./src/bot.ts
203+
```
204+
205+
Это особенно полезно для ботов, где первое действие — обращение к Telegram API. С этим флагом Bun "разогреет" соединение на этапе старта, и ваш бот будет готов отправлять запросы с меньшей задержкой. Общее время старта может немного увеличиться, но время до первого успешного API-запроса уменьшится. В основном это не мешает, но меньше ощущается когда первый запрос отправляется сразу после запуска процесса.
206+
207+
Подробнее в [документации Bun](https://bun.sh/docs/api/fetch#preconnect-to-a-host).

docs/ru/plugins/official/scenes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ const bot = new Bot(process.env.TOKEN as string)
403403
404404
<!-- TODO: Translate any new or changed sections from docs/plugins/official/scenes.md if missed above. -->
405405

406-
По умолчанию при регистрации плагина `scenes()` используется `inMemoryStorage`. Так что когда вам необходимо использовать `scenesDerives()` для управления сценами, вы должны сами объявить `inMemoryStorage` и явно указать его в опциях `scenesDerives()` и `scenes()`.
406+
По умолчанию при регистрации плагина `scenes()` используется `inMemoryStorage`. Поэтому если вам нужно использовать `scenesDerives()` для управления сценами, необходимо явно объявить `inMemoryStorage` и явно указать его в опциях как для `scenesDerives()`, так и для `scenes()`.
407407

408408
```ts
409+
import { inMemoryStorage } from "@gramio/storage";
410+
409411
const storage = inMemoryStorage(); // Хранит в памяти процесса и будет стёрто при перезапуске
410412

411413
const bot = new Bot(process.env.TOKEN as string)

0 commit comments

Comments
 (0)