mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
Merge branch 'master' of github.com:bukhalo/nestjs-telegraf into feature/v2
Conflicts: package-lock.json
This commit is contained in:
@@ -14,4 +14,5 @@ export * from './phone.decorator';
|
||||
export * from './settings.decorator';
|
||||
export * from './start.decorator';
|
||||
export * from './update.decorator';
|
||||
export * from './update-hooks.decorators';
|
||||
export * from './use.decorator';
|
||||
|
@@ -1,10 +1,16 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
import * as tt from 'telegraf/typings/telegram-types';
|
||||
|
||||
export type TelegrafInlineQueryTriggers = string | string[] | RegExp | RegExp[];
|
||||
|
||||
export interface InlineQueryOptions {
|
||||
triggers: TelegrafInlineQueryTriggers;
|
||||
triggers?: TelegrafInlineQueryTriggers;
|
||||
updateType:
|
||||
| tt.UpdateType
|
||||
| tt.UpdateType[]
|
||||
| tt.MessageSubTypes
|
||||
| tt.MessageSubTypes[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -13,7 +19,10 @@ export interface InlineQueryOptions {
|
||||
* @see https://telegraf.js.org/#/?id=inlinequery
|
||||
*/
|
||||
export const InlineQuery = (
|
||||
triggers: TelegrafInlineQueryTriggers,
|
||||
triggers?: TelegrafInlineQueryTriggers,
|
||||
): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.INLINE_QUERY, { triggers });
|
||||
return SetMetadata(DECORATORS.INLINE_QUERY, {
|
||||
triggers,
|
||||
updateType: 'inline_query',
|
||||
});
|
||||
};
|
||||
|
104
lib/decorators/update-hooks.decorators.ts
Normal file
104
lib/decorators/update-hooks.decorators.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { DECORATORS } from '../telegraf.constants';
|
||||
import * as tt from 'telegraf/typings/telegram-types';
|
||||
|
||||
export interface UpdateHookOptions {
|
||||
updateType:
|
||||
| tt.UpdateType
|
||||
| tt.UpdateType[]
|
||||
| tt.MessageSubTypes
|
||||
| tt.MessageSubTypes[];
|
||||
}
|
||||
|
||||
/**
|
||||
* New incoming message of any kind — text, photo, sticker, etc.
|
||||
* @constructor
|
||||
*/
|
||||
export const Message = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'message',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New version of a message that is known to the bot and was edited
|
||||
* @constructor
|
||||
*/
|
||||
export const EditedMessage = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'edited_message',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New incoming channel post of any kind — text, photo, sticker, etc.
|
||||
* @constructor
|
||||
*/
|
||||
export const ChannelPost = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'channel_post',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New version of a channel post that is known to the bot and was edited
|
||||
* @constructor
|
||||
*/
|
||||
export const EditedChannelPost = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'edited_channel_post',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New incoming inline query
|
||||
* See this decorator in inline-query.decorator.ts
|
||||
* @constructor
|
||||
*/
|
||||
// export const InlineQuery = (): MethodDecorator => {
|
||||
// return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
// updateType: 'inline_query',
|
||||
// });
|
||||
// };
|
||||
|
||||
/**
|
||||
* The result of an inline query that was chosen by a user and sent to their chat partner.
|
||||
* @constructor
|
||||
*/
|
||||
export const ChosenInlineResult = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'chosen_inline_result',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New incoming callback query
|
||||
* @constructor
|
||||
*/
|
||||
export const CallbackQuery = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'callback_query',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New incoming shipping query. Only for invoices with flexible price
|
||||
* @constructor
|
||||
*/
|
||||
export const ShippingQuery = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'shipping_query',
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* New incoming pre-checkout query. Contains full information about checkout
|
||||
* @constructor
|
||||
*/
|
||||
export const PreCheckoutQuery = (): MethodDecorator => {
|
||||
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
||||
updateType: 'pre_checkout_query',
|
||||
});
|
||||
};
|
||||
|
||||
// Two more decorators are missing here. For 'poll' and 'poll_answer' update types.
|
@@ -3,6 +3,6 @@ import { DECORATORS } from '../telegraf.constants';
|
||||
|
||||
/**
|
||||
* `@Update` decorator, it's like NestJS `@Controller` decorator,
|
||||
* only for Telegram Bot API updates.
|
||||
* but for Telegram Bot API updates.
|
||||
*/
|
||||
export const Update = (): ClassDecorator => SetMetadata(DECORATORS.UPDATE, {});
|
||||
|
Reference in New Issue
Block a user