1 |
|
2 |
|
3 | import { Message, Opts, Telegram, Update } from './core/types/typegram'
|
4 | import { UnionKeys } from './deunionize'
|
5 |
|
6 | export { Markup } from './markup'
|
7 |
|
8 |
|
9 | export type ChatAction = Opts<'sendChatAction'>['action']
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | type MakeExtra<
|
18 | M extends keyof Telegram,
|
19 | K extends keyof Omit<Opts<M>, 'chat_id'> = never
|
20 | > = Omit<Opts<M>, 'chat_id' | K>
|
21 |
|
22 | export type ExtraAddStickerToSet = MakeExtra<
|
23 | 'addStickerToSet',
|
24 | 'name' | 'user_id'
|
25 | >
|
26 | export type ExtraAnimation = MakeExtra<'sendAnimation', 'animation'>
|
27 | export type ExtraAnswerCbQuery = MakeExtra<
|
28 | 'answerCallbackQuery',
|
29 | 'text' | 'callback_query_id'
|
30 | >
|
31 | export type ExtraAnswerInlineQuery = MakeExtra<
|
32 | 'answerInlineQuery',
|
33 | 'inline_query_id' | 'results'
|
34 | >
|
35 | export type ExtraAudio = MakeExtra<'sendAudio', 'audio'>
|
36 | export type ExtraContact = MakeExtra<
|
37 | 'sendContact',
|
38 | 'phone_number' | 'first_name'
|
39 | >
|
40 | export type ExtraCopyMessage = MakeExtra<
|
41 | 'copyMessage',
|
42 | 'from_chat_id' | 'message_id'
|
43 | >
|
44 | export type ExtraCreateChatInviteLink = MakeExtra<'createChatInviteLink'>
|
45 | export type ExtraCreateNewStickerSet = MakeExtra<
|
46 | 'createNewStickerSet',
|
47 | 'name' | 'title' | 'user_id'
|
48 | >
|
49 | export type ExtraDice = MakeExtra<'sendDice'>
|
50 | export type ExtraDocument = MakeExtra<'sendDocument', 'document'>
|
51 | export type ExtraEditChatInviteLink = MakeExtra<
|
52 | 'editChatInviteLink',
|
53 | 'invite_link'
|
54 | >
|
55 | export type ExtraEditMessageCaption = MakeExtra<
|
56 | 'editMessageCaption',
|
57 | 'message_id' | 'inline_message_id' | 'caption'
|
58 | >
|
59 | export type ExtraEditMessageLiveLocation = MakeExtra<
|
60 | 'editMessageLiveLocation',
|
61 | 'message_id' | 'inline_message_id' | 'latitude' | 'longitude'
|
62 | >
|
63 | export type ExtraEditMessageMedia = MakeExtra<
|
64 | 'editMessageMedia',
|
65 | 'message_id' | 'inline_message_id' | 'media'
|
66 | >
|
67 | export type ExtraEditMessageText = MakeExtra<
|
68 | 'editMessageText',
|
69 | 'message_id' | 'inline_message_id' | 'text'
|
70 | >
|
71 | export type ExtraGame = MakeExtra<'sendGame', 'game_short_name'>
|
72 | export type NewInvoiceParameters = MakeExtra<
|
73 | 'sendInvoice',
|
74 | | 'disable_notification'
|
75 | | 'reply_to_message_id'
|
76 | | 'allow_sending_without_reply'
|
77 | | 'reply_markup'
|
78 | >
|
79 | export type ExtraInvoice = MakeExtra<'sendInvoice', keyof NewInvoiceParameters>
|
80 | export type ExtraKickChatMember = MakeExtra<
|
81 | 'kickChatMember',
|
82 | 'user_id' | 'until_date'
|
83 | >
|
84 | export type ExtraLocation = MakeExtra<'sendLocation', 'latitude' | 'longitude'>
|
85 | export type ExtraMediaGroup = MakeExtra<'sendMediaGroup', 'media'>
|
86 | export type ExtraPhoto = MakeExtra<'sendPhoto', 'photo'>
|
87 | export type ExtraPoll = MakeExtra<'sendPoll', 'question' | 'options' | 'type'>
|
88 | export type ExtraPromoteChatMember = MakeExtra<'promoteChatMember', 'user_id'>
|
89 | export type ExtraReplyMessage = MakeExtra<'sendMessage', 'text'>
|
90 | export type ExtraRestrictChatMember = MakeExtra<'restrictChatMember', 'user_id'>
|
91 | export type ExtraSetMyCommands = MakeExtra<'setMyCommands', 'commands'>
|
92 | export type ExtraSetWebhook = MakeExtra<'setWebhook', 'url'>
|
93 | export type ExtraSticker = MakeExtra<'sendSticker', 'sticker'>
|
94 | export type ExtraStopPoll = MakeExtra<'stopPoll', 'message_id'>
|
95 | export type ExtraVenue = MakeExtra<
|
96 | 'sendVenue',
|
97 | 'latitude' | 'longitude' | 'title' | 'address'
|
98 | >
|
99 | export type ExtraVideo = MakeExtra<'sendVideo', 'video'>
|
100 | export type ExtraVideoNote = MakeExtra<'sendVideoNote', 'video_note'>
|
101 | export type ExtraVoice = MakeExtra<'sendVoice', 'voice'>
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | export type UpdateType = Exclude<UnionKeys<Update>, keyof Update>
|
107 |
|
108 |
|
109 | export type MessageSubType =
|
110 | | 'forward_date'
|
111 | | Exclude<
|
112 | UnionKeys<Message>,
|
113 | keyof Message.CaptionableMessage | 'entities' | 'media_group_id'
|
114 | >
|
115 |
|
116 | type ExtractPartial<T extends object, U extends object> = T extends unknown
|
117 | ? Required<T> extends U
|
118 | ? T
|
119 | : never
|
120 | : never
|
121 |
|
122 |
|
123 |
|
124 |
|
125 | export type MountMap = {
|
126 | [T in UpdateType]: Extract<Update, Record<T, object>>
|
127 | } &
|
128 | {
|
129 | [T in MessageSubType]: {
|
130 | message: ExtractPartial<
|
131 | Update.MessageUpdate['message'],
|
132 | Record<T, unknown>
|
133 | >
|
134 | update_id: number
|
135 | }
|
136 | }
|