From b1a6e50f8fb2e786f003b5defcb1007f337fd11e Mon Sep 17 00:00:00 2001 From: Alexander Bukhalo Date: Wed, 30 Dec 2020 23:19:54 +0300 Subject: [PATCH] docs(): add standalone applications page, refactoring webhooks page --- .../docs/extras/standalone-applications.md | 27 +++++++++++++++++++ .../docs/{webhooks.md => getting-updates.md} | 16 +++++++---- website/sidebars.js | 3 ++- 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 website/docs/extras/standalone-applications.md rename website/docs/{webhooks.md => getting-updates.md} (79%) diff --git a/website/docs/extras/standalone-applications.md b/website/docs/extras/standalone-applications.md new file mode 100644 index 0000000..0317eea --- /dev/null +++ b/website/docs/extras/standalone-applications.md @@ -0,0 +1,27 @@ +--- +id: standalone-applications +title: Standalone applications +sidebar_label: Standalone applications +slug: standalone-applications +--- + +If you initialized your application with the [Nest CLI](https://docs.nestjs.com/cli/overview), [Express](https://expressjs.com/) framework will be installed by default along with Nest. Nest and NestJS Telegraf does not require Express for work. So if you don't plan to getting bot updates through webhooks, and you don't need a web server, you can remove Express. + +To do this, change the `bootstrap` function in the `main.ts` file of your project on something like that: +```typescript +async function bootstrap() { + const app = await NestFactory.createApplicationContext(AppModule); +} +bootstrap(); +``` + +This initializes Nest as a **standalone application** (without any network listeners). + +All that remains is to remove unused dependencies: +```bash +npm un @nestjs/platform-express @types/express +``` + +:::info +More information about standalone applications located at [Nest documentation](https://docs.nestjs.com/standalone-applications) +::: diff --git a/website/docs/webhooks.md b/website/docs/getting-updates.md similarity index 79% rename from website/docs/webhooks.md rename to website/docs/getting-updates.md index e61c97b..df6e31a 100644 --- a/website/docs/webhooks.md +++ b/website/docs/getting-updates.md @@ -1,12 +1,18 @@ --- -id: webhooks -title: Webhooks -sidebar_label: Webhooks -slug: webhooks +id: getting-updates +title: Getting updates +sidebar_label: Getting updates +slug: getting-updates --- +## Long polling + +By default, the bot receives updates using long-polling and requires no additional action. + +## Webhooks + If you want to configure a telegram bot webhook, you need to get a middleware from `TelegrafProvider` for connect it in your `main.ts` file. - + To access it, you must use the `app.get()` method, followed by the provider reference: ```typescript const telegrafProvider = app.get('TelegrafProvider'); diff --git a/website/sidebars.js b/website/sidebars.js index b45bc2b..9912645 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -2,11 +2,12 @@ module.exports = { docs: { 'Getting Started': [ 'installation', + 'getting-updates', 'telegraf-methods', 'bot-injection', 'async-configuration', - 'webhooks', ], + Extras: ['extras/standalone-applications'], 'API Reference': ['api-reference/decorators'], }, };