UNPKG

6.5 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 './core/helpers/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 ExtraCopyMessages = MakeExtra<'copyMessages', 'from_chat_id' | 'message_ids'>;
28export type ExtraCreateChatInviteLink = MakeExtra<'createChatInviteLink'>;
29export type NewInvoiceLinkParameters = MakeExtra<'createInvoiceLink'>;
30export type ExtraCreateNewStickerSet = MakeExtra<'createNewStickerSet', 'name' | 'title' | 'user_id'>;
31export type ExtraDice = MakeExtra<'sendDice'>;
32export type ExtraDocument = MakeExtra<'sendDocument', 'document'>;
33export type ExtraEditChatInviteLink = MakeExtra<'editChatInviteLink', 'invite_link'>;
34export type ExtraEditMessageCaption = MakeExtra<'editMessageCaption', 'message_id' | 'inline_message_id' | 'caption'>;
35export type ExtraEditMessageLiveLocation = MakeExtra<'editMessageLiveLocation', 'message_id' | 'inline_message_id' | 'latitude' | 'longitude'>;
36export type ExtraEditMessageMedia = MakeExtra<'editMessageMedia', 'message_id' | 'inline_message_id' | 'media'>;
37export type ExtraEditMessageText = MakeExtra<'editMessageText', 'message_id' | 'inline_message_id' | 'text'>;
38export type ExtraGame = MakeExtra<'sendGame', 'game_short_name'>;
39export type NewInvoiceParameters = MakeExtra<'sendInvoice', 'disable_notification' | 'reply_parameters' | 'reply_markup' | 'message_thread_id'>;
40export type ExtraInvoice = MakeExtra<'sendInvoice', keyof NewInvoiceParameters>;
41export type ExtraBanChatMember = MakeExtra<'banChatMember', 'user_id' | 'until_date'>;
42export type ExtraKickChatMember = ExtraBanChatMember;
43export type ExtraLocation = MakeExtra<'sendLocation', 'latitude' | 'longitude'>;
44export type ExtraMediaGroup = MakeExtra<'sendMediaGroup', 'media'>;
45export type ExtraPhoto = MakeExtra<'sendPhoto', 'photo'>;
46export type ExtraPoll = MakeExtra<'sendPoll', 'question' | 'options' | 'type'>;
47export type ExtraPromoteChatMember = MakeExtra<'promoteChatMember', 'user_id'>;
48export type ExtraReplyMessage = MakeExtra<'sendMessage', 'text'>;
49export type ExtraForwardMessage = MakeExtra<'forwardMessage', 'from_chat_id' | 'message_id'>;
50export type ExtraForwardMessages = MakeExtra<'forwardMessages', 'from_chat_id' | 'message_ids'>;
51export type ExtraSendChatAction = MakeExtra<'sendChatAction', 'action'>;
52export type ExtraRestrictChatMember = MakeExtra<'restrictChatMember', 'user_id'>;
53export type ExtraSetMyCommands = MakeExtra<'setMyCommands', 'commands'>;
54export type ExtraSetWebhook = MakeExtra<'setWebhook', 'url'>;
55export type ExtraSticker = MakeExtra<'sendSticker', 'sticker'>;
56export type ExtraStopPoll = MakeExtra<'stopPoll', 'message_id'>;
57export type ExtraVenue = MakeExtra<'sendVenue', 'latitude' | 'longitude' | 'title' | 'address'>;
58export type ExtraVideo = MakeExtra<'sendVideo', 'video'>;
59export type ExtraVideoNote = MakeExtra<'sendVideoNote', 'video_note'>;
60export type ExtraVoice = MakeExtra<'sendVoice', 'voice'>;
61export type ExtraBanChatSenderChat = MakeExtra<'banChatSenderChat', 'sender_chat_id'>;
62export type ExtraCreateForumTopic = MakeExtra<'createForumTopic', 'name'>;
63export type ExtraEditForumTopic = MakeExtra<'editForumTopic', 'message_thread_id'>;
64export type MediaGroup = readonly (InputMediaPhoto | InputMediaVideo)[] | readonly InputMediaAudio[] | readonly InputMediaDocument[];
65/** Possible update types */
66export type UpdateType = Exclude<UnionKeys<Update>, keyof Update>;
67/** Possible message subtypes. Same as the properties on a message object */
68export type MessageSubType = 'forward_date' | Exclude<UnionKeys<Message>, keyof Message.CaptionableMessage | 'entities' | 'media_group_id'>;
69type ExtractPartial<T extends object, U extends object> = T extends unknown ? Required<T> extends U ? T : never : never;
70/**
71 * Maps [[`Composer.on`]]'s `updateType` or `messageSubType` to a `tt.Update` subtype.
72 * @deprecated
73 */
74export type MountMap = {
75 [T in UpdateType]: Extract<Update, Record<T, object>>;
76} & {
77 [T in MessageSubType]: {
78 message: ExtractPartial<Update.MessageUpdate['message'], Record<T, unknown>>;
79 update_id: number;
80 };
81};
82export interface CommandContextExtn {
83 match: RegExpExecArray;
84 /**
85 * Matched command. This will always be the actual command, excluding preceeding slash and `@botname`
86 *
87 * Examples:
88 * ```
89 * /command abc -> command
90 * /command@xyzbot abc -> command
91 * ```
92 */
93 command: string;
94 /**
95 * The unparsed payload part of the command
96 *
97 * Examples:
98 * ```
99 * /command abc def -> "abc def"
100 * /command "token1 token2" -> "\"token1 token2\""
101 * ```
102 */
103 payload: string;
104 /**
105 * Command args parsed into an array.
106 *
107 * Examples:
108 * ```
109 * /command token1 token2 -> [ "token1", "token2" ]
110 * /command "token1 token2" -> [ "token1 token2" ]
111 * /command token1 "token2 token3" -> [ "token1" "token2 token3" ]
112 * ```
113 * @unstable Parser implementation might vary until considered stable
114 * */
115 args: string[];
116}
117//# sourceMappingURL=telegram-types.d.ts.map
\No newline at end of file