mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat: add on message decorator handler
This commit is contained in:
parent
855a1fa625
commit
c47c05570b
@ -9,5 +9,6 @@ interface ArgumentTransformation {
|
|||||||
export interface HandleParameters {
|
export interface HandleParameters {
|
||||||
onStart?: boolean
|
onStart?: boolean
|
||||||
command?: string
|
command?: string
|
||||||
|
message?: string | RegExp
|
||||||
transformations?: ArgumentTransformation[]
|
transformations?: ArgumentTransformation[]
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ export class TelegramBot {
|
|||||||
const handlers = this.createHandlers()
|
const handlers = this.createHandlers()
|
||||||
|
|
||||||
this.setupOnStart(handlers)
|
this.setupOnStart(handlers)
|
||||||
|
this.setupOnMessage(handlers)
|
||||||
this.setupOnCommand(handlers)
|
this.setupOnCommand(handlers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,6 +84,14 @@ export class TelegramBot {
|
|||||||
this.bot.start(this.adoptHandle(head(onStart)))
|
this.bot.start(this.adoptHandle(head(onStart)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setupOnMessage(handlers: Handler[]): void {
|
||||||
|
const onMessageHandlers = handlers.filter(({ config }) => config.message)
|
||||||
|
|
||||||
|
onMessageHandlers.forEach(handler => {
|
||||||
|
this.bot.hears(handler.config.message, this.adoptHandle(handler))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private setupOnCommand(handlers: Handler[]): void {
|
private setupOnCommand(handlers: Handler[]): void {
|
||||||
const commandHandlers = handlers.filter(({ config }) => config.command)
|
const commandHandlers = handlers.filter(({ config }) => config.command)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user