diff --git a/lib/interfaces/handle-parameters.interface.ts b/lib/interfaces/handle-parameters.interface.ts index bf7b62e..561953c 100644 --- a/lib/interfaces/handle-parameters.interface.ts +++ b/lib/interfaces/handle-parameters.interface.ts @@ -1,5 +1,6 @@ import { ContextTransformer } from './' import { HearsTriggers } from 'telegraf' +import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types' import { Type } from '@nestjs/common' interface ArgumentTransformation { @@ -9,6 +10,7 @@ interface ArgumentTransformation { export interface HandleParameters { onStart?: boolean + on?: UpdateType | UpdateType[] | MessageSubTypes | MessageSubTypes[] command?: string message?: string | RegExp action?: HearsTriggers diff --git a/lib/telegraf.service.ts b/lib/telegraf.service.ts index aa2aa88..48a27a5 100644 --- a/lib/telegraf.service.ts +++ b/lib/telegraf.service.ts @@ -34,6 +34,7 @@ export class TelegrafService { const handlers = this.createHandlers() this.setupOnStart(handlers) + this.setupOn(handlers) this.setupOnMessage(handlers) this.setupOnCommand(handlers) this.setupActions(handlers) @@ -96,6 +97,14 @@ export class TelegrafService { this.bot.start(this.adoptHandle(head(onStart))) } + private setupOn(handlers: Handler[]): void { + const onHandlers = handlers.filter(({ config }) => config.on) + + onHandlers.forEach(handler => { + this.bot.on(handler.config.on, this.adoptHandle(handler)) + }) + } + private setupOnMessage(handlers: Handler[]): void { const onMessageHandlers = handlers.filter(({ config }) => config.message) diff --git a/package-lock.json b/package-lock.json index 8670bb4..62717d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nestjs-telegraf", - "version": "0.7.1", + "version": "0.7.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 708c292..0c1cdc2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nestjs-telegraf", - "version": "0.7.1", + "version": "0.7.2", "description": "Telegraf module for Nest framework", "keywords": [ "nest",