2021-05-04 14:07:40 +03:00
|
|
|
import {
|
2023-06-05 03:30:48 +03:00
|
|
|
BotChatJoinRequestUpdate,
|
|
|
|
BotStoppedUpdate,
|
2021-05-05 01:50:04 +03:00
|
|
|
CallbackQuery,
|
2023-06-05 03:30:48 +03:00
|
|
|
ChatJoinRequestUpdate,
|
2021-07-09 19:41:02 +03:00
|
|
|
ChatMemberUpdate,
|
2021-07-17 17:26:31 +03:00
|
|
|
ChosenInlineResult,
|
|
|
|
DeleteMessageUpdate,
|
2023-06-05 03:30:48 +03:00
|
|
|
HistoryReadUpdate,
|
|
|
|
InlineQuery,
|
|
|
|
MaybeAsync,
|
|
|
|
Message,
|
|
|
|
PeersIndex,
|
2021-07-17 17:26:31 +03:00
|
|
|
PollUpdate,
|
2023-06-05 03:30:48 +03:00
|
|
|
PollVoteUpdate,
|
2022-10-30 20:51:50 +03:00
|
|
|
PreCheckoutQuery,
|
2023-06-05 03:30:48 +03:00
|
|
|
TelegramClient,
|
|
|
|
UserStatusUpdate,
|
|
|
|
UserTypingUpdate,
|
2021-08-05 20:38:24 +03:00
|
|
|
} from '@mtcute/client'
|
|
|
|
import { tl } from '@mtcute/tl'
|
2022-06-30 16:32:56 +03:00
|
|
|
|
2021-07-17 17:26:31 +03:00
|
|
|
import { PropagationAction } from './propagation'
|
2021-04-08 12:19:38 +03:00
|
|
|
|
2022-08-24 23:37:26 +03:00
|
|
|
export interface BaseUpdateHandler<Name, Handler, Checker> {
|
2021-07-17 17:26:31 +03:00
|
|
|
name: Name
|
2021-04-08 12:19:38 +03:00
|
|
|
callback: Handler
|
|
|
|
|
|
|
|
check?: Checker
|
|
|
|
}
|
|
|
|
|
2022-10-30 20:51:50 +03:00
|
|
|
export type ParsedUpdateHandler<
|
|
|
|
Name,
|
|
|
|
Update,
|
|
|
|
State = never
|
|
|
|
> = BaseUpdateHandler<
|
2021-07-17 17:26:31 +03:00
|
|
|
Name,
|
2021-06-14 18:58:07 +03:00
|
|
|
(update: Update, state: State) => MaybeAsync<void | PropagationAction>,
|
2021-05-27 01:02:31 +03:00
|
|
|
(update: Update, state: State) => MaybeAsync<boolean>
|
2021-04-08 12:19:38 +03:00
|
|
|
>
|
|
|
|
|
|
|
|
export type RawUpdateHandler = BaseUpdateHandler<
|
|
|
|
'raw',
|
|
|
|
(
|
|
|
|
client: TelegramClient,
|
2021-07-17 17:26:31 +03:00
|
|
|
update: tl.TypeUpdate | tl.TypeMessage,
|
2021-11-23 00:03:59 +03:00
|
|
|
peers: PeersIndex
|
2021-06-14 18:58:07 +03:00
|
|
|
) => MaybeAsync<void | PropagationAction>,
|
2021-04-08 12:19:38 +03:00
|
|
|
(
|
|
|
|
client: TelegramClient,
|
2021-07-17 17:26:31 +03:00
|
|
|
update: tl.TypeUpdate | tl.TypeMessage,
|
2021-11-23 00:03:59 +03:00
|
|
|
peers: PeersIndex
|
2021-04-08 12:19:38 +03:00
|
|
|
) => MaybeAsync<boolean>
|
|
|
|
>
|
|
|
|
|
2021-05-05 00:43:35 +03:00
|
|
|
// begin-codegen
|
2021-05-27 01:02:31 +03:00
|
|
|
export type NewMessageHandler<T = Message, S = never> = ParsedUpdateHandler<
|
2021-04-27 20:31:04 +03:00
|
|
|
'new_message',
|
2021-05-27 01:02:31 +03:00
|
|
|
T,
|
|
|
|
S
|
2021-04-27 20:31:04 +03:00
|
|
|
>
|
2021-05-27 01:02:31 +03:00
|
|
|
export type EditMessageHandler<T = Message, S = never> = ParsedUpdateHandler<
|
2021-04-28 23:00:51 +03:00
|
|
|
'edit_message',
|
2021-05-27 01:02:31 +03:00
|
|
|
T,
|
|
|
|
S
|
2021-04-28 23:00:51 +03:00
|
|
|
>
|
2021-05-16 13:06:26 +03:00
|
|
|
export type DeleteMessageHandler<T = DeleteMessageUpdate> = ParsedUpdateHandler<
|
|
|
|
'delete_message',
|
|
|
|
T
|
|
|
|
>
|
2021-04-27 20:31:04 +03:00
|
|
|
export type ChatMemberUpdateHandler<T = ChatMemberUpdate> = ParsedUpdateHandler<
|
|
|
|
'chat_member',
|
|
|
|
T
|
|
|
|
>
|
2021-05-04 14:07:40 +03:00
|
|
|
export type InlineQueryHandler<T = InlineQuery> = ParsedUpdateHandler<
|
|
|
|
'inline_query',
|
|
|
|
T
|
|
|
|
>
|
2022-05-09 17:25:38 +03:00
|
|
|
export type ChosenInlineResultHandler<T = ChosenInlineResult> =
|
|
|
|
ParsedUpdateHandler<'chosen_inline_result', T>
|
2021-05-27 01:02:31 +03:00
|
|
|
export type CallbackQueryHandler<
|
|
|
|
T = CallbackQuery,
|
|
|
|
S = never
|
|
|
|
> = ParsedUpdateHandler<'callback_query', T, S>
|
2021-05-07 15:37:17 +03:00
|
|
|
export type PollUpdateHandler<T = PollUpdate> = ParsedUpdateHandler<'poll', T>
|
|
|
|
export type PollVoteHandler<T = PollVoteUpdate> = ParsedUpdateHandler<
|
|
|
|
'poll_vote',
|
|
|
|
T
|
|
|
|
>
|
2021-05-08 16:35:25 +03:00
|
|
|
export type UserStatusUpdateHandler<T = UserStatusUpdate> = ParsedUpdateHandler<
|
|
|
|
'user_status',
|
|
|
|
T
|
|
|
|
>
|
|
|
|
export type UserTypingHandler<T = UserTypingUpdate> = ParsedUpdateHandler<
|
|
|
|
'user_typing',
|
|
|
|
T
|
|
|
|
>
|
2021-07-09 19:41:02 +03:00
|
|
|
export type HistoryReadHandler<T = HistoryReadUpdate> = ParsedUpdateHandler<
|
|
|
|
'history_read',
|
|
|
|
T
|
|
|
|
>
|
2021-08-04 13:23:39 +03:00
|
|
|
export type BotStoppedHandler<T = BotStoppedUpdate> = ParsedUpdateHandler<
|
|
|
|
'bot_stopped',
|
|
|
|
T
|
|
|
|
>
|
2022-05-09 17:25:38 +03:00
|
|
|
export type BotChatJoinRequestHandler<T = BotChatJoinRequestUpdate> =
|
|
|
|
ParsedUpdateHandler<'bot_chat_join_request', T>
|
|
|
|
export type ChatJoinRequestHandler<T = ChatJoinRequestUpdate> =
|
|
|
|
ParsedUpdateHandler<'chat_join_request', T>
|
2022-10-30 20:51:50 +03:00
|
|
|
export type PreCheckoutQueryHandler<T = PreCheckoutQuery> = ParsedUpdateHandler<
|
|
|
|
'pre_checkout_query',
|
|
|
|
T
|
|
|
|
>
|
2021-04-08 12:19:38 +03:00
|
|
|
|
2021-04-27 20:31:04 +03:00
|
|
|
export type UpdateHandler =
|
|
|
|
| RawUpdateHandler
|
|
|
|
| NewMessageHandler
|
2021-04-28 23:00:51 +03:00
|
|
|
| EditMessageHandler
|
2021-05-16 13:06:26 +03:00
|
|
|
| DeleteMessageHandler
|
2021-04-27 20:31:04 +03:00
|
|
|
| ChatMemberUpdateHandler
|
2021-04-28 23:00:51 +03:00
|
|
|
| InlineQueryHandler
|
2021-05-04 14:07:40 +03:00
|
|
|
| ChosenInlineResultHandler
|
2021-05-05 01:50:04 +03:00
|
|
|
| CallbackQueryHandler
|
2021-05-07 15:37:17 +03:00
|
|
|
| PollUpdateHandler
|
|
|
|
| PollVoteHandler
|
2021-05-08 16:35:25 +03:00
|
|
|
| UserStatusUpdateHandler
|
|
|
|
| UserTypingHandler
|
2021-07-09 19:41:02 +03:00
|
|
|
| HistoryReadHandler
|
2021-08-04 13:23:39 +03:00
|
|
|
| BotStoppedHandler
|
2022-05-09 17:25:38 +03:00
|
|
|
| BotChatJoinRequestHandler
|
|
|
|
| ChatJoinRequestHandler
|
2022-10-30 20:51:50 +03:00
|
|
|
| PreCheckoutQueryHandler
|
2021-05-05 00:43:35 +03:00
|
|
|
|
|
|
|
// end-codegen
|