mirror of
				https://github.com/Maks1mS/nestjs-telegraf.git
				synced 2025-10-31 05:52:17 +03:00 
			
		
		
		
	chore: publish 0.7.0 release (#6)
* feat(TelegramActionHandler): add 'action' parameter for handling 'callback_data'
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							57baf28809
						
					
				
				
					commit
					6138ae0918
				
			| @@ -1,4 +1,5 @@ | ||||
| { | ||||
|   "trailingComma": "none", | ||||
|   "singleQuote": true | ||||
| } | ||||
|   "trailingComma": "es5", | ||||
|   "singleQuote": true, | ||||
|   "semi": false | ||||
| } | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| import { ContextTransformer } from './' | ||||
| import { HearsTriggers } from 'telegraf' | ||||
| import { Type } from '@nestjs/common' | ||||
|  | ||||
| interface ArgumentTransformation { | ||||
| @@ -10,5 +11,6 @@ export interface HandleParameters { | ||||
|   onStart?: boolean | ||||
|   command?: string | ||||
|   message?: string | RegExp | ||||
|   action?: HearsTriggers | ||||
|   transformations?: ArgumentTransformation[] | ||||
| } | ||||
|   | ||||
| @@ -21,7 +21,7 @@ export class TelegrafService { | ||||
|   private ref: ModuleRef | ||||
|  | ||||
|   public constructor( | ||||
|     @Inject(TokenInjectionToken) options: TelegrafOptionsFactory, | ||||
|     @Inject(TokenInjectionToken) options: TelegrafOptionsFactory | ||||
|   ) { | ||||
|     const { token, sitePublicUrl } = options.createTelegrafOptions() | ||||
|     this.sitePublicUrl = sitePublicUrl | ||||
| @@ -36,6 +36,7 @@ export class TelegrafService { | ||||
|     this.setupOnStart(handlers) | ||||
|     this.setupOnMessage(handlers) | ||||
|     this.setupOnCommand(handlers) | ||||
|     this.setupActions(handlers) | ||||
|  | ||||
|     if (devMode) { | ||||
|       this.startPolling() | ||||
| @@ -46,7 +47,7 @@ export class TelegrafService { | ||||
|     if (!this.sitePublicUrl) { | ||||
|       throw new InvalidConfigurationException( | ||||
|         'sitePublicUrl', | ||||
|         'does not exist, but webook used', | ||||
|         'does not exist, but webook used' | ||||
|       ) | ||||
|     } | ||||
|  | ||||
| @@ -64,7 +65,7 @@ export class TelegrafService { | ||||
|       () => this.bot.startPolling(), | ||||
|       () => { | ||||
|         // okay, never mind | ||||
|       }, | ||||
|       } | ||||
|     ) | ||||
|   } | ||||
|  | ||||
| @@ -78,10 +79,10 @@ export class TelegrafService { | ||||
|             ([methodName, methodCondig]) => ({ | ||||
|               handle: handlerInstance[methodName].bind(handlerInstance), | ||||
|               config: methodCondig, | ||||
|             }), | ||||
|             }) | ||||
|           ) | ||||
|         }, | ||||
|       ), | ||||
|         } | ||||
|       ) | ||||
|     ) | ||||
|   } | ||||
|  | ||||
| @@ -111,6 +112,14 @@ export class TelegrafService { | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   private setupActions(handlers: Handler[]): void { | ||||
|     const commandHandlers = handlers.filter(({ config }) => config.action) | ||||
|  | ||||
|     commandHandlers.forEach(handler => { | ||||
|       this.bot.action(handler.config.action, this.adoptHandle(handler)) | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   private adoptHandle({ handle, config }: Handler) { | ||||
|     const errorHandler = this.createCatch() | ||||
|  | ||||
| @@ -121,8 +130,8 @@ export class TelegrafService { | ||||
|           .map(({ transform }) => | ||||
|             this.ref | ||||
|               .get<ContextTransformer>(transform, { strict: false }) | ||||
|               .transform(ctx), | ||||
|           ), | ||||
|               .transform(ctx) | ||||
|           ) | ||||
|       ) | ||||
|  | ||||
|       return handle(ctx, ...args).catch(errorHandler(ctx)) | ||||
| @@ -131,7 +140,7 @@ export class TelegrafService { | ||||
|  | ||||
|   private createCatch() { | ||||
|     const handlers = Array.from( | ||||
|       (TelegramCatch.handlers || new Map()).entries(), | ||||
|       (TelegramCatch.handlers || new Map()).entries() | ||||
|     ).map(([errorType, handlerType]) => { | ||||
|       const handler = this.ref.get<TelegramErrorHandler>(handlerType, { | ||||
|         strict: false, | ||||
|   | ||||
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "nestjs-telegraf", | ||||
|   "version": "0.6.0", | ||||
|   "version": "0.7.0", | ||||
|   "lockfileVersion": 1, | ||||
|   "requires": true, | ||||
|   "dependencies": { | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "nestjs-telegraf", | ||||
|   "version": "0.6.0", | ||||
|   "version": "0.7.0", | ||||
|   "description": "Telegraf module for Nest framework", | ||||
|   "keywords": [ | ||||
|     "nest", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user