UNPKG

16.1 kBTypeScriptView Raw
1import * as tg from './core/types/typegram';
2import * as tt from './telegram-types';
3import { Deunionize, PropOr, UnionKeys } from './deunionize';
4import ApiClient from './core/network/client';
5import Telegram from './telegram';
6declare type Tail<T> = T extends [unknown, ...infer U] ? U : never;
7declare type Shorthand<FName extends Exclude<keyof Telegram, keyof ApiClient>> = Tail<Parameters<Telegram[FName]>>;
8export declare class Context<U extends Deunionize<tg.Update> = tg.Update> {
9 readonly update: U;
10 readonly tg: Telegram;
11 readonly botInfo: tg.UserFromGetMe;
12 readonly state: Record<string | symbol, any>;
13 constructor(update: U, tg: Telegram, botInfo: tg.UserFromGetMe);
14 get updateType(): Extract<UnionKeys<U>, tt.UpdateType>;
15 get me(): string;
16 get telegram(): Telegram;
17 get message(): PropOr<U, "message", undefined>;
18 get editedMessage(): PropOr<U, "edited_message", undefined>;
19 get inlineQuery(): PropOr<U, "inline_query", undefined>;
20 get shippingQuery(): PropOr<U, "shipping_query", undefined>;
21 get preCheckoutQuery(): PropOr<U, "pre_checkout_query", undefined>;
22 get chosenInlineResult(): PropOr<U, "chosen_inline_result", undefined>;
23 get channelPost(): PropOr<U, "channel_post", undefined>;
24 get editedChannelPost(): PropOr<U, "edited_channel_post", undefined>;
25 get callbackQuery(): PropOr<U, "callback_query", undefined>;
26 get poll(): PropOr<U, "poll", undefined>;
27 get pollAnswer(): PropOr<U, "poll_answer", undefined>;
28 get myChatMember(): PropOr<U, "my_chat_member", undefined>;
29 get chatMember(): PropOr<U, "chat_member", undefined>;
30 get chat(): Getter<U, 'chat'>;
31 get senderChat(): PropOr<GetUpdateContent<U>, "sender_chat", undefined>;
32 get from(): PropOr<GetUpdateContent<U>, "from", undefined>;
33 get inlineMessageId(): string | undefined;
34 get passportData(): tg.PassportData | undefined;
35 /**
36 * @deprecated use {@link Telegram.webhookReply}
37 */
38 get webhookReply(): boolean;
39 set webhookReply(enable: boolean);
40 private assert;
41 /**
42 * @see https://core.telegram.org/bots/api#answerinlinequery
43 */
44 answerInlineQuery(this: Context, ...args: Shorthand<'answerInlineQuery'>): Promise<true>;
45 /**
46 * @see https://core.telegram.org/bots/api#answercallbackquery
47 */
48 answerCbQuery(this: Context, ...args: Shorthand<'answerCbQuery'>): Promise<true>;
49 /**
50 * @see https://core.telegram.org/bots/api#answercallbackquery
51 */
52 answerGameQuery(this: Context, ...args: Shorthand<'answerGameQuery'>): Promise<true>;
53 /**
54 * @see https://core.telegram.org/bots/api#answershippingquery
55 */
56 answerShippingQuery(this: Context, ...args: Shorthand<'answerShippingQuery'>): Promise<true>;
57 /**
58 * @see https://core.telegram.org/bots/api#answerprecheckoutquery
59 */
60 answerPreCheckoutQuery(this: Context, ...args: Shorthand<'answerPreCheckoutQuery'>): Promise<true>;
61 /**
62 * @see https://core.telegram.org/bots/api#editmessagetext
63 */
64 editMessageText(this: Context, text: string, extra?: tt.ExtraEditMessageText): Promise<true | (tg.Update.Edited & tg.Message.TextMessage)>;
65 /**
66 * @see https://core.telegram.org/bots/api#editmessagecaption
67 */
68 editMessageCaption(this: Context, caption: string | undefined, extra?: tt.ExtraEditMessageCaption): Promise<true | (tg.Update.Edited & tg.Message.CaptionableMessage)>;
69 /**
70 * @see https://core.telegram.org/bots/api#editmessagemedia
71 */
72 editMessageMedia(this: Context, media: tg.InputMedia, extra?: tt.ExtraEditMessageMedia): Promise<true | (tg.Update.Edited & tg.Message.AnimationMessage) | (tg.Update.Edited & tg.Message.DocumentMessage) | (tg.Update.Edited & tg.Message.AudioMessage) | (tg.Update.Edited & tg.Message.PhotoMessage) | (tg.Update.Edited & tg.Message.VideoMessage)>;
73 /**
74 * @see https://core.telegram.org/bots/api#editmessagereplymarkup
75 */
76 editMessageReplyMarkup(this: Context, markup: tg.InlineKeyboardMarkup | undefined): Promise<true | (tg.Update.Edited & tg.Message)>;
77 /**
78 * @see https://core.telegram.org/bots/api#editmessagelivelocation
79 */
80 editMessageLiveLocation(this: Context, latitude: number, longitude: number, extra?: tt.ExtraEditMessageLiveLocation): Promise<true | (tg.Update.Edited & tg.Message.LocationMessage)>;
81 /**
82 * @see https://core.telegram.org/bots/api#stopmessagelivelocation
83 */
84 stopMessageLiveLocation(this: Context, markup?: tg.InlineKeyboardMarkup): Promise<true | (tg.Update.Edited & tg.Message.LocationMessage)>;
85 /**
86 * @see https://core.telegram.org/bots/api#sendmessage
87 */
88 reply(this: Context, ...args: Shorthand<'sendMessage'>): Promise<tg.Message.TextMessage>;
89 /**
90 * @see https://core.telegram.org/bots/api#getchat
91 */
92 getChat(this: Context, ...args: Shorthand<'getChat'>): Promise<tg.ChatFromGetChat>;
93 /**
94 * @see https://core.telegram.org/bots/api#exportchatinvitelink
95 */
96 exportChatInviteLink(this: Context, ...args: Shorthand<'exportChatInviteLink'>): Promise<string>;
97 /**
98 * @see https://core.telegram.org/bots/api#createchatinvitelink
99 */
100 createChatInviteLink(this: Context, ...args: Shorthand<'createChatInviteLink'>): Promise<tg.ChatInviteLink>;
101 /**
102 * @see https://core.telegram.org/bots/api#editchatinvitelink
103 */
104 editChatInviteLink(this: Context, ...args: Shorthand<'editChatInviteLink'>): Promise<tg.ChatInviteLink>;
105 /**
106 * @see https://core.telegram.org/bots/api#revokechatinvitelink
107 */
108 revokeChatInviteLink(this: Context, ...args: Shorthand<'revokeChatInviteLink'>): Promise<tg.ChatInviteLink>;
109 /**
110 * @see https://core.telegram.org/bots/api#banchatmember
111 */
112 kickChatMember(this: Context, ...args: Shorthand<'kickChatMember'>): Promise<true>;
113 /**
114 * @see https://core.telegram.org/bots/api#unbanchatmember
115 */
116 unbanChatMember(this: Context, ...args: Shorthand<'unbanChatMember'>): Promise<true>;
117 /**
118 * @see https://core.telegram.org/bots/api#restrictchatmember
119 */
120 restrictChatMember(this: Context, ...args: Shorthand<'restrictChatMember'>): Promise<true>;
121 /**
122 * @see https://core.telegram.org/bots/api#promotechatmember
123 */
124 promoteChatMember(this: Context, ...args: Shorthand<'promoteChatMember'>): Promise<true>;
125 /**
126 * @see https://core.telegram.org/bots/api#setchatadministratorcustomtitle
127 */
128 setChatAdministratorCustomTitle(this: Context, ...args: Shorthand<'setChatAdministratorCustomTitle'>): Promise<true>;
129 /**
130 * @see https://core.telegram.org/bots/api#setchatphoto
131 */
132 setChatPhoto(this: Context, ...args: Shorthand<'setChatPhoto'>): Promise<true>;
133 /**
134 * @see https://core.telegram.org/bots/api#deletechatphoto
135 */
136 deleteChatPhoto(this: Context, ...args: Shorthand<'deleteChatPhoto'>): Promise<true>;
137 /**
138 * @see https://core.telegram.org/bots/api#setchattitle
139 */
140 setChatTitle(this: Context, ...args: Shorthand<'setChatTitle'>): Promise<true>;
141 /**
142 * @see https://core.telegram.org/bots/api#setchatdescription
143 */
144 setChatDescription(this: Context, ...args: Shorthand<'setChatDescription'>): Promise<true>;
145 /**
146 * @see https://core.telegram.org/bots/api#pinchatmessage
147 */
148 pinChatMessage(this: Context, ...args: Shorthand<'pinChatMessage'>): Promise<true>;
149 /**
150 * @see https://core.telegram.org/bots/api#unpinchatmessage
151 */
152 unpinChatMessage(this: Context, ...args: Shorthand<'unpinChatMessage'>): Promise<true>;
153 /**
154 * @see https://core.telegram.org/bots/api#unpinallchatmessages
155 */
156 unpinAllChatMessages(this: Context, ...args: Shorthand<'unpinAllChatMessages'>): Promise<true>;
157 /**
158 * @see https://core.telegram.org/bots/api#leavechat
159 */
160 leaveChat(this: Context, ...args: Shorthand<'leaveChat'>): Promise<true>;
161 /**
162 * @see https://core.telegram.org/bots/api#setchatpermissions
163 */
164 setChatPermissions(this: Context, ...args: Shorthand<'setChatPermissions'>): Promise<true>;
165 /**
166 * @see https://core.telegram.org/bots/api#getchatadministrators
167 */
168 getChatAdministrators(this: Context, ...args: Shorthand<'getChatAdministrators'>): Promise<tg.ChatMember[]>;
169 /**
170 * @see https://core.telegram.org/bots/api#getchatmember
171 */
172 getChatMember(this: Context, ...args: Shorthand<'getChatMember'>): Promise<tg.ChatMember>;
173 /**
174 * @see https://core.telegram.org/bots/api#getchatmembercount
175 */
176 getChatMembersCount(this: Context, ...args: Shorthand<'getChatMembersCount'>): Promise<number>;
177 /**
178 * @see https://core.telegram.org/bots/api#setpassportdataerrors
179 */
180 setPassportDataErrors(this: Context, errors: readonly tg.PassportElementError[]): Promise<true>;
181 /**
182 * @see https://core.telegram.org/bots/api#replywithphoto
183 */
184 replyWithPhoto(this: Context, ...args: Shorthand<'sendPhoto'>): Promise<tg.Message.PhotoMessage>;
185 /**
186 * @see https://core.telegram.org/bots/api#replywithmediagroup
187 */
188 replyWithMediaGroup(this: Context, ...args: Shorthand<'sendMediaGroup'>): Promise<(tg.Message.DocumentMessage | tg.Message.AudioMessage | tg.Message.PhotoMessage | tg.Message.VideoMessage)[]>;
189 /**
190 * @see https://core.telegram.org/bots/api#replywithaudio
191 */
192 replyWithAudio(this: Context, ...args: Shorthand<'sendAudio'>): Promise<tg.Message.AudioMessage>;
193 /**
194 * @see https://core.telegram.org/bots/api#replywithdice
195 */
196 replyWithDice(this: Context, ...args: Shorthand<'sendDice'>): Promise<tg.Message.DiceMessage>;
197 /**
198 * @see https://core.telegram.org/bots/api#replywithdocument
199 */
200 replyWithDocument(this: Context, ...args: Shorthand<'sendDocument'>): Promise<tg.Message.DocumentMessage>;
201 /**
202 * @see https://core.telegram.org/bots/api#replywithsticker
203 */
204 replyWithSticker(this: Context, ...args: Shorthand<'sendSticker'>): Promise<tg.Message.StickerMessage>;
205 /**
206 * @see https://core.telegram.org/bots/api#replywithvideo
207 */
208 replyWithVideo(this: Context, ...args: Shorthand<'sendVideo'>): Promise<tg.Message.VideoMessage>;
209 /**
210 * @see https://core.telegram.org/bots/api#replywithanimation
211 */
212 replyWithAnimation(this: Context, ...args: Shorthand<'sendAnimation'>): Promise<tg.Message.AnimationMessage>;
213 /**
214 * @see https://core.telegram.org/bots/api#replywithvideonote
215 */
216 replyWithVideoNote(this: Context, ...args: Shorthand<'sendVideoNote'>): Promise<tg.Message.VideoNoteMessage>;
217 /**
218 * @see https://core.telegram.org/bots/api#replywithinvoice
219 */
220 replyWithInvoice(this: Context, ...args: Shorthand<'sendInvoice'>): Promise<tg.Message.InvoiceMessage>;
221 /**
222 * @see https://core.telegram.org/bots/api#replywithgame
223 */
224 replyWithGame(this: Context, ...args: Shorthand<'sendGame'>): Promise<tg.Message.GameMessage>;
225 /**
226 * @see https://core.telegram.org/bots/api#replywithvoice
227 */
228 replyWithVoice(this: Context, ...args: Shorthand<'sendVoice'>): Promise<tg.Message.VoiceMessage>;
229 /**
230 * @see https://core.telegram.org/bots/api#replywithpoll
231 */
232 replyWithPoll(this: Context, ...args: Shorthand<'sendPoll'>): Promise<tg.Message.PollMessage>;
233 /**
234 * @see https://core.telegram.org/bots/api#replywithquiz
235 */
236 replyWithQuiz(this: Context, ...args: Shorthand<'sendQuiz'>): Promise<tg.Message.PollMessage>;
237 /**
238 * @see https://core.telegram.org/bots/api#stoppoll
239 */
240 stopPoll(this: Context, ...args: Shorthand<'stopPoll'>): Promise<tg.Poll>;
241 /**
242 * @see https://core.telegram.org/bots/api#replywithchataction
243 */
244 replyWithChatAction(this: Context, ...args: Shorthand<'sendChatAction'>): Promise<true>;
245 /**
246 * @see https://core.telegram.org/bots/api#replywithlocation
247 */
248 replyWithLocation(this: Context, ...args: Shorthand<'sendLocation'>): Promise<tg.Message.LocationMessage>;
249 /**
250 * @see https://core.telegram.org/bots/api#replywithvenue
251 */
252 replyWithVenue(this: Context, ...args: Shorthand<'sendVenue'>): Promise<tg.Message.VenueMessage>;
253 /**
254 * @see https://core.telegram.org/bots/api#replywithcontact
255 */
256 replyWithContact(this: Context, ...args: Shorthand<'sendContact'>): Promise<tg.Message.ContactMessage>;
257 /**
258 * @deprecated use {@link Telegram.getStickerSet}
259 * @see https://core.telegram.org/bots/api#getstickerset
260 */
261 getStickerSet(this: Context, setName: string): Promise<tg.StickerSet>;
262 /**
263 * @see https://core.telegram.org/bots/api#setchatstickerset
264 */
265 setChatStickerSet(this: Context, setName: string): Promise<true>;
266 /**
267 * @see https://core.telegram.org/bots/api#deletechatstickerset
268 */
269 deleteChatStickerSet(this: Context): Promise<true>;
270 /**
271 * @deprecated use {@link Telegram.setStickerPositionInSet}
272 * @see https://core.telegram.org/bots/api#setstickerpositioninset
273 */
274 setStickerPositionInSet(this: Context, sticker: string, position: number): Promise<true>;
275 /**
276 * @deprecated use {@link Telegram.setStickerSetThumb}
277 * @see https://core.telegram.org/bots/api#setstickersetthumb
278 */
279 setStickerSetThumb(this: Context, ...args: Parameters<Telegram['setStickerSetThumb']>): Promise<true>;
280 /**
281 * @deprecated use {@link Telegram.deleteStickerFromSet}
282 * @see https://core.telegram.org/bots/api#deletestickerfromset
283 */
284 deleteStickerFromSet(this: Context, sticker: string): Promise<true>;
285 /**
286 * @see https://core.telegram.org/bots/api#uploadstickerfile
287 */
288 uploadStickerFile(this: Context, ...args: Shorthand<'uploadStickerFile'>): Promise<tg.File>;
289 /**
290 * @see https://core.telegram.org/bots/api#createnewstickerset
291 */
292 createNewStickerSet(this: Context, ...args: Shorthand<'createNewStickerSet'>): Promise<true>;
293 /**
294 * @see https://core.telegram.org/bots/api#addstickertoset
295 */
296 addStickerToSet(this: Context, ...args: Shorthand<'addStickerToSet'>): Promise<true>;
297 /**
298 * @deprecated use {@link Telegram.getMyCommands}
299 * @see https://core.telegram.org/bots/api#getmycommands
300 */
301 getMyCommands(this: Context): Promise<tg.BotCommand[]>;
302 /**
303 * @deprecated use {@link Telegram.setMyCommands}
304 * @see https://core.telegram.org/bots/api#setmycommands
305 */
306 setMyCommands(this: Context, commands: readonly tg.BotCommand[]): Promise<true>;
307 /**
308 * @see https://core.telegram.org/bots/api#sendmessage
309 */
310 replyWithMarkdown(this: Context, markdown: string, extra?: tt.ExtraReplyMessage): Promise<tg.Message.TextMessage>;
311 /**
312 * @see https://core.telegram.org/bots/api#sendmessage
313 */
314 replyWithMarkdownV2(this: Context, markdown: string, extra?: tt.ExtraReplyMessage): Promise<tg.Message.TextMessage>;
315 /**
316 * @see https://core.telegram.org/bots/api#sendmessage
317 */
318 replyWithHTML(this: Context, html: string, extra?: tt.ExtraReplyMessage): Promise<tg.Message.TextMessage>;
319 /**
320 * @see https://core.telegram.org/bots/api#deletemessage
321 */
322 deleteMessage(this: Context, messageId?: number): Promise<true>;
323 /**
324 * @see https://core.telegram.org/bots/api#forwardmessage
325 */
326 forwardMessage(this: Context, chatId: string | number, extra?: {
327 disable_notification?: boolean;
328 }): Promise<tg.Message>;
329 /**
330 * @see https://core.telegram.org/bots/api#copymessage
331 */
332 copyMessage(this: Context, chatId: string | number, extra?: tt.ExtraCopyMessage): Promise<tg.MessageId>;
333}
334export default Context;
335declare type UpdateTypes<U extends Deunionize<tg.Update>> = Extract<UnionKeys<U>, tt.UpdateType>;
336export declare type GetUpdateContent<U extends tg.Update> = U extends tg.Update.CallbackQueryUpdate ? U['callback_query']['message'] : U[UpdateTypes<U>];
337declare type Getter<U extends Deunionize<tg.Update>, P extends string> = PropOr<GetUpdateContent<U>, P>;
338//# sourceMappingURL=context.d.ts.map
\No newline at end of file