mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-03-16 23:13:44 +03:00
feat(decorators): metadata typings added
This commit is contained in:
parent
dd59da7737
commit
25710b7908
@ -2,12 +2,20 @@ import { SetMetadata } from '@nestjs/common';
|
|||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
import { HearsTriggers } from 'telegraf';
|
import { HearsTriggers } from 'telegraf';
|
||||||
|
|
||||||
|
export type TelegrafActionTriggers = HearsTriggers;
|
||||||
|
|
||||||
|
export interface TelegrafActionMetadata {
|
||||||
|
triggers: TelegrafActionTriggers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers middleware for handling callback_data actions with regular expressions.
|
* Registers middleware for handling callback_data actions with regular expressions.
|
||||||
* @param triggers Triggers
|
* @param triggers Triggers
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=action
|
* https://telegraf.js.org/#/?id=action
|
||||||
*/
|
*/
|
||||||
export function TelegrafAction(triggers: HearsTriggers): MethodDecorator {
|
export function TelegrafAction(
|
||||||
|
triggers: TelegrafActionTriggers,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.ACTION, { triggers });
|
return SetMetadata(DECORATORS.ACTION, { triggers });
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type TelegrafCashtagCashtag = string | string[];
|
||||||
|
|
||||||
|
export interface TelegrafCashtagMetadata {
|
||||||
|
cashtag: TelegrafCashtagCashtag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cashtag handling.
|
* Cashtag handling.
|
||||||
* @param cashtag Cashtag
|
* @param cashtag Cashtag
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=cashtag
|
* https://telegraf.js.org/#/?id=cashtag
|
||||||
*/
|
*/
|
||||||
export function TelegrafCashtag(cashtag: string | string[]): MethodDecorator {
|
export function TelegrafCashtag(
|
||||||
|
cashtag: TelegrafCashtagCashtag,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.CASHTAG, { cashtag });
|
return SetMetadata(DECORATORS.CASHTAG, { cashtag });
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type TelegrafCommandCommands = string | string[];
|
||||||
|
|
||||||
|
export interface TelegrafCommandMetadata {
|
||||||
|
commands: TelegrafCommandCommands;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command handling.
|
* Command handling.
|
||||||
* @param commands Commands
|
* @param commands Commands
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=command
|
* https://telegraf.js.org/#/?id=command
|
||||||
*/
|
*/
|
||||||
export function TelegrafCommand(commands: string | string[]): MethodDecorator {
|
export function TelegrafCommand(
|
||||||
|
commands: TelegrafCommandCommands,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.COMMAND, { commands });
|
return SetMetadata(DECORATORS.COMMAND, { commands });
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
export type Entity = string | string[] | RegExp | RegExp[] | Function;
|
export type TelegrafEntityEntity =
|
||||||
|
| string
|
||||||
|
| string[]
|
||||||
|
| RegExp
|
||||||
|
| RegExp[]
|
||||||
|
| Function;
|
||||||
|
|
||||||
|
export interface TelegrafEntityMetadata {
|
||||||
|
entity: TelegrafEntityEntity;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity handling.
|
* Entity handling.
|
||||||
@ -9,6 +18,6 @@ export type Entity = string | string[] | RegExp | RegExp[] | Function;
|
|||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=entity
|
* https://telegraf.js.org/#/?id=entity
|
||||||
*/
|
*/
|
||||||
export function TelegrafEntity(entity: Entity): MethodDecorator {
|
export function TelegrafEntity(entity: TelegrafEntityEntity): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.ENTITY, { entity });
|
return SetMetadata(DECORATORS.ENTITY, { entity });
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type TelegrafHashtagHashtag = string | string[];
|
||||||
|
|
||||||
|
export interface TelegrafHashtagMetadata {
|
||||||
|
hashtag: TelegrafHashtagHashtag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hashtag handling.
|
* Hashtag handling.
|
||||||
* @param hashtag Hashtag
|
* @param hashtag Hashtag
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=hashtag
|
* https://telegraf.js.org/#/?id=hashtag
|
||||||
*/
|
*/
|
||||||
export function TelegrafHashtag(hashtag: string | string[]): MethodDecorator {
|
export function TelegrafHashtag(
|
||||||
|
hashtag: TelegrafHashtagHashtag,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.HASHTAG, { hashtag });
|
return SetMetadata(DECORATORS.HASHTAG, { hashtag });
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,20 @@ import { SetMetadata } from '@nestjs/common';
|
|||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
import { HearsTriggers } from 'telegraf';
|
import { HearsTriggers } from 'telegraf';
|
||||||
|
|
||||||
|
export type TelegrafHearsTriggers = HearsTriggers;
|
||||||
|
|
||||||
|
export interface TelegrafHearsMetadata {
|
||||||
|
triggers: TelegrafHearsTriggers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers middleware for handling text messages.
|
* Registers middleware for handling text messages.
|
||||||
* @param triggers Triggers
|
* @param triggers Triggers
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=hears
|
* https://telegraf.js.org/#/?id=hears
|
||||||
*/
|
*/
|
||||||
export function TelegrafHears(triggers: HearsTriggers): MethodDecorator {
|
export function TelegrafHears(
|
||||||
|
triggers: TelegrafHearsTriggers,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.HEARS, { triggers: triggers });
|
return SetMetadata(DECORATORS.HEARS, { triggers: triggers });
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
export type Triggers = string | string[] | RegExp | RegExp[];
|
export type TelegrafInlineQueryTriggers = string | string[] | RegExp | RegExp[];
|
||||||
|
|
||||||
|
export interface TelegrafInlineQueryMetadata {
|
||||||
|
triggers: TelegrafInlineQueryTriggers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers middleware for handling inline_query actions with regular expressions.
|
* Registers middleware for handling inline_query actions with regular expressions.
|
||||||
@ -9,6 +13,8 @@ export type Triggers = string | string[] | RegExp | RegExp[];
|
|||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=inlinequery
|
* https://telegraf.js.org/#/?id=inlinequery
|
||||||
*/
|
*/
|
||||||
export function TelegrafInlineQuery(triggers: Triggers): MethodDecorator {
|
export function TelegrafInlineQuery(
|
||||||
|
triggers: TelegrafInlineQueryTriggers,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
|
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,20 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type TelegrafMentionUsername = string | string[];
|
||||||
|
|
||||||
|
export interface TelegrafMentionMetadata {
|
||||||
|
username: TelegrafMentionUsername;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mention handling.
|
* Mention handling.
|
||||||
* @param username Username
|
* @param username Username
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=mention
|
* https://telegraf.js.org/#/?id=mention
|
||||||
*/
|
*/
|
||||||
export function TelegrafMention(username: string | string[]): MethodDecorator {
|
export function TelegrafMention(
|
||||||
|
username: TelegrafMentionUsername,
|
||||||
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.MENTION, { username });
|
return SetMetadata(DECORATORS.MENTION, { username });
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,16 @@ import { SetMetadata } from '@nestjs/common';
|
|||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types';
|
import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types';
|
||||||
|
|
||||||
|
export type TelegrafOnUpdateTypes =
|
||||||
|
| UpdateType
|
||||||
|
| UpdateType[]
|
||||||
|
| MessageSubTypes
|
||||||
|
| MessageSubTypes[];
|
||||||
|
|
||||||
|
export interface TelegrafOnMetadata {
|
||||||
|
updateTypes: TelegrafOnUpdateTypes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers middleware for provided update type.
|
* Registers middleware for provided update type.
|
||||||
* @param updateTypes Update type
|
* @param updateTypes Update type
|
||||||
@ -9,7 +19,7 @@ import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types';
|
|||||||
* https://telegraf.js.org/#/?id=on
|
* https://telegraf.js.org/#/?id=on
|
||||||
*/
|
*/
|
||||||
export function TelegrafOn(
|
export function TelegrafOn(
|
||||||
updateTypes: UpdateType | UpdateType[] | MessageSubTypes | MessageSubTypes[],
|
updateTypes: TelegrafOnUpdateTypes,
|
||||||
): MethodDecorator {
|
): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.ON, { updateTypes: updateTypes });
|
return SetMetadata(DECORATORS.ON, { updateTypes: updateTypes });
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
import { SetMetadata } from '@nestjs/common';
|
import { SetMetadata } from '@nestjs/common';
|
||||||
import { DECORATORS } from '../telegraf.constants';
|
import { DECORATORS } from '../telegraf.constants';
|
||||||
|
|
||||||
|
export type TelegrafPhonePhone = string | string[];
|
||||||
|
|
||||||
|
export interface TelegrafPhoneMetadata {
|
||||||
|
phone: TelegrafPhonePhone;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Phone number handling.
|
* Phone number handling.
|
||||||
* @param phone Phone number
|
* @param phone Phone number
|
||||||
*
|
*
|
||||||
* https://telegraf.js.org/#/?id=phone
|
* https://telegraf.js.org/#/?id=phone
|
||||||
*/
|
*/
|
||||||
export function TelegrafPhone(phone: string | string[]): MethodDecorator {
|
export function TelegrafPhone(phone: TelegrafPhonePhone): MethodDecorator {
|
||||||
return SetMetadata(DECORATORS.PHONE, { phone });
|
return SetMetadata(DECORATORS.PHONE, { phone });
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,18 @@
|
|||||||
import { Injectable, Type } from '@nestjs/common';
|
import { Injectable, Type } from '@nestjs/common';
|
||||||
import { Reflector } from '@nestjs/core';
|
import { Reflector } from '@nestjs/core';
|
||||||
import { TelegrafStart } from './decorators';
|
import {
|
||||||
|
TelegrafActionMetadata,
|
||||||
|
TelegrafCashtagMetadata,
|
||||||
|
TelegrafCommandMetadata,
|
||||||
|
TelegrafEntityMetadata,
|
||||||
|
TelegrafHashtagMetadata,
|
||||||
|
TelegrafHearsMetadata,
|
||||||
|
TelegrafInlineQueryMetadata,
|
||||||
|
TelegrafMentionMetadata,
|
||||||
|
TelegrafOnMetadata,
|
||||||
|
TelegrafPhoneMetadata,
|
||||||
|
TelegrafStart,
|
||||||
|
} from './decorators';
|
||||||
import { DECORATORS } from './telegraf.constants';
|
import { DECORATORS } from './telegraf.constants';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -21,7 +33,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.ON, target);
|
return !!this.reflector.get(DECORATORS.ON, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafOnMetadata(target: Type<any> | Function) {
|
getTelegrafOnMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafOnMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.ON, target);
|
return this.reflector.get(DECORATORS.ON, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +46,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.HEARS, target);
|
return !!this.reflector.get(DECORATORS.HEARS, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafHearsMetadata(target: Type<any> | Function) {
|
getTelegrafHearsMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafHearsMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.HEARS, target);
|
return this.reflector.get(DECORATORS.HEARS, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +59,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.COMMAND, target);
|
return !!this.reflector.get(DECORATORS.COMMAND, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafCommandMetadata(target: Type<any> | Function) {
|
getTelegrafCommandMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafCommandMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.COMMAND, target);
|
return this.reflector.get(DECORATORS.COMMAND, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +93,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.ENTITY, target);
|
return !!this.reflector.get(DECORATORS.ENTITY, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafEntityMetadata(target: Type<any> | Function) {
|
getTelegrafEntityMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafEntityMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.ENTITY, target);
|
return this.reflector.get(DECORATORS.ENTITY, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +106,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.MENTION, target);
|
return !!this.reflector.get(DECORATORS.MENTION, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafMentionMetadata(target: Type<any> | Function) {
|
getTelegrafMentionMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafMentionMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.MENTION, target);
|
return this.reflector.get(DECORATORS.MENTION, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +119,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.PHONE, target);
|
return !!this.reflector.get(DECORATORS.PHONE, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafPhoneMetadata(target: Type<any> | Function) {
|
getTelegrafPhoneMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafPhoneMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.PHONE, target);
|
return this.reflector.get(DECORATORS.PHONE, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +132,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.HASHTAG, target);
|
return !!this.reflector.get(DECORATORS.HASHTAG, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafHashtagMetadata(target: Type<any> | Function) {
|
getTelegrafHashtagMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafHashtagMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.HASHTAG, target);
|
return this.reflector.get(DECORATORS.HASHTAG, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +145,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.CASHTAG, target);
|
return !!this.reflector.get(DECORATORS.CASHTAG, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafCashtagMetadata(target: Type<any> | Function) {
|
getTelegrafCashtagMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafCashtagMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.CASHTAG, target);
|
return this.reflector.get(DECORATORS.CASHTAG, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +158,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.ACTION, target);
|
return !!this.reflector.get(DECORATORS.ACTION, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafActionMetadata(target: Type<any> | Function) {
|
getTelegrafActionMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafActionMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.ACTION, target);
|
return this.reflector.get(DECORATORS.ACTION, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +171,9 @@ export class TelegrafMetadataAccessor {
|
|||||||
return !!this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
return !!this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTelegrafInlineQueryMetadata(target: Type<any> | Function) {
|
getTelegrafInlineQueryMetadata(
|
||||||
|
target: Type<any> | Function,
|
||||||
|
): TelegrafInlineQueryMetadata | undefined {
|
||||||
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
return this.reflector.get(DECORATORS.INLINE_QUERY, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,18 @@ import { TelegrafMetadataAccessor } from './telegraf-metadata.accessor';
|
|||||||
import { TelegrafProvider } from './telegraf.provider';
|
import { TelegrafProvider } from './telegraf.provider';
|
||||||
import { TELEGRAF_PROVIDER } from './telegraf.constants';
|
import { TELEGRAF_PROVIDER } from './telegraf.constants';
|
||||||
import { ContextMessageUpdate } from 'telegraf';
|
import { ContextMessageUpdate } from 'telegraf';
|
||||||
|
import {
|
||||||
|
TelegrafActionMetadata,
|
||||||
|
TelegrafCashtagMetadata,
|
||||||
|
TelegrafCommandMetadata,
|
||||||
|
TelegrafEntityMetadata,
|
||||||
|
TelegrafHashtagMetadata,
|
||||||
|
TelegrafHearsMetadata,
|
||||||
|
TelegrafInlineQueryMetadata,
|
||||||
|
TelegrafMentionMetadata,
|
||||||
|
TelegrafOnMetadata,
|
||||||
|
TelegrafPhoneMetadata,
|
||||||
|
} from './decorators';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TelegrafExplorer implements OnModuleInit {
|
export class TelegrafExplorer implements OnModuleInit {
|
||||||
@ -119,7 +131,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafOnMetadata,
|
||||||
) {
|
) {
|
||||||
telegraf.on(metadata.updateTypes, instance[key].bind(instance));
|
telegraf.on(metadata.updateTypes, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
@ -128,7 +140,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafHearsMetadata,
|
||||||
) {
|
) {
|
||||||
telegraf.hears(metadata.triggers, instance[key].bind(instance));
|
telegraf.hears(metadata.triggers, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
@ -137,7 +149,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafCommandMetadata,
|
||||||
) {
|
) {
|
||||||
telegraf.command(metadata.commands, instance[key].bind(instance));
|
telegraf.command(metadata.commands, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
@ -171,7 +183,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafEntityMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.entity(metadata.entity, instance[key].bind(instance));
|
telegraf.entity(metadata.entity, instance[key].bind(instance));
|
||||||
@ -181,7 +193,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafMentionMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.mention(metadata.username, instance[key].bind(instance));
|
telegraf.mention(metadata.username, instance[key].bind(instance));
|
||||||
@ -191,7 +203,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafPhoneMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.phone(metadata.phone, instance[key].bind(instance));
|
telegraf.phone(metadata.phone, instance[key].bind(instance));
|
||||||
@ -201,7 +213,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafHashtagMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.hashtag(metadata.hashtag, instance[key].bind(instance));
|
telegraf.hashtag(metadata.hashtag, instance[key].bind(instance));
|
||||||
@ -211,7 +223,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafCashtagMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.cashtag(metadata.cashtag, instance[key].bind(instance));
|
telegraf.cashtag(metadata.cashtag, instance[key].bind(instance));
|
||||||
@ -221,7 +233,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafActionMetadata,
|
||||||
) {
|
) {
|
||||||
telegraf.action(metadata.triggers, instance[key].bind(instance));
|
telegraf.action(metadata.triggers, instance[key].bind(instance));
|
||||||
}
|
}
|
||||||
@ -230,7 +242,7 @@ export class TelegrafExplorer implements OnModuleInit {
|
|||||||
instance: object,
|
instance: object,
|
||||||
key: string,
|
key: string,
|
||||||
telegraf: Telegraf<ContextMessageUpdate>,
|
telegraf: Telegraf<ContextMessageUpdate>,
|
||||||
metadata: any,
|
metadata: TelegrafInlineQueryMetadata,
|
||||||
) {
|
) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance));
|
telegraf.inlineQuery(metadata.triggers, instance[key].bind(instance));
|
||||||
|
@ -3,6 +3,7 @@ import {
|
|||||||
Inject,
|
Inject,
|
||||||
OnApplicationBootstrap,
|
OnApplicationBootstrap,
|
||||||
Logger,
|
Logger,
|
||||||
|
OnApplicationShutdown,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import Telegraf, { ContextMessageUpdate } from 'telegraf';
|
import Telegraf, { ContextMessageUpdate } from 'telegraf';
|
||||||
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
||||||
@ -12,7 +13,7 @@ import { TelegrafModuleOptions } from './interfaces';
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
||||||
extends Telegraf<TContext>
|
extends Telegraf<TContext>
|
||||||
implements OnApplicationBootstrap {
|
implements OnApplicationBootstrap, OnApplicationShutdown {
|
||||||
private logger = new Logger('Telegraf');
|
private logger = new Logger('Telegraf');
|
||||||
|
|
||||||
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
||||||
@ -25,4 +26,8 @@ export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
|||||||
});
|
});
|
||||||
this.startPolling();
|
this.startPolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async onApplicationShutdown(signal?: string) {
|
||||||
|
await this.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user