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