mirror of
				https://github.com/Maks1mS/nestjs-telegraf.git
				synced 2025-11-04 07:51:22 +03:00 
			
		
		
		
	feat: add on message decorator handler
This commit is contained in:
		@@ -9,5 +9,6 @@ interface ArgumentTransformation {
 | 
			
		||||
export interface HandleParameters {
 | 
			
		||||
  onStart?: boolean
 | 
			
		||||
  command?: string
 | 
			
		||||
  message?: string | RegExp
 | 
			
		||||
  transformations?: ArgumentTransformation[]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ export class TelegramBot {
 | 
			
		||||
    const handlers = this.createHandlers()
 | 
			
		||||
 | 
			
		||||
    this.setupOnStart(handlers)
 | 
			
		||||
    this.setupOnMessage(handlers)
 | 
			
		||||
    this.setupOnCommand(handlers)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -83,6 +84,14 @@ export class TelegramBot {
 | 
			
		||||
    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 {
 | 
			
		||||
    const commandHandlers = handlers.filter(({ config }) => config.command)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user