UNPKG

5.4 kBTypeScriptView Raw
1/** @format */
2import { Expand } from './core/helpers/util';
3import { Message, Opts, Telegram, Update, InputMediaAudio, InputMediaDocument, InputMediaPhoto, InputMediaVideo } from './core/types/typegram';
4import { UnionKeys } from './deunionize';
5import { FmtString } from './format';
6export { Markup } from './markup';
7export type ChatAction = Opts<'sendChatAction'>['action'];
8export type WrapCaption<T> = T extends {
9 caption?: string;
10} ? Expand<Omit<T, 'caption'> & {
11 caption?: string | FmtString;
12}> : T;
13/**
14 * Create an `Extra*` type from the arguments of a given method `M extends keyof Telegram` but `Omit`ting fields with key `K` from it.
15 *
16 * Note that `chat_id` may not be specified in `K` because it is `Omit`ted by default.
17 */
18type MakeExtra<M extends keyof Telegram, K extends keyof Omit<Opts<M>, 'chat_id'> = never> = WrapCaption<Omit<Opts<M>, 'chat_id' | K>>;
19export type ExtraAddStickerToSet = MakeExtra<'addStickerToSet', 'name' | 'user_id'>;
20export type ExtraAnimation = MakeExtra<'sendAnimation', 'animation'>;
21export type ExtraAnswerCbQuery = MakeExtra<'answerCallbackQuery', 'text' | 'callback_query_id'>;
22export type ExtraAnswerInlineQuery = MakeExtra<'answerInlineQuery', 'inline_query_id' | 'results'>;
23export type ExtraSetChatPermissions = MakeExtra<'setChatPermissions', 'permissions'>;
24export type ExtraAudio = MakeExtra<'sendAudio', 'audio'>;
25export type ExtraContact = MakeExtra<'sendContact', 'phone_number' | 'first_name'>;
26export type ExtraCopyMessage = MakeExtra<'copyMessage', 'from_chat_id' | 'message_id'>;
27export type ExtraCreateChatInviteLink = MakeExtra<'createChatInviteLink'>;
28export type NewInvoiceLinkParameters = MakeExtra<'createInvoiceLink'>;
29export type ExtraCreateNewStickerSet = MakeExtra<'createNewStickerSet', 'name' | 'title' | 'user_id'>;
30export type ExtraDice = MakeExtra<'sendDice'>;
31export type ExtraDocument = MakeExtra<'sendDocument', 'document'>;
32export type ExtraEditChatInviteLink = MakeExtra<'editChatInviteLink', 'invite_link'>;
33export type ExtraEditMessageCaption = MakeExtra<'editMessageCaption', 'message_id' | 'inline_message_id' | 'caption'>;
34export type ExtraEditMessageLiveLocation = MakeExtra<'editMessageLiveLocation', 'message_id' | 'inline_message_id' | 'latitude' | 'longitude'>;
35export type ExtraEditMessageMedia = MakeExtra<'editMessageMedia', 'message_id' | 'inline_message_id' | 'media'>;
36export type ExtraEditMessageText = MakeExtra<'editMessageText', 'message_id' | 'inline_message_id' | 'text'>;
37export type ExtraGame = MakeExtra<'sendGame', 'game_short_name'>;
38export type NewInvoiceParameters = MakeExtra<'sendInvoice', 'disable_notification' | 'reply_to_message_id' | 'allow_sending_without_reply' | 'reply_markup' | 'message_thread_id'>;
39export type ExtraInvoice = MakeExtra<'sendInvoice', keyof NewInvoiceParameters>;
40export type ExtraBanChatMember = MakeExtra<'banChatMember', 'user_id' | 'until_date'>;
41export type ExtraKickChatMember = ExtraBanChatMember;
42export type ExtraLocation = MakeExtra<'sendLocation', 'latitude' | 'longitude'>;
43export type ExtraMediaGroup = MakeExtra<'sendMediaGroup', 'media'>;
44export type ExtraPhoto = MakeExtra<'sendPhoto', 'photo'>;
45export type ExtraPoll = MakeExtra<'sendPoll', 'question' | 'options' | 'type'>;
46export type ExtraPromoteChatMember = MakeExtra<'promoteChatMember', 'user_id'>;
47export type ExtraReplyMessage = MakeExtra<'sendMessage', 'text'>;
48export type ExtraForwardMessage = MakeExtra<'forwardMessage', 'from_chat_id' | 'message_id'>;
49export type ExtraSendChatAction = MakeExtra<'sendChatAction', 'action'>;
50export type ExtraRestrictChatMember = MakeExtra<'restrictChatMember', 'user_id'>;
51export type ExtraSetMyCommands = MakeExtra<'setMyCommands', 'commands'>;
52export type ExtraSetWebhook = MakeExtra<'setWebhook', 'url'>;
53export type ExtraSticker = MakeExtra<'sendSticker', 'sticker'>;
54export type ExtraStopPoll = MakeExtra<'stopPoll', 'message_id'>;
55export type ExtraVenue = MakeExtra<'sendVenue', 'latitude' | 'longitude' | 'title' | 'address'>;
56export type ExtraVideo = MakeExtra<'sendVideo', 'video'>;
57export type ExtraVideoNote = MakeExtra<'sendVideoNote', 'video_note'>;
58export type ExtraVoice = MakeExtra<'sendVoice', 'voice'>;
59export type ExtraBanChatSenderChat = MakeExtra<'banChatSenderChat', 'sender_chat_id'>;
60export type ExtraCreateForumTopic = MakeExtra<'createForumTopic', 'name'>;
61export type ExtraEditForumTopic = MakeExtra<'editForumTopic', 'message_thread_id'>;
62export type MediaGroup = readonly (InputMediaPhoto | InputMediaVideo)[] | readonly InputMediaAudio[] | readonly InputMediaDocument[];
63/** Possible update types */
64export type UpdateType = Exclude<UnionKeys<Update>, keyof Update>;
65/** Possible message subtypes. Same as the properties on a message object */
66export type MessageSubType = 'forward_date' | Exclude<UnionKeys<Message>, keyof Message.CaptionableMessage | 'entities' | 'media_group_id'>;
67type ExtractPartial<T extends object, U extends object> = T extends unknown ? Required<T> extends U ? T : never : never;
68/**
69 * Maps [[`Composer.on`]]'s `updateType` or `messageSubType` to a `tt.Update` subtype.
70 * @deprecated
71 */
72export type MountMap = {
73 [T in UpdateType]: Extract<Update, Record<T, object>>;
74} & {
75 [T in MessageSubType]: {
76 message: ExtractPartial<Update.MessageUpdate['message'], Record<T, unknown>>;
77 update_id: number;
78 };
79};
80//# sourceMappingURL=telegram-types.d.ts.map
\No newline at end of file