mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +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 { ContextTransformer } from './'
|
||||||
import { HearsTriggers } from 'telegraf'
|
import { HearsTriggers } from 'telegraf'
|
||||||
|
import { UpdateType, MessageSubTypes } from 'telegraf/typings/telegram-types'
|
||||||
import { Type } from '@nestjs/common'
|
import { Type } from '@nestjs/common'
|
||||||
|
|
||||||
interface ArgumentTransformation {
|
interface ArgumentTransformation {
|
||||||
@ -9,6 +10,7 @@ interface ArgumentTransformation {
|
|||||||
|
|
||||||
export interface HandleParameters {
|
export interface HandleParameters {
|
||||||
onStart?: boolean
|
onStart?: boolean
|
||||||
|
on?: UpdateType | UpdateType[] | MessageSubTypes | MessageSubTypes[]
|
||||||
command?: string
|
command?: string
|
||||||
message?: string | RegExp
|
message?: string | RegExp
|
||||||
action?: HearsTriggers
|
action?: HearsTriggers
|
||||||
|
@ -34,6 +34,7 @@ export class TelegrafService {
|
|||||||
const handlers = this.createHandlers()
|
const handlers = this.createHandlers()
|
||||||
|
|
||||||
this.setupOnStart(handlers)
|
this.setupOnStart(handlers)
|
||||||
|
this.setupOn(handlers)
|
||||||
this.setupOnMessage(handlers)
|
this.setupOnMessage(handlers)
|
||||||
this.setupOnCommand(handlers)
|
this.setupOnCommand(handlers)
|
||||||
this.setupActions(handlers)
|
this.setupActions(handlers)
|
||||||
@ -96,6 +97,14 @@ export class TelegrafService {
|
|||||||
this.bot.start(this.adoptHandle(head(onStart)))
|
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 {
|
private setupOnMessage(handlers: Handler[]): void {
|
||||||
const onMessageHandlers = handlers.filter(({ config }) => config.message)
|
const onMessageHandlers = handlers.filter(({ config }) => config.message)
|
||||||
|
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nestjs-telegraf",
|
"name": "nestjs-telegraf",
|
||||||
"version": "0.7.1",
|
"version": "0.7.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nestjs-telegraf",
|
"name": "nestjs-telegraf",
|
||||||
"version": "0.7.1",
|
"version": "0.7.2",
|
||||||
"description": "Telegraf module for Nest framework",
|
"description": "Telegraf module for Nest framework",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"nest",
|
"nest",
|
||||||
|
Loading…
Reference in New Issue
Block a user