From 40490c3f3b34e823a7fa9011b9ff62029ba30898 Mon Sep 17 00:00:00 2001 From: Aleksandr Bukhalo Date: Thu, 5 Aug 2021 12:45:35 +0300 Subject: [PATCH] update docs --- README.md | 16 +++ website/README.md | 33 ------- website/docusaurus.config.js | 30 +----- website/src/pages/index.js | 98 ------------------- website/src/pages/styles.module.css | 37 ------- .../version-1.2.1/async-configuration.md | 60 ------------ .../version-1.2.1/bot-injection.md | 17 ---- .../version-1.2.1/installation.md | 30 ------ .../version-1.2.1/telegraf-methods.md | 46 --------- .../versioned_docs/version-1.2.1/webhooks.md | 35 ------- .../version-1.3.0/api-reference/decorators.md | 23 ----- .../version-1.3.0/async-configuration.md | 60 ------------ .../version-1.3.0/bot-injection.md | 17 ---- .../version-1.3.0/installation.md | 30 ------ .../version-1.3.0/telegraf-methods.md | 46 --------- .../versioned_docs/version-1.3.0/webhooks.md | 35 ------- .../version-2.0.0/async-configuration.md | 60 ------------ .../version-2.0.0/extras/bot-injection.md | 36 ------- .../version-2.0.0/extras/middlewares.md | 13 --- .../version-2.0.0/extras/multiple-bots.md | 74 -------------- .../extras/standalone-applications.md | 27 ----- .../version-2.0.0/getting-updates.md | 44 --------- .../version-2.0.0/installation.md | 28 ------ .../version-2.0.0/migrating/from-v1-to-v2.md | 41 -------- .../version-2.0.0/telegraf-methods.md | 45 --------- .../version-1.2.1-sidebars.json | 31 ------ .../version-1.3.0-sidebars.json | 42 -------- .../version-2.0.0-sidebars.json | 61 ------------ website/versions.json | 5 - 29 files changed, 21 insertions(+), 1099 deletions(-) delete mode 100644 website/README.md delete mode 100644 website/src/pages/index.js delete mode 100644 website/src/pages/styles.module.css delete mode 100644 website/versioned_docs/version-1.2.1/async-configuration.md delete mode 100644 website/versioned_docs/version-1.2.1/bot-injection.md delete mode 100644 website/versioned_docs/version-1.2.1/installation.md delete mode 100644 website/versioned_docs/version-1.2.1/telegraf-methods.md delete mode 100644 website/versioned_docs/version-1.2.1/webhooks.md delete mode 100644 website/versioned_docs/version-1.3.0/api-reference/decorators.md delete mode 100644 website/versioned_docs/version-1.3.0/async-configuration.md delete mode 100644 website/versioned_docs/version-1.3.0/bot-injection.md delete mode 100644 website/versioned_docs/version-1.3.0/installation.md delete mode 100644 website/versioned_docs/version-1.3.0/telegraf-methods.md delete mode 100644 website/versioned_docs/version-1.3.0/webhooks.md delete mode 100644 website/versioned_docs/version-2.0.0/async-configuration.md delete mode 100644 website/versioned_docs/version-2.0.0/extras/bot-injection.md delete mode 100644 website/versioned_docs/version-2.0.0/extras/middlewares.md delete mode 100644 website/versioned_docs/version-2.0.0/extras/multiple-bots.md delete mode 100644 website/versioned_docs/version-2.0.0/extras/standalone-applications.md delete mode 100644 website/versioned_docs/version-2.0.0/getting-updates.md delete mode 100644 website/versioned_docs/version-2.0.0/installation.md delete mode 100644 website/versioned_docs/version-2.0.0/migrating/from-v1-to-v2.md delete mode 100644 website/versioned_docs/version-2.0.0/telegraf-methods.md delete mode 100644 website/versioned_sidebars/version-1.2.1-sidebars.json delete mode 100644 website/versioned_sidebars/version-1.3.0-sidebars.json delete mode 100644 website/versioned_sidebars/version-2.0.0-sidebars.json delete mode 100644 website/versions.json diff --git a/README.md b/README.md index 3f236f2..d896464 100644 --- a/README.md +++ b/README.md @@ -81,3 +81,19 @@ export class AppUpdate { } } ``` + +## Telegraf instance access +If you want to use `Telegraf` instance directly, you can use `@InjectBot` for that. +```typescript +import { Injectable } from '@nestjs/common'; +import { InjectBot } from 'nestjs-telegraf'; +import { Telegraf } from 'telegraf'; +import { TelegrafContext } from '../common/interfaces/telegraf-context.interface.ts'; + +@Injectable() +export class EchoService { + constructor(@InjectBot() private bot: Telegraf) {} + ... +} +``` +See more on a docs page: https://nestjs-telegraf.vercel.app/docs/extras/bot-injection \ No newline at end of file diff --git a/website/README.md b/website/README.md deleted file mode 100644 index ee0ccc9..0000000 --- a/website/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Website - -This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator. - -### Installation - -``` -$ yarn -``` - -### Local Development - -``` -$ yarn start -``` - -This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server. - -### Build - -``` -$ yarn build -``` - -This command generates static content into the `build` directory and can be served using any static contents hosting service. - -### Deployment - -``` -$ GIT_USER= USE_SSH=true yarn deploy -``` - -If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 50c943d..b9ff347 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -5,27 +5,12 @@ module.exports = { baseUrl: '/', onBrokenLinks: 'throw', favicon: 'img/favicon.ico', - organizationName: 'bukhalo', // Usually your GitHub org/user name. - projectName: 'nestjs-telegraf', // Usually your repo name. + organizationName: 'bukhalo', + projectName: 'nestjs-telegraf', themeConfig: { navbar: { title: 'NestJS Telegraf', - // logo: { - // alt: 'My Site Logo', - // src: 'img/logo.svg', - // }, items: [ - { - type: 'docsVersionDropdown', - position: 'left', - }, - { - to: 'docs/', - activeBasePath: 'docs', - label: 'Docs', - position: 'left', - }, - // {to: 'blog', label: 'Blog', position: 'left'}, { href: 'https://github.com/bukhalo/nestjs-telegraf', label: 'GitHub', @@ -41,7 +26,7 @@ module.exports = { items: [ { label: 'Getting Started', - to: 'docs/', + to: '/', }, ], }, @@ -72,7 +57,7 @@ module.exports = { ], }, ], - copyright: `Copyright © 2019 - ${new Date().getFullYear()}, Alexander Bukhalo & Arthur Asimov.`, + copyright: `Copyright © 2019 - ${new Date().getFullYear()}, Alexander Bukhalo, Arthur Asimov and Others.`, }, }, presets: [ @@ -81,17 +66,12 @@ module.exports = { { docs: { sidebarPath: require.resolve('./sidebars.js'), + routeBasePath: '/', editUrl: 'https://github.com/bukhalo/nestjs-telegraf/edit/master/website/', showLastUpdateAuthor: true, showLastUpdateTime: true, }, - // blog: { - // showReadingTime: true, - // // Please change this to your repo. - // editUrl: - // 'https://github.com/bukhalo/nestjs-telegraf/edit/master/website/blog/', - // }, theme: { customCss: require.resolve('./src/css/custom.css'), }, diff --git a/website/src/pages/index.js b/website/src/pages/index.js deleted file mode 100644 index b261c66..0000000 --- a/website/src/pages/index.js +++ /dev/null @@ -1,98 +0,0 @@ -import React from 'react'; -import clsx from 'clsx'; -import Layout from '@theme/Layout'; -import Link from '@docusaurus/Link'; -import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; -import useBaseUrl from '@docusaurus/useBaseUrl'; -import styles from './styles.module.css'; - -const features = [ - { - title: 'Easy to Use', - imageUrl: 'img/undraw_docusaurus_mountain.svg', - description: ( - <> - Docusaurus was designed from the ground up to be easily installed and - used to get your website up and running quickly. - - ), - }, - { - title: 'Focus on What Matters', - imageUrl: 'img/undraw_docusaurus_tree.svg', - description: ( - <> - Docusaurus lets you focus on your docs, and we'll do the chores. Go - ahead and move your docs into the docs directory. - - ), - }, - { - title: 'Powered by React', - imageUrl: 'img/undraw_docusaurus_react.svg', - description: ( - <> - Extend or customize your website layout by reusing React. Docusaurus can - be extended while reusing the same header and footer. - - ), - }, -]; - -function Feature({imageUrl, title, description}) { - const imgUrl = useBaseUrl(imageUrl); - return ( -
- {imgUrl && ( -
- {title} -
- )} -

{title}

-

{description}

-
- ); -} - -function Home() { - const context = useDocusaurusContext(); - const {siteConfig = {}} = context; - return ( - -
-
-

{siteConfig.title}

-

{siteConfig.tagline}

-
- - Get Started - -
-
-
-
- {/* {features && features.length > 0 && ( -
-
-
- {features.map((props, idx) => ( - - ))} -
-
-
- )} - */} -
-
- ); -} - -export default Home; diff --git a/website/src/pages/styles.module.css b/website/src/pages/styles.module.css deleted file mode 100644 index c1aa851..0000000 --- a/website/src/pages/styles.module.css +++ /dev/null @@ -1,37 +0,0 @@ -/* stylelint-disable docusaurus/copyright-header */ - -/** - * CSS files with the .module.css suffix will be treated as CSS modules - * and scoped locally. - */ - -.heroBanner { - padding: 4rem 0; - text-align: center; - position: relative; - overflow: hidden; -} - -@media screen and (max-width: 966px) { - .heroBanner { - padding: 2rem; - } -} - -.buttons { - display: flex; - align-items: center; - justify-content: center; -} - -.features { - display: flex; - align-items: center; - padding: 2rem 0; - width: 100%; -} - -.featureImage { - height: 200px; - width: 200px; -} diff --git a/website/versioned_docs/version-1.2.1/async-configuration.md b/website/versioned_docs/version-1.2.1/async-configuration.md deleted file mode 100644 index 14414f0..0000000 --- a/website/versioned_docs/version-1.2.1/async-configuration.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -id: async-configuration -title: Async configuration -sidebar_label: Async configuration -slug: /async-configuration ---- - -When you need to pass module options asynchronously instead of statically, use the forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration. - -One technique is to use a factory function: - -```typescript -TelegrafModule.forRootAsync({ - useFactory: () => ({ - token: 'TELEGRAM_BOT_TOKEN', - }), -}); -``` - -Like other [factory providers](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory), our factory function can be async and can inject dependencies through inject. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useFactory: async (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - }), - inject: [ConfigService], -}); -``` - -Alternatively, you can configure the TelegrafModule using a class instead of a factory, as shown below: - -```typescript -TelegrafModule.forRootAsync({ - useClass: TelegrafConfigService, -}); -``` - -The construction above instantiates `TelegrafConfigService` inside `TelegrafModule`, using it to create the required options object. Note that in this example, the `TelegrafConfigService` has to implement the `TelegrafOptionsFactory` interface, as shown below. The `TelegrafModule` will call the `createTelegrafOptions()` method on the instantiated object of the supplied class. - -```typescript -@Injectable() -class TelegrafConfigService implements TelegrafOptionsFactory { - createTelegrafOptions(): TelegrafModuleOptions { - return { - token: 'TELEGRAM_BOT_TOKEN', - }; - } -} -``` - -If you want to reuse an existing options provider instead of creating a private copy inside the `TelegrafModule`, use the `useExisting` syntax. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useExisting: ConfigService, -}); -``` diff --git a/website/versioned_docs/version-1.2.1/bot-injection.md b/website/versioned_docs/version-1.2.1/bot-injection.md deleted file mode 100644 index 8aa67df..0000000 --- a/website/versioned_docs/version-1.2.1/bot-injection.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -id: bot-injection -title: Bot injection -sidebar_label: Bot injection -slug: /bot-injection ---- - -At times you may need to access the native `Telegraf` instance. For example, you may want to connect stage middleware. You can inject the Telegraf by using the `@InjectBot()` decorator as follows: -```typescript -import { Injectable } from '@nestjs/common'; -import { InjectBot, TelegrafProvider } from 'nestjs-telegraf'; - -@Injectable() -export class BotSettingsService { - constructor(@InjectBot() private bot: TelegrafProvider) {} -} -``` diff --git a/website/versioned_docs/version-1.2.1/installation.md b/website/versioned_docs/version-1.2.1/installation.md deleted file mode 100644 index 22cd71c..0000000 --- a/website/versioned_docs/version-1.2.1/installation.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -id: installation -title: Installation -sidebar_label: Installation -slug: / ---- - -```bash -$ npm i nestjs-telegraf -``` - -Once the installation process is complete, we can import the TelegrafModule into the root AppModule. - -```typescript -/* app.module.ts */ - -import { Module } from '@nestjs/common'; -import { TelegrafModule } from 'nestjs-telegraf'; - -@Module({ - imports: [ - TelegrafModule.forRoot({ - token: 'TELEGRAM_BOT_TOKEN', - }) - ], -}) -export class AppModule {} -``` - -The `forRoot()` method accepts the same configuration object as Telegraf class constructor from the Telegraf package, as described [here](https://telegraf.js.org/#/?id=constructor). diff --git a/website/versioned_docs/version-1.2.1/telegraf-methods.md b/website/versioned_docs/version-1.2.1/telegraf-methods.md deleted file mode 100644 index 76eb837..0000000 --- a/website/versioned_docs/version-1.2.1/telegraf-methods.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -id: telegraf-methods -title: Telegraf methods -sidebar_label: Telegraf methods -slug: /telegraf-methods ---- - -Each Telegraf instance method described [here](https://telegraf.js.org/#/?id=telegraf) has own decorator in `nestjs-telegraf` package. The name of the decorator corresponds to the name of the Telegraf method. For example [`@TelegrafHears`](https://telegraf.js.org/#/?id=hears), [`@TelegrafOn`](https://telegraf.js.org/#/?id=on), [`@TelegrafAction`](https://telegraf.js.org/#/?id=action) and so on. - -Now let's try to repeat the example from the Telegraf [documentation page](https://telegraf.js.org/#/?id=example). - -```typescript -/* app.service.ts */ - -import { Injectable } from '@nestjs/common'; -import { - TelegrafStart, - TelegrafHelp, - TelegrafOn, - TelegrafHears, - Context, -} from 'nestjs-telegraf'; - -@Injectable() -export class AppService { - @TelegrafStart() - start(ctx: Context) { - ctx.reply('Welcome'); - } - - @TelegrafHelp() - help(ctx: Context) { - ctx.reply('Send me a sticker'); - } - - @TelegrafOn('sticker') - on(ctx: Context) { - ctx.reply('👍'); - } - - @TelegrafHears('hi') - hears(ctx: Context) { - ctx.reply('Hey there'); - } -} -``` diff --git a/website/versioned_docs/version-1.2.1/webhooks.md b/website/versioned_docs/version-1.2.1/webhooks.md deleted file mode 100644 index e61c97b..0000000 --- a/website/versioned_docs/version-1.2.1/webhooks.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -id: webhooks -title: Webhooks -sidebar_label: Webhooks -slug: 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'); -``` - -Now you can connect middleware: -```typescript -app.use(telegrafProvider.webhookCallback('/secret-path')); -``` - -The last step is to specify launchOptions in `forRoot` method: -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useFactory: async (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - launchOptions: { - webhook: { - domain: 'domain.tld', - hookPath: '/secret-path', - } - } - }), - inject: [ConfigService], -}); -``` diff --git a/website/versioned_docs/version-1.3.0/api-reference/decorators.md b/website/versioned_docs/version-1.3.0/api-reference/decorators.md deleted file mode 100644 index 37cce22..0000000 --- a/website/versioned_docs/version-1.3.0/api-reference/decorators.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -id: decorators -title: Decorators -sidebar_label: Decorators -slug: /api-reference/decorators ---- - -:::caution -The described functionality is under development, the functionality has not been tested and can be changed at any time! -::: - -### Update - -`@Update` class decorator, it's like NestJS [`@Controller`](https://docs.nestjs.com/controllers) decorator, but for [Telegram Bot API updates](https://core.telegram.org/bots/api#getting-updates). Reserved for future use. - -```typescript {3} -import { Update, Context } from 'nestjs-telegraf'; - -@Update() -export class SomeBotService { - ... -} -``` diff --git a/website/versioned_docs/version-1.3.0/async-configuration.md b/website/versioned_docs/version-1.3.0/async-configuration.md deleted file mode 100644 index 14414f0..0000000 --- a/website/versioned_docs/version-1.3.0/async-configuration.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -id: async-configuration -title: Async configuration -sidebar_label: Async configuration -slug: /async-configuration ---- - -When you need to pass module options asynchronously instead of statically, use the forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration. - -One technique is to use a factory function: - -```typescript -TelegrafModule.forRootAsync({ - useFactory: () => ({ - token: 'TELEGRAM_BOT_TOKEN', - }), -}); -``` - -Like other [factory providers](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory), our factory function can be async and can inject dependencies through inject. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useFactory: async (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - }), - inject: [ConfigService], -}); -``` - -Alternatively, you can configure the TelegrafModule using a class instead of a factory, as shown below: - -```typescript -TelegrafModule.forRootAsync({ - useClass: TelegrafConfigService, -}); -``` - -The construction above instantiates `TelegrafConfigService` inside `TelegrafModule`, using it to create the required options object. Note that in this example, the `TelegrafConfigService` has to implement the `TelegrafOptionsFactory` interface, as shown below. The `TelegrafModule` will call the `createTelegrafOptions()` method on the instantiated object of the supplied class. - -```typescript -@Injectable() -class TelegrafConfigService implements TelegrafOptionsFactory { - createTelegrafOptions(): TelegrafModuleOptions { - return { - token: 'TELEGRAM_BOT_TOKEN', - }; - } -} -``` - -If you want to reuse an existing options provider instead of creating a private copy inside the `TelegrafModule`, use the `useExisting` syntax. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useExisting: ConfigService, -}); -``` diff --git a/website/versioned_docs/version-1.3.0/bot-injection.md b/website/versioned_docs/version-1.3.0/bot-injection.md deleted file mode 100644 index 8aa67df..0000000 --- a/website/versioned_docs/version-1.3.0/bot-injection.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -id: bot-injection -title: Bot injection -sidebar_label: Bot injection -slug: /bot-injection ---- - -At times you may need to access the native `Telegraf` instance. For example, you may want to connect stage middleware. You can inject the Telegraf by using the `@InjectBot()` decorator as follows: -```typescript -import { Injectable } from '@nestjs/common'; -import { InjectBot, TelegrafProvider } from 'nestjs-telegraf'; - -@Injectable() -export class BotSettingsService { - constructor(@InjectBot() private bot: TelegrafProvider) {} -} -``` diff --git a/website/versioned_docs/version-1.3.0/installation.md b/website/versioned_docs/version-1.3.0/installation.md deleted file mode 100644 index 22cd71c..0000000 --- a/website/versioned_docs/version-1.3.0/installation.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -id: installation -title: Installation -sidebar_label: Installation -slug: / ---- - -```bash -$ npm i nestjs-telegraf -``` - -Once the installation process is complete, we can import the TelegrafModule into the root AppModule. - -```typescript -/* app.module.ts */ - -import { Module } from '@nestjs/common'; -import { TelegrafModule } from 'nestjs-telegraf'; - -@Module({ - imports: [ - TelegrafModule.forRoot({ - token: 'TELEGRAM_BOT_TOKEN', - }) - ], -}) -export class AppModule {} -``` - -The `forRoot()` method accepts the same configuration object as Telegraf class constructor from the Telegraf package, as described [here](https://telegraf.js.org/#/?id=constructor). diff --git a/website/versioned_docs/version-1.3.0/telegraf-methods.md b/website/versioned_docs/version-1.3.0/telegraf-methods.md deleted file mode 100644 index aa39a30..0000000 --- a/website/versioned_docs/version-1.3.0/telegraf-methods.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -id: telegraf-methods -title: Telegraf methods -sidebar_label: Telegraf methods -slug: /telegraf-methods ---- - -Each Telegraf instance method described [here](https://telegraf.js.org/#/?id=telegraf) has own decorator in `nestjs-telegraf` package. The name of the decorator corresponds to the name of the Telegraf method. For example [`@Hears`](https://telegraf.js.org/#/?id=hears), [`@On`](https://telegraf.js.org/#/?id=on), [`@Action`](https://telegraf.js.org/#/?id=action) and so on. - -Now let's try to repeat the example from the Telegraf [documentation page](https://telegraf.js.org/#/?id=example). - -```typescript -/* app.service.ts */ - -import { Injectable } from '@nestjs/common'; -import { - Start, - Help, - On, - Hears, - Context, -} from 'nestjs-telegraf'; - -@Injectable() -export class AppService { - @Start() - start(ctx: Context) { - ctx.reply('Welcome'); - } - - @Help() - help(ctx: Context) { - ctx.reply('Send me a sticker'); - } - - @On('sticker') - on(ctx: Context) { - ctx.reply('👍'); - } - - @Hears('hi') - hears(ctx: Context) { - ctx.reply('Hey there'); - } -} -``` diff --git a/website/versioned_docs/version-1.3.0/webhooks.md b/website/versioned_docs/version-1.3.0/webhooks.md deleted file mode 100644 index e61c97b..0000000 --- a/website/versioned_docs/version-1.3.0/webhooks.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -id: webhooks -title: Webhooks -sidebar_label: Webhooks -slug: 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'); -``` - -Now you can connect middleware: -```typescript -app.use(telegrafProvider.webhookCallback('/secret-path')); -``` - -The last step is to specify launchOptions in `forRoot` method: -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useFactory: async (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - launchOptions: { - webhook: { - domain: 'domain.tld', - hookPath: '/secret-path', - } - } - }), - inject: [ConfigService], -}); -``` diff --git a/website/versioned_docs/version-2.0.0/async-configuration.md b/website/versioned_docs/version-2.0.0/async-configuration.md deleted file mode 100644 index 14414f0..0000000 --- a/website/versioned_docs/version-2.0.0/async-configuration.md +++ /dev/null @@ -1,60 +0,0 @@ ---- -id: async-configuration -title: Async configuration -sidebar_label: Async configuration -slug: /async-configuration ---- - -When you need to pass module options asynchronously instead of statically, use the forRootAsync() method. As with most dynamic modules, Nest provides several techniques to deal with async configuration. - -One technique is to use a factory function: - -```typescript -TelegrafModule.forRootAsync({ - useFactory: () => ({ - token: 'TELEGRAM_BOT_TOKEN', - }), -}); -``` - -Like other [factory providers](https://docs.nestjs.com/fundamentals/custom-providers#factory-providers-usefactory), our factory function can be async and can inject dependencies through inject. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useFactory: async (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - }), - inject: [ConfigService], -}); -``` - -Alternatively, you can configure the TelegrafModule using a class instead of a factory, as shown below: - -```typescript -TelegrafModule.forRootAsync({ - useClass: TelegrafConfigService, -}); -``` - -The construction above instantiates `TelegrafConfigService` inside `TelegrafModule`, using it to create the required options object. Note that in this example, the `TelegrafConfigService` has to implement the `TelegrafOptionsFactory` interface, as shown below. The `TelegrafModule` will call the `createTelegrafOptions()` method on the instantiated object of the supplied class. - -```typescript -@Injectable() -class TelegrafConfigService implements TelegrafOptionsFactory { - createTelegrafOptions(): TelegrafModuleOptions { - return { - token: 'TELEGRAM_BOT_TOKEN', - }; - } -} -``` - -If you want to reuse an existing options provider instead of creating a private copy inside the `TelegrafModule`, use the `useExisting` syntax. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - useExisting: ConfigService, -}); -``` diff --git a/website/versioned_docs/version-2.0.0/extras/bot-injection.md b/website/versioned_docs/version-2.0.0/extras/bot-injection.md deleted file mode 100644 index c322288..0000000 --- a/website/versioned_docs/version-2.0.0/extras/bot-injection.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -id: bot-injection -title: Bot injection -sidebar_label: Bot injection -slug: /extras/bot-injection ---- - -At times you may need to access the native `Telegraf` instance. You can inject the Telegraf by using the `@InjectBot()` decorator as follows: - -```typescript {8} title="src/echo/echo.service.ts" -import { Injectable } from '@nestjs/common'; -import { InjectBot } from 'nestjs-telegraf'; -import { Telegraf } from 'telegraf'; -import { TelegrafContext } from '../common/interfaces/telegraf-context.interface.ts'; - -@Injectable() -export class EchoService { - constructor(@InjectBot() private bot: Telegraf) {} - ... -} -``` - -If you run [multiple bots](/docs/extras/multiple-bots) in the same application, explicitly specify the bot name: - -```typescript {8} title="src/echo/echo.service.ts" -import { Injectable } from '@nestjs/common'; -import { InjectBot } from 'nestjs-telegraf'; -import { Telegraf } from 'telegraf'; -import { TelegrafContext } from '../common/interfaces/telegraf-context.interface.ts'; - -@Injectable() -export class EchoService { - constructor(@InjectBot('cats') private bot: Telegraf) {} - ... -} -``` \ No newline at end of file diff --git a/website/versioned_docs/version-2.0.0/extras/middlewares.md b/website/versioned_docs/version-2.0.0/extras/middlewares.md deleted file mode 100644 index b2fe2b7..0000000 --- a/website/versioned_docs/version-2.0.0/extras/middlewares.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -id: middlewares -title: Middlewares -sidebar_label: Middlewares -slug: /extras/middlewares ---- - -`nestjs-telegraf` has support of the Telegraf middleware packages. To use an existing middleware package, simply import it and add it to the middlewares array: -```typescript -TelegrafModule.forRoot({ - middlewares: [session()], -}), -``` diff --git a/website/versioned_docs/version-2.0.0/extras/multiple-bots.md b/website/versioned_docs/version-2.0.0/extras/multiple-bots.md deleted file mode 100644 index 5347730..0000000 --- a/website/versioned_docs/version-2.0.0/extras/multiple-bots.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -id: multiple-bots -title: Multiple bots -sidebar_label: Multiple bots -slug: /extras/multiple-bots ---- - -In some cases, you may need to run multiple bots at the same time. This can also be achieved with this module. To work with multiple bots, first create the bots. In this case, bot naming becomes mandatory. -```typescript -import { Module } from '@nestjs/common'; -import { ConfigModule } from '@nestjs/config'; -import { TelegrafModule } from 'nestjs-telegraf'; - -@Module({ - imports: [ - ConfigModule.forRoot(), - TelegrafModule.forRootAsync({ - imports: [ConfigModule], - botName: 'cat', - useFactory: (configService: ConfigService) => ({ - token: configService.get('CAT_BOT_TOKEN'), - }), - inject: [ConfigService], - }), - TelegrafModule.forRootAsync({ - imports: [ConfigModule.forFeature(telegrafModuleConfig)], - botName: 'dog', - useFactory: async (configService: ConfigService) => ({ - token: configService.get('DOG_BOT_TOKEN'), - }), - inject: [ConfigService], - }), - ], -}) -export class AppModule {} -``` - -:::caution -Please note that you shouldn't have multiple bots without a name, or with the same name, otherwise they will get overridden. -::: - -You can also inject the `Bot` for a given bot: -```typescript -import { Injectable } from '@nestjs/common'; -import { InjectBot, Telegraf, Context } from 'nestjs-telegraf'; - -@Injectable() -export class EchoService { - constructor(@InjectBot('cat') private catBot: Telegraf) {} -} -``` -To inject a given `Bot` to a custom provider (for example, factory provider), use the `getBotToken()` function passing the name of the bot as an argument. -```typescript -{ - provide: CatsService, - useFactory: (catBot: Telegraf) => { - return new CatsService(catBot); - }, - inject: [getBotToken('cat')], -} -``` -Another useful feature of the `nestjs-telegraf` module is the ability to choose which modules should handle updates for each launched bot. By default, module searches for handlers throughout the whole app. To limit this scan to only a subset of modules, use the include property. - -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule], - botName: 'cat', - useFactory: (configService: ConfigService) => ({ - token: configService.get('CAT_BOT_TOKEN'), - include: [CatsModule], - }), - inject: [ConfigService], -}), -``` diff --git a/website/versioned_docs/version-2.0.0/extras/standalone-applications.md b/website/versioned_docs/version-2.0.0/extras/standalone-applications.md deleted file mode 100644 index 0317eea..0000000 --- a/website/versioned_docs/version-2.0.0/extras/standalone-applications.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -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/versioned_docs/version-2.0.0/getting-updates.md b/website/versioned_docs/version-2.0.0/getting-updates.md deleted file mode 100644 index a42d3fe..0000000 --- a/website/versioned_docs/version-2.0.0/getting-updates.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -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 via `getBotToken` helper in your `main.ts` file. - -To access it, you must use the `app.get()` method, followed by the provider reference: -```typescript -import { getBotToken } from 'nestjs-telegraf'; - -// ... -const bot = app.get(getBotToken()); -``` - -Now you can connect middleware: -```typescript -app.use(bot.webhookCallback('/secret-path')); -``` - -The last step is to specify launchOptions in `forRoot` method: -```typescript -TelegrafModule.forRootAsync({ - imports: [ConfigModule], - useFactory: (configService: ConfigService) => ({ - token: configService.get('TELEGRAM_BOT_TOKEN'), - launchOptions: { - webhook: { - domain: 'domain.tld', - hookPath: '/secret-path', - } - } - }), - inject: [ConfigService], -}); -``` diff --git a/website/versioned_docs/version-2.0.0/installation.md b/website/versioned_docs/version-2.0.0/installation.md deleted file mode 100644 index 87f976b..0000000 --- a/website/versioned_docs/version-2.0.0/installation.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -id: installation -title: Installation -sidebar_label: Installation -slug: / ---- - -```bash -$ npm i nestjs-telegraf telegraf -``` - -Once the installation process is complete, we can import the `TelegrafModule` into the root `AppModule`. - -```typescript title="src/app.module.ts" -import { Module } from '@nestjs/common'; -import { TelegrafModule } from 'nestjs-telegraf'; - -@Module({ - imports: [ - TelegrafModule.forRoot({ - token: 'TELEGRAM_BOT_TOKEN', - }) - ], -}) -export class AppModule {} -``` - -The `forRoot()` method accepts the same configuration object as Telegraf class constructor from the Telegraf package, as described [here](https://telegraf.js.org/#/?id=constructor). diff --git a/website/versioned_docs/version-2.0.0/migrating/from-v1-to-v2.md b/website/versioned_docs/version-2.0.0/migrating/from-v1-to-v2.md deleted file mode 100644 index 742f525..0000000 --- a/website/versioned_docs/version-2.0.0/migrating/from-v1-to-v2.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -id: from-v1-to-v2 -title: From v1 to v2 -sidebar_label: From v1 to v2 -slug: /migrating/from-v1-to-v2 ---- - -## Remove `Telegraf` prefix -If you previously used decorators with the prefix `Telegraf` in the decorator name (such as `@TelegrafOn()` or `@TelegrafHelp()`) replace them with the same decorators but without the prefix `Telegraf`, such as `@On()`, `@Start()`, `@Command()` and so on. - -## `@Update()` decorator -Since v2, `nestjs-telegraf` looks for all update handlers only inside individual classes, under the `@Update()` decorator. - -Previously, you could declare a handler anywhere, for example: -```typescript title="src/cats/cats.provider.ts" -import { Injectable } from '@nestjs/common'; -import { Command } from 'nestjs-telegraf'; - -@Injectable() -export class CatsProvider { - @Command('cats') - async helpCommand(ctx: TelegrafContext) { - await ctx.reply('Meow.'); - } -} -``` - -Now you must explicitly bind the class, for Telegram Bot Api update handlers: -```typescript {3} title="src/cats/cats.updates.ts" -import { Update, Ctx } from 'nestjs-telegraf'; - -@Update() -export class HelpUpdate { - @Command('help') - async helpCommand(@Ctx() ctx: TelegrafContext) { - await ctx.reply('Help command.'); - } -} -``` - -Treat the `@Update()` decorator like the `@Controller()` decorator, but to capture Telegram Bot Api updates. diff --git a/website/versioned_docs/version-2.0.0/telegraf-methods.md b/website/versioned_docs/version-2.0.0/telegraf-methods.md deleted file mode 100644 index a9bb1ac..0000000 --- a/website/versioned_docs/version-2.0.0/telegraf-methods.md +++ /dev/null @@ -1,45 +0,0 @@ ---- -id: telegraf-methods -title: Telegraf methods -sidebar_label: Telegraf methods -slug: /telegraf-methods ---- - -Each Telegraf instance method has own decorator in `nestjs-telegraf` package. The name of the decorator corresponds to the name of the Telegraf method. For example [`@Hears`](https://telegraf.js.org/classes/telegraf.html#hears), [`@On`](https://telegraf.js.org/classes/telegraf.html#on), [`@Action`](https://telegraf.js.org/classes/telegraf.html#action) and so on. - -Now let's try simple example: - -```typescript title="src/app.update.ts" -import { - Update, - Ctx, - Start, - Help, - On, - Hears, -} from 'nestjs-telegraf'; -import { TelegrafContext } from './common/interfaces/telegraf-context.interface.ts'; - -@Update() -export class AppUpdate { - @Start() - async start(@Ctx() ctx: TelegrafContext) { - await ctx.reply('Welcome'); - } - - @Help() - async help(@Ctx() ctx: TelegrafContext) { - await ctx.reply('Send me a sticker'); - } - - @On('sticker') - async on(@Ctx() ctx: TelegrafContext) { - await ctx.reply('👍'); - } - - @Hears('hi') - async hears(@Ctx() ctx: TelegrafContext) { - await ctx.reply('Hey there'); - } -} -``` diff --git a/website/versioned_sidebars/version-1.2.1-sidebars.json b/website/versioned_sidebars/version-1.2.1-sidebars.json deleted file mode 100644 index ab75657..0000000 --- a/website/versioned_sidebars/version-1.2.1-sidebars.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "version-1.2.1/docs": [ - { - "collapsed": true, - "type": "category", - "label": "Getting Started", - "items": [ - { - "type": "doc", - "id": "version-1.2.1/installation" - }, - { - "type": "doc", - "id": "version-1.2.1/telegraf-methods" - }, - { - "type": "doc", - "id": "version-1.2.1/bot-injection" - }, - { - "type": "doc", - "id": "version-1.2.1/async-configuration" - }, - { - "type": "doc", - "id": "version-1.2.1/webhooks" - } - ] - } - ] -} diff --git a/website/versioned_sidebars/version-1.3.0-sidebars.json b/website/versioned_sidebars/version-1.3.0-sidebars.json deleted file mode 100644 index 0fb93aa..0000000 --- a/website/versioned_sidebars/version-1.3.0-sidebars.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version-1.3.0/docs": [ - { - "collapsed": false, - "type": "category", - "label": "Getting Started", - "items": [ - { - "type": "doc", - "id": "version-1.3.0/installation" - }, - { - "type": "doc", - "id": "version-1.3.0/telegraf-methods" - }, - { - "type": "doc", - "id": "version-1.3.0/bot-injection" - }, - { - "type": "doc", - "id": "version-1.3.0/async-configuration" - }, - { - "type": "doc", - "id": "version-1.3.0/webhooks" - } - ] - }, - { - "collapsed": true, - "type": "category", - "label": "API Reference", - "items": [ - { - "type": "doc", - "id": "version-1.3.0/api-reference/decorators" - } - ] - } - ] -} diff --git a/website/versioned_sidebars/version-2.0.0-sidebars.json b/website/versioned_sidebars/version-2.0.0-sidebars.json deleted file mode 100644 index ea978d1..0000000 --- a/website/versioned_sidebars/version-2.0.0-sidebars.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "version-2.0.0/docs": [ - { - "collapsed": true, - "type": "category", - "label": "Getting Started", - "items": [ - { - "type": "doc", - "id": "version-2.0.0/installation" - }, - { - "type": "doc", - "id": "version-2.0.0/getting-updates" - }, - { - "type": "doc", - "id": "version-2.0.0/telegraf-methods" - }, - { - "type": "doc", - "id": "version-2.0.0/async-configuration" - } - ] - }, - { - "collapsed": true, - "type": "category", - "label": "Extras", - "items": [ - { - "type": "doc", - "id": "version-2.0.0/extras/bot-injection" - }, - { - "type": "doc", - "id": "version-2.0.0/extras/middlewares" - }, - { - "type": "doc", - "id": "version-2.0.0/extras/multiple-bots" - }, - { - "type": "doc", - "id": "version-2.0.0/extras/standalone-applications" - } - ] - }, - { - "collapsed": true, - "type": "category", - "label": "Migrating", - "items": [ - { - "type": "doc", - "id": "version-2.0.0/migrating/from-v1-to-v2" - } - ] - } - ] -} diff --git a/website/versions.json b/website/versions.json deleted file mode 100644 index 2e24c4b..0000000 --- a/website/versions.json +++ /dev/null @@ -1,5 +0,0 @@ -[ - "2.0.0", - "1.3.0", - "1.2.1" -]