mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat: upgrade telegraf package to the latest version
This commit is contained in:
parent
2133594688
commit
aece1d0bca
@ -1 +0,0 @@
|
||||
lib/telegraf.provider.ts
|
@ -1,8 +1,9 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
import { HearsTriggers } from 'telegraf';
|
||||
import { HearsTriggers } from 'telegraf/typings/composer';
|
||||
import { Context } from '../interfaces';
|
||||
|
||||
export type TelegrafActionTriggers = HearsTriggers;
|
||||
export type TelegrafActionTriggers = HearsTriggers<Context>;
|
||||
|
||||
export interface TelegrafActionMetadata {
|
||||
triggers: TelegrafActionTriggers;
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
import { HearsTriggers } from 'telegraf';
|
||||
import { HearsTriggers } from 'telegraf/typings/composer';
|
||||
import { Context } from '../interfaces';
|
||||
|
||||
export type TelegrafHearsTriggers = HearsTriggers;
|
||||
export type TelegrafHearsTriggers = HearsTriggers<Context>;
|
||||
|
||||
export interface TelegrafHearsMetadata {
|
||||
triggers: TelegrafHearsTriggers;
|
||||
|
5
lib/interfaces/context.interface.ts
Normal file
5
lib/interfaces/context.interface.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { TelegrafContext } from 'telegraf/typings/context';
|
||||
|
||||
export interface Context extends TelegrafContext {
|
||||
[key: string]: any;
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
export { ContextMessageUpdate } from 'telegraf';
|
||||
export * from './context.interface';
|
||||
export * from './telegraf-options.interface';
|
||||
|
@ -3,7 +3,7 @@ import {
|
||||
TelegrafOptions,
|
||||
LaunchPollingOptions,
|
||||
LaunchWebhookOptions,
|
||||
} from 'telegraf';
|
||||
} from 'telegraf/typings/telegraf';
|
||||
|
||||
export interface TelegrafModuleOptions {
|
||||
token: string;
|
||||
|
@ -5,7 +5,6 @@ import { MetadataScanner } from '@nestjs/core/metadata-scanner';
|
||||
import { TelegrafMetadataAccessor } from './telegraf-metadata.accessor';
|
||||
import { TelegrafProvider } from './telegraf.provider';
|
||||
import { TELEGRAF_PROVIDER } from './telegraf.constants';
|
||||
import { Telegraf, ContextMessageUpdate } from 'telegraf';
|
||||
import {
|
||||
TelegrafActionMetadata,
|
||||
TelegrafCashtagMetadata,
|
||||
@ -41,9 +40,11 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
return;
|
||||
}
|
||||
|
||||
const telegraf = this.moduleRef.get<TelegrafProvider<any>>(
|
||||
const telegraf: TelegrafProvider = this.moduleRef.get<TelegrafProvider>(
|
||||
TELEGRAF_PROVIDER,
|
||||
{ strict: false },
|
||||
{
|
||||
strict: false,
|
||||
},
|
||||
);
|
||||
|
||||
this.metadataScanner.scanFromPrototype(
|
||||
@ -118,18 +119,14 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
});
|
||||
}
|
||||
|
||||
handleTelegrafUse(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
) {
|
||||
handleTelegrafUse(instance: object, key: string, telegraf: TelegrafProvider) {
|
||||
telegraf.use(instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafOn(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafOnMetadata,
|
||||
) {
|
||||
telegraf.on(metadata.updateTypes, instance[key].bind(instance));
|
||||
@ -138,7 +135,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafHears(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafHearsMetadata,
|
||||
) {
|
||||
telegraf.hears(metadata.triggers, instance[key].bind(instance));
|
||||
@ -147,7 +144,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafCommand(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafCommandMetadata,
|
||||
) {
|
||||
telegraf.command(metadata.commands, instance[key].bind(instance));
|
||||
@ -156,7 +153,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafStart(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
) {
|
||||
telegraf.start(instance[key].bind(instance));
|
||||
}
|
||||
@ -164,7 +161,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafHelp(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
) {
|
||||
telegraf.help(instance[key].bind(instance));
|
||||
}
|
||||
@ -172,7 +169,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafSettings(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
) {
|
||||
// @ts-ignore
|
||||
telegraf.settings(instance[key].bind(instance));
|
||||
@ -181,7 +178,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafEntity(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafEntityMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -191,7 +188,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafMention(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafMentionMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -201,7 +198,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafPhone(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafPhoneMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -211,7 +208,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafHashtag(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafHashtagMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -221,7 +218,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafCashtag(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafCashtagMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -231,7 +228,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafAction(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafActionMetadata,
|
||||
) {
|
||||
telegraf.action(metadata.triggers, instance[key].bind(instance));
|
||||
@ -240,7 +237,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafInlineQuery(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
metadata: TelegrafInlineQueryMetadata,
|
||||
) {
|
||||
// @ts-ignore
|
||||
@ -250,7 +247,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
handleTelegrafGameQuery(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
telegraf: TelegrafProvider,
|
||||
) {
|
||||
telegraf.gameQuery(instance[key].bind(instance));
|
||||
}
|
||||
|
@ -5,32 +5,30 @@ import {
|
||||
Logger,
|
||||
OnApplicationShutdown,
|
||||
} from '@nestjs/common';
|
||||
import Telegraf, { ContextMessageUpdate } from 'telegraf';
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { Context, TelegrafModuleOptions } from './interfaces';
|
||||
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
||||
import { TelegrafModuleOptions } from './interfaces';
|
||||
|
||||
@Injectable()
|
||||
export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
||||
// @ts-ignore
|
||||
extends Telegraf<TContext>
|
||||
export class TelegrafProvider extends Telegraf<Context>
|
||||
implements OnApplicationBootstrap, OnApplicationShutdown {
|
||||
private logger = new Logger('Telegraf');
|
||||
private launchOptions;
|
||||
private readonly launchOptions;
|
||||
|
||||
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
||||
super(options.token, options.options);
|
||||
this.launchOptions = options.launchOptions;
|
||||
}
|
||||
|
||||
onApplicationBootstrap() {
|
||||
async onApplicationBootstrap() {
|
||||
this.catch((e) => {
|
||||
this.logger.error(e);
|
||||
});
|
||||
|
||||
this.launch(this.launchOptions);
|
||||
await this.launch(this.launchOptions);
|
||||
}
|
||||
|
||||
async onApplicationShutdown(signal?: string) {
|
||||
async onApplicationShutdown() {
|
||||
await this.stop();
|
||||
}
|
||||
}
|
||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -2845,9 +2845,9 @@
|
||||
}
|
||||
},
|
||||
"telegraf": {
|
||||
"version": "3.37.0",
|
||||
"resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.37.0.tgz",
|
||||
"integrity": "sha512-V3448qwfOolBqkIc87yxjW4zMvR2P6AIF24pPTlX9WhZPwA1TF/x3nQhnWPRLtGh2SJuvDcr83iTkXPXT7Opnw==",
|
||||
"version": "3.38.0",
|
||||
"resolved": "https://registry.npmjs.org/telegraf/-/telegraf-3.38.0.tgz",
|
||||
"integrity": "sha512-va4VlrKWp64JrowFoZX/NPzzA6q38kvaIukVXOWFO1V+jR1G8+hCfgJy4TX8Z3rwLJzwaBEet1QhikHDRZWl3A==",
|
||||
"requires": {
|
||||
"debug": "^4.0.1",
|
||||
"minimist": "^1.2.0",
|
||||
|
@ -33,7 +33,7 @@
|
||||
"test": ""
|
||||
},
|
||||
"dependencies": {
|
||||
"telegraf": "3.37.0"
|
||||
"telegraf": "3.38.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/common": "7.0.9",
|
||||
|
Loading…
Reference in New Issue
Block a user