2020-09-09 22:46:25 +03:00
|
|
|
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
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const Message = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'message',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New version of a message that is known to the bot and was edited
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const EditedMessage = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'edited_message',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New incoming channel post of any kind — text, photo, sticker, etc.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const ChannelPost = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'channel_post',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New version of a channel post that is known to the bot and was edited
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const EditedChannelPost = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'edited_channel_post',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New incoming inline query
|
2020-09-10 11:23:04 +03:00
|
|
|
* See this decorator in inline-query.decorator.ts
|
2020-09-09 22:46:25 +03:00
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
// export const InlineQuery = (): MethodDecorator => {
|
|
|
|
// return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
// updateType: 'inline_query',
|
|
|
|
// });
|
|
|
|
// };
|
2020-09-09 22:46:25 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The result of an inline query that was chosen by a user and sent to their chat partner.
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const ChosenInlineResult = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'chosen_inline_result',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New incoming callback query
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const CallbackQuery = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'callback_query',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New incoming shipping query. Only for invoices with flexible price
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const ShippingQuery = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'shipping_query',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* New incoming pre-checkout query. Contains full information about checkout
|
|
|
|
* @constructor
|
|
|
|
*/
|
2020-09-10 11:23:04 +03:00
|
|
|
export const PreCheckoutQuery = (): MethodDecorator => {
|
2020-09-09 22:46:25 +03:00
|
|
|
return SetMetadata(DECORATORS.UPDATE_HOOK, {
|
|
|
|
updateType: 'pre_checkout_query',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Two more decorators are missing here. For 'poll' and 'poll_answer' update types.
|