mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat(telegraf-service): support registers middleware for provided update type in @TelegramActionHandler decorator
This commit is contained in:
parent
bdff44d6a1
commit
2e1e607933
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestjs-telegraf",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nestjs-telegraf",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "Telegraf module for Nest framework",
|
||||
"keywords": [
|
||||
"nest",
|
||||
|
Loading…
Reference in New Issue
Block a user