mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-04-09 17:53:44 +03:00
feat(decorators): TelegrafPhone added
This commit is contained in:
parent
f5d9cf13b6
commit
225c931dbb
@ -4,4 +4,7 @@ export * from './telegraf-hears.decorator';
|
||||
export * from './telegraf-command.decorator';
|
||||
export * from './telegraf-start.decorator';
|
||||
export * from './telegraf-help.decorator';
|
||||
export * from './telegraf-settings.decorator';
|
||||
export * from './telegraf-entity.decorator';
|
||||
export * from './telegraf-mention.decorator';
|
||||
export * from './telegraf-phone.decorator';
|
||||
|
12
lib/decorators/telegraf-phone.decorator.ts
Normal file
12
lib/decorators/telegraf-phone.decorator.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
|
||||
/**
|
||||
* Phone number handling.
|
||||
* @param phone Phone number
|
||||
*
|
||||
* https://telegraf.js.org/#/?id=phone
|
||||
*/
|
||||
export function TelegrafPhone(phone: string | string[]): MethodDecorator {
|
||||
return SetMetadata(DECORATORS.PHONE, { phone });
|
||||
}
|
@ -89,4 +89,15 @@ export class TelegrafMetadataAccessor {
|
||||
getTelegrafMentionMetadata(target: Type<any> | Function) {
|
||||
return this.reflector.get(DECORATORS.MENTION, target);
|
||||
}
|
||||
|
||||
isTelegrafPhone(target: Type<any> | Function): boolean {
|
||||
if (!target) {
|
||||
return false;
|
||||
}
|
||||
return !!this.reflector.get(DECORATORS.PHONE, target);
|
||||
}
|
||||
|
||||
getTelegrafPhoneMetadata(target: Type<any> | Function) {
|
||||
return this.reflector.get(DECORATORS.PHONE, target);
|
||||
}
|
||||
}
|
||||
|
@ -12,4 +12,5 @@ export const DECORATORS = {
|
||||
SETTINGS: `${DECORATORS_PREFIX}/SETTINGS`,
|
||||
ENTITY: `${DECORATORS_PREFIX}/ENTITY`,
|
||||
MENTION: `${DECORATORS_PREFIX}/MENTION`,
|
||||
PHONE: `${DECORATORS_PREFIX}/PHONE`,
|
||||
};
|
||||
|
@ -72,6 +72,11 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
instance[key],
|
||||
);
|
||||
this.handleTelegrafMention(instance, key, telegraf, metadata);
|
||||
} else if (this.metadataAccessor.isTelegrafPhone(instance[key])) {
|
||||
const metadata = this.metadataAccessor.getTelegrafPhoneMetadata(
|
||||
instance[key],
|
||||
);
|
||||
this.handleTelegrafPhone(instance, key, telegraf, metadata);
|
||||
}
|
||||
},
|
||||
);
|
||||
@ -157,4 +162,14 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
// @ts-ignore
|
||||
telegraf.mention(metadata.username, instance[key].bind(instance));
|
||||
}
|
||||
|
||||
handleTelegrafPhone(
|
||||
instance: object,
|
||||
key: string,
|
||||
telegraf: Telegraf<ContextMessageUpdate>,
|
||||
metadata: any,
|
||||
) {
|
||||
// @ts-ignore
|
||||
telegraf.phone(metadata.phone, instance[key].bind(instance));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user