mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-01-11 14:48:10 +03:00
chore(release): v1.1.0 (#63) from bukhalo/feature/webhooks
Webhooks support
This commit is contained in:
commit
45106e74d9
30
README.md
30
README.md
@ -147,6 +147,36 @@ TelegrafModule.forRootAsync({
|
||||
});
|
||||
```
|
||||
|
||||
## 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(telegrafService.webhookCallback('/secret-path'));
|
||||
```
|
||||
|
||||
The last step is to specify launchOptions in `forRoot` method:
|
||||
```typescript
|
||||
TelegrafModule.forRootAsync({
|
||||
imports: [ConfigModule],
|
||||
useFactory: async (configService: ConfigService) => ({
|
||||
token: configService.get<string>('TELEGRAM_BOT_TOKEN'),
|
||||
launchOptions: {
|
||||
webhook: {
|
||||
domain: 'domain.tld',
|
||||
hookPath: '/secret-path',
|
||||
}
|
||||
}
|
||||
}),
|
||||
inject: [ConfigService],
|
||||
});
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
@ -1,9 +1,17 @@
|
||||
import { ModuleMetadata, Type } from '@nestjs/common/interfaces';
|
||||
import { TelegrafOptions } from 'telegraf';
|
||||
import {
|
||||
TelegrafOptions,
|
||||
LaunchPollingOptions,
|
||||
LaunchWebhookOptions,
|
||||
} from 'telegraf';
|
||||
|
||||
export interface TelegrafModuleOptions {
|
||||
token: string;
|
||||
options?: TelegrafOptions;
|
||||
launchOptions?: {
|
||||
polling?: LaunchPollingOptions;
|
||||
webhook?: LaunchWebhookOptions;
|
||||
};
|
||||
}
|
||||
|
||||
export interface TelegrafOptionsFactory {
|
||||
|
@ -1,5 +1,5 @@
|
||||
export const TELEGRAF_MODULE_OPTIONS = 'TELEGRAF_MODULE_OPTIONS';
|
||||
export const TELEGRAF_PROVIDER = 'TELEGRAF_PROVIDER';
|
||||
export const TELEGRAF_PROVIDER = 'TelegrafProvider';
|
||||
|
||||
export const DECORATORS_PREFIX = 'TELEGRAF';
|
||||
export const DECORATORS = {
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
Logger,
|
||||
OnApplicationShutdown,
|
||||
} from '@nestjs/common';
|
||||
import { Telegraf, ContextMessageUpdate } from 'telegraf';
|
||||
import Telegraf, { ContextMessageUpdate } from 'telegraf';
|
||||
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
||||
import { TelegrafModuleOptions } from './interfaces';
|
||||
|
||||
@ -15,16 +15,19 @@ export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
||||
extends Telegraf<TContext>
|
||||
implements OnApplicationBootstrap, OnApplicationShutdown {
|
||||
private logger = new Logger('Telegraf');
|
||||
private launchOptions;
|
||||
|
||||
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
||||
super(options.token, options.options);
|
||||
this.launchOptions = options.launchOptions;
|
||||
}
|
||||
|
||||
onApplicationBootstrap() {
|
||||
this.catch((e) => {
|
||||
this.logger.error(e);
|
||||
});
|
||||
this.startPolling();
|
||||
|
||||
this.launch(this.launchOptions);
|
||||
}
|
||||
|
||||
async onApplicationShutdown(signal?: string) {
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestjs-telegraf",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestjs-telegraf",
|
||||
"version": "1.0.2",
|
||||
"version": "1.1.0",
|
||||
"description": "Telegraf module for NestJS",
|
||||
"keywords": [
|
||||
"nest",
|
||||
|
Loading…
Reference in New Issue
Block a user