UNPKG

@gramio/contexts

Version:

Contexts for GramIO framework

1,201 lines (1,162 loc) 352 kB
import * as _gramio_types from '@gramio/types'; import { TelegramObjects, TelegramInputMedia, TelegramUpdate, APIMethods, APIMethodParams, TelegramResponseParameters, APIMethodReturn, TelegramParams, TelegramMessage } from '@gramio/types'; /** * This object describes the types of gifts that can be gifted to a user or a chat. * * [Documentation](https://core.telegram.org/bots/api/#acceptedgifttypes) */ declare class AcceptedGiftTypes { payload: TelegramObjects.TelegramAcceptedGiftTypes; constructor(payload: TelegramObjects.TelegramAcceptedGiftTypes); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * True, if unlimited regular gifts are accepted */ get unlimitedGifts(): boolean; /** * True, if limited regular gifts are accepted */ get limitedGifts(): boolean; /** * True, if unique gifts or gifts that can be upgraded to unique for free are accepted */ get uniqueGifts(): boolean; /** * True, if a Telegram Premium subscription is accepted */ get premiumSubscription(): boolean; /** * True, if transfers of unique gifts from channels are accepted */ get giftsFromChannels(): boolean; } /** Helper to detect if a type is 'any' */ type IsAny<T> = 0 extends 1 & T ? true : false; interface Suppress<IsSuppressed extends boolean | undefined = undefined> { /** * Pass `true` if you want to suppress throwing errors of this method. * * **But this does not undo getting into the `onResponseError` hook**. * * @example * ```ts * const response = await bot.api.sendMessage({ * suppress: true, * chat_id: "@not_found", * text: "Suppressed method" * }); * * if(response instanceof TelegramError) console.error("sendMessage returns an error...") * else console.log("Message has been sent successfully"); * ``` * * */ suppress?: IsSuppressed; } type SuppressedParams<Method extends keyof APIMethods, IsSuppressed extends boolean | undefined = undefined> = APIMethodParams<Method> & Suppress<IsSuppressed>; interface TelegramError<T extends keyof APIMethods> extends Error { method: T; params: APIMethodParams<T>; code: number; payload?: TelegramResponseParameters; } type SuppressedReturn<Method extends keyof APIMethods, IsSuppressed extends boolean | undefined = undefined> = true extends IsSuppressed ? TelegramError<Method> | APIMethodReturn<Method> : APIMethodReturn<Method>; type SuppressedAPIMethods<Methods extends keyof APIMethods = keyof APIMethods> = { [APIMethod in Methods]: APIMethodParams<APIMethod> extends undefined ? <IsSuppressed extends boolean | undefined = undefined>(params?: Suppress<IsSuppressed>) => Promise<SuppressedReturn<APIMethod, IsSuppressed>> : undefined extends APIMethodParams<APIMethod> ? <IsSuppressed extends boolean | undefined = undefined>(params?: SuppressedParams<APIMethod, IsSuppressed>) => Promise<SuppressedReturn<APIMethod, IsSuppressed>> : <IsSuppressed extends boolean | undefined = undefined>(params: SuppressedParams<APIMethod, IsSuppressed>) => Promise<SuppressedReturn<APIMethod, IsSuppressed>>; }; /** The required object that the contexts are based on */ interface BotLike { __Derives: Record<UpdateName | "global", {}>; api: SuppressedAPIMethods; downloadFile(attachment: Attachment | { file_id: string; } | string): Promise<ArrayBuffer>; downloadFile(attachment: Attachment | { file_id: string; } | string, path: string): Promise<string>; } type GetDerives<Bot extends BotLike, Event extends keyof ContextsMapping<Bot>> = IsAny<Bot["__Derives"]> extends true ? {} : Bot["__Derives"]["global"] & Bot["__Derives"][Event]; type MessageContextWithRequiredFrom<Bot extends BotLike> = Constructor<InstanceType<MessageContext<Bot>> & Require<InstanceType<MessageContext<Bot>>, "from">>; /** Mapping events to their contexts */ type ContextsMapping<Bot extends BotLike> = { callback_query: CallbackQueryContext<Bot>; chat_join_request: ChatJoinRequestContext<Bot>; chat_member: ChatMemberContext<Bot>; my_chat_member: ChatMemberContext<Bot>; chosen_inline_result: ChosenInlineResultContext<Bot>; delete_chat_photo: DeleteChatPhotoContext<Bot>; group_chat_created: GroupChatCreatedContext<Bot>; inline_query: InlineQueryContext<Bot>; invoice: InvoiceContext<Bot>; left_chat_member: LeftChatMemberContext<Bot>; location: LocationContext<Bot>; managed_bot: ManagedBotContext<Bot>; managed_bot_created: ManagedBotCreatedContext<Bot>; message_auto_delete_timer_changed: MessageAutoDeleteTimerChangedContext<Bot>; message: MessageContextWithRequiredFrom<Bot>; channel_post: MessageContext<Bot>; edited_message: MessageContextWithRequiredFrom<Bot>; edited_channel_post: MessageContextWithRequiredFrom<Bot>; business_message: MessageContextWithRequiredFrom<Bot>; edited_business_message: MessageContextWithRequiredFrom<Bot>; guest_message: MessageContextWithRequiredFrom<Bot>; deleted_business_messages: BusinessMessagesDeletedContext<Bot>; business_connection: BusinessConnectionContext<Bot>; migrate_from_chat_id: MigrateFromChatIdContext<Bot>; migrate_to_chat_id: MigrateToChatIdContext<Bot>; new_chat_members: NewChatMembersContext<Bot>; new_chat_photo: NewChatPhotoContext<Bot>; new_chat_title: NewChatTitleContext<Bot>; passport_data: PassportDataContext<Bot>; pinned_message: PinnedMessageContext<Bot>; poll_answer: PollAnswerContext<Bot>; poll_option_added: PollOptionAddedContext<Bot>; poll_option_deleted: PollOptionDeletedContext<Bot>; poll: PollContext<Bot>; pre_checkout_query: PreCheckoutQueryContext<Bot>; proximity_alert_triggered: ProximityAlertTriggeredContext<Bot>; write_access_allowed: WriteAccessAllowedContext<Bot>; boost_added: BoostAddedContext<Bot>; chat_background_set: ChatBackgroundSetContext<Bot>; checklist_tasks_done: ChecklistTasksDoneContext<Bot>; checklist_tasks_added: ChecklistTasksAddedContext<Bot>; direct_message_price_changed: DirectMessagePriceChangedContext<Bot>; suggested_post_approved: SuggestedPostApprovedContext<Bot>; suggested_post_approval_failed: SuggestedPostApprovalFailedContext<Bot>; suggested_post_declined: SuggestedPostDeclinedContext<Bot>; suggested_post_paid: SuggestedPostPaidContext<Bot>; suggested_post_refunded: SuggestedPostRefundedContext<Bot>; forum_topic_created: ForumTopicCreatedContext<Bot>; forum_topic_edited: ForumTopicEditedContext<Bot>; forum_topic_closed: ForumTopicClosedContext<Bot>; forum_topic_reopened: ForumTopicReopenedContext<Bot>; general_forum_topic_hidden: GeneralForumTopicHiddenContext<Bot>; general_forum_topic_unhidden: GeneralForumTopicUnhiddenContext<Bot>; shipping_query: ShippingQueryContext<Bot>; successful_payment: SuccessfulPaymentContext<Bot>; refunded_payment: RefundedPaymentContext<Bot>; users_shared: UsersSharedContext<Bot>; chat_shared: ChatSharedContext<Bot>; gift: GiftContext<Bot>; gift_upgrade_sent: GiftUpgradeSentContext<Bot>; unique_gift: UniqueGiftContext<Bot>; chat_owner_left: ChatOwnerLeftContext<Bot>; chat_owner_changed: ChatOwnerChangedContext<Bot>; paid_message_price_changed: PaidMessagePriceChangedContext<Bot>; video_chat_ended: VideoChatEndedContext<Bot>; video_chat_participants_invited: VideoChatParticipantsInvitedContext<Bot>; video_chat_scheduled: VideoChatScheduledContext<Bot>; video_chat_started: VideoChatStartedContext<Bot>; web_app_data: WebAppDataContext<Bot>; service_message: MessageContext<Bot>; message_reaction: MessageReactionContext<Bot>; message_reaction_count: MessageReactionCountContext<Bot>; chat_boost: ChatBoostContext<Bot>; removed_chat_boost: RemovedChatBoostContext<Bot>; giveaway_created: GiveawayCreatedContext<Bot>; giveaway_completed: GiveawayCompletedContext<Bot>; giveaway_winners: GiveawayWinnersContext<Bot>; purchased_paid_media: PaidMediaPurchasedContext<Bot>; }; /** * Type util to get type of Context * * @example * ```ts * type Message = ContextType<Bot, "message">; * ``` * * */ type ContextType<Bot extends BotLike, Name extends keyof ContextsMapping<Bot>> = InstanceType<ContextsMapping<Bot>[Name]> & GetDerives<Bot, Name>; /** Union type of MessageEvent names */ type MessageEventName = "new_chat_members" | "left_chat_member" | "new_chat_title" | "new_chat_photo" | "delete_chat_photo" | "group_chat_created" | "message_auto_delete_timer_changed" | "migrate_to_chat_id" | "migrate_from_chat_id" | "pinned_message" | "invoice" | "successful_payment" | "refunded_payment" | "users_shared" | "chat_shared" | "gift" | "gift_upgrade_sent" | "unique_gift" | "chat_owner_left" | "chat_owner_changed" | "paid_message_price_changed" | "proximity_alert_triggered" | "write_access_allowed" | "forum_topic_created" | "forum_topic_edited" | "forum_topic_closed" | "forum_topic_reopened" | "general_forum_topic_hidden" | "general_forum_topic_unhidden" | "video_chat_scheduled" | "video_chat_started" | "video_chat_ended" | "video_chat_participants_invited" | "web_app_data" | "location" | "passport_data" | "giveaway_created" | "giveaway_completed" | "giveaway_winners" | "boost_added" | "chat_background_set" | "checklist_tasks_done" | "checklist_tasks_added" | "direct_message_price_changed" | "suggested_post_approved" | "suggested_post_approval_failed" | "suggested_post_declined" | "suggested_post_paid" | "suggested_post_refunded" | "managed_bot_created" | "poll_option_added" | "poll_option_deleted"; /** Custom Event Name */ type CustomEventName = "service_message"; /** Union type of Update names */ type UpdateName = Exclude<keyof TelegramUpdate, "update_id"> | MessageEventName | CustomEventName; /** Type helper to join union type */ type JoinUnion<T> = T extends infer U ? U extends any ? // biome-ignore lint/suspicious/noExplicitAny: <explanation> Record<string, any> & U : never : never; /** Type helper to add array and non-array type */ type MaybeArray<T> = T | T[]; /** Union type of attachments type */ type AttachmentType = TelegramInputMedia["type"] | "sticker" | "video_note" | "voice" | "contact" | "poll" | "venue" | "location" | "story"; /** Permits `string` but gives hints */ type SoftString<S extends string> = (string & {}) | S; /** Like `Required<T>` but for specified keys of `T` */ type Require<O, K extends keyof O> = { [P in K]-?: NonNullable<O[P]>; }; /** Type helper constructor */ type Constructor<T = {}> = new (...args: any[]) => T; /** Like `Require<O, K>` but it sets `V` as the value for `K` values */ type RequireValue<O, K extends keyof O, V> = Omit<O, K> & { [P in K]-?: V; }; /** Make some keys optional */ type Optional<T, K extends keyof T> = /** We pick every field but `K` and leave them as is */ Pick<T, Exclude<keyof T, K>> /** Then, we take our `K` fields and mark them as optional */ & { [P in K]?: T[P]; } /** Lastly, we add `[key: string]: any;` */ /** Lastly, we add `[key: string]: any;` */ & {}; /** Type util to make chat_id optional and add type property */ type id<T, I extends { chat_id: string | number; }> = { type: T; } & Optional<I, "chat_id">; /** This type represent SendAnimationParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendAnimation = id<"animation", TelegramParams.SendAnimationParams>; /** This type represent SendAudioParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendAudio = id<"audio", TelegramParams.SendAudioParams>; /** This type represent SendDocumentParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendDocument = id<"document", TelegramParams.SendDocumentParams>; /** This type represent SendPhotoParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendPhoto = id<"photo", TelegramParams.SendPhotoParams>; /** This type represent SendStickerParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendSticker = id<"sticker", TelegramParams.SendStickerParams>; /** This type represent SendVideoParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendVideo = id<"video", TelegramParams.SendVideoParams>; /** This type represent SendVideoNoteParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendVideoNote = id<"video_note", TelegramParams.SendVideoNoteParams>; /** This type represent SendVoiceParams and used by {@link Contexts.MessageContext.sendMedia} */ type tSendVoice = id<"voice", TelegramParams.SendVoiceParams>; /** This Union type represent a media that can be sended and used by {@link Contexts.MessageContext.sendMedia} */ type tSendMethods = tSendAnimation | tSendAudio | tSendDocument | tSendPhoto | tSendSticker | tSendVideo | tSendVideoNote | tSendVoice; /** Enum of ChatType property */ declare enum ChatType { Private = "private", Group = "group", Supergroup = "supergroup", Channel = "channel" } /** Enum of PollType property */ declare enum PollType { Regular = "regular", Quiz = "quiz" } /** Mapping attachments type to their structures */ interface AttachmentsMapping { animation: AnimationAttachment; audio: AudioAttachment; contact: ContactAttachment; document: DocumentAttachment; live_photo: LivePhotoAttachment; location: LocationAttachment; photo: PhotoAttachment; poll: PollAttachment; sticker: StickerAttachment; story: StoryAttachment; venue: VenueAttachment; video_note: VideoNoteAttachment; video: VideoAttachment; voice: VoiceAttachment; } /** A chunk of text for streaming via sendMessageDraft */ type MessageDraftPiece = string | { /** Optional draft identifier to control message splitting */ draft_id?: number; /** The text content of this chunk */ text: string; /** Optional entities for this chunk (offsets relative to entire stream) */ entities?: TelegramObjects.TelegramMessageEntity[]; }; /** Options for SendMixin.streamMessage */ interface StreamMessageOptions { /** Offset added to draft IDs. Defaults to 256 * updateId */ draftIdOffset?: number; /** Extra params for sendMessageDraft calls (e.g. parse_mode) */ draftParams?: Omit<TelegramParams.SendMessageDraftParams, "chat_id" | "draft_id" | "text" | "entities">; /** Extra params for sendMessage calls (e.g. reply_markup) */ messageParams?: Optional<TelegramParams.SendMessageParams, "chat_id" | "text" | "entities">; /** AbortSignal to cancel streaming */ signal?: AbortSignal; } /** Enum of EntityType property */ declare enum EntityType { Mention = "mention", Hashtag = "hashtag", Cashtag = "cashtag", BotCommand = "bot_command", Url = "url", Email = "email", PhoneNumber = "phone_number", Bold = "bold", Italic = "italic", Underline = "underline", Strikethrough = "strikethrough", Code = "code", Pre = "pre", TextLink = "text_link", TextMention = "text_mention" } /** This object represents one size of a photo or a file / sticker thumbnail */ declare class PhotoSize { payload: TelegramObjects.TelegramPhotoSize; constructor(payload: TelegramObjects.TelegramPhotoSize); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Identifier for this file, which can be used to download or reuse the file */ get fileId(): string; /** * Unique identifier for this file, which is supposed to be the same over * time and for different bots. Can't be used to download or reuse the file. */ get fileUniqueId(): string; /** Photo width */ get width(): number; /** Photo height */ get height(): number; /** File size */ get fileSize(): number | undefined; } /** Simple attachment */ declare class Attachment { attachmentType?: AttachmentType; /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; } /** Base interface for attachment */ interface DefaultAttachment { file_id: string; file_unique_id: string; } /** Attachment with `fileId` and `fileUniqueId` properties */ declare class FileAttachment<T extends DefaultAttachment = DefaultAttachment> extends Attachment { protected payload: T; /** Returns attachment's type (e.g. `'audio'`, `'photo'`) */ attachmentType?: AttachmentType; constructor(payload: T); /** Identifier for this file, which can be used to download or reuse the file */ get fileId(): string; /** * Unique identifier for this file, which is supposed to be the same over * time and for different bots. Can't be used to download or reuse the file. */ get fileUniqueId(): string; } /** * This object represents an animation file * (GIF or H.264/MPEG-4 AVC video without sound). */ declare class AnimationAttachment extends FileAttachment<TelegramObjects.TelegramAnimation> { attachmentType: AttachmentType; /** Video width as defined by sender */ get width(): number; /** Video height as defined by sender */ get height(): number; /** Duration of the video in seconds as defined by sender */ get duration(): number; /** Animation thumbnail as defined by sender */ get thumbnail(): PhotoSize | undefined; /** Original animation filename as defined by sender */ get fileName(): string | undefined; /** MIME type of the file as defined by sender */ get mimeType(): string | undefined; /** File size */ get fileSize(): number | undefined; } /** * This object represents an audio file to be treated as music by the Telegram * clients. */ declare class AudioAttachment extends FileAttachment<TelegramObjects.TelegramAudio> { attachmentType: AttachmentType; /** Duration of the audio in seconds as defined by sender */ get duration(): number; /** Performer of the audio as defined by sender or by audio tags */ get performer(): string | undefined; /** Title of the audio as defined by sender or by audio tags */ get title(): string | undefined; /** Original filename as defined by sender */ get fileName(): string | undefined; /** MIME type of the file as defined by sender */ get mimeType(): string | undefined; /** File size */ get fileSize(): number | undefined; /** Thumbnail of the album cover to which the music file belongs */ get thumbnail(): PhotoSize | undefined; } /** This object represents a phone contact. */ declare class Contact { payload: TelegramObjects.TelegramContact; constructor(payload: TelegramObjects.TelegramContact); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Contact's phone number */ get phoneNumber(): string; /** Contact's first name */ get firstName(): string; /** Contact's last name */ get lastName(): string | undefined; /** Contact's user identifier in Telegram */ get userId(): number | undefined; /** Additional data about the contact in the form of a vCard */ get vCard(): string | undefined; } /** This object represents a phone contact. */ declare class ContactAttachment extends Contact { attachmentType: AttachmentType; } interface ContactAttachment extends Attachment { } /** * This object represents a general file (as opposed to photos, voice messages * and audio files). */ declare class DocumentAttachment extends FileAttachment<TelegramObjects.TelegramDocument> { attachmentType: AttachmentType; /** Document thumbnail as defined by sender */ get thumbnail(): PhotoSize | undefined; /** Original filename as defined by sender */ get fileName(): string | undefined; /** MIME type of the file as defined by sender */ get mimeType(): string | undefined; /** File size */ get fileSize(): number | undefined; } /** This object represents a live photo. */ declare class LivePhotoAttachment extends FileAttachment<TelegramObjects.TelegramLivePhoto> { attachmentType: AttachmentType; /** Available sizes of the corresponding static photo */ get photo(): PhotoSize[] | undefined; /** Video width as defined by the sender */ get width(): number; /** Video height as defined by the sender */ get height(): number; /** Duration of the video in seconds as defined by the sender */ get duration(): number; /** MIME type of the file as defined by the sender */ get mimeType(): string | undefined; /** File size in bytes */ get fileSize(): number | undefined; } /** This object represents a point on the map. */ declare class Location { payload: TelegramObjects.TelegramLocation; constructor(payload: TelegramObjects.TelegramLocation); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Longitude as defined by sender */ get longitude(): number; /** Latitude as defined by sender */ get latitude(): number; /** The radius of uncertainty for the location, measured in meters; `0-1500` */ get horizontalAccuracy(): number | undefined; /** * Time relative to the message sending date, * during which the location can be updated, in seconds. * For active live locations only. */ get livePeriod(): number | undefined; /** * The direction in which user is moving, in degrees; `1-360`. * For active live locations only. */ get heading(): number | undefined; /** * Maximum distance for proximity alerts about approaching another chat member, in meters. * For sent live locations only. */ get proximityAlertRadius(): number | undefined; } /** This object represents a point on the map. */ declare class LocationAttachment extends Location { attachmentType: AttachmentType; } interface LocationAttachment extends Attachment { } /** This object represents a photo file with it's sizes */ declare class PhotoAttachment extends Attachment { private payload; private readonly sorted; attachmentType: AttachmentType; constructor(payload: PhotoSize[]); /** Photo sizes */ get sizes(): PhotoSize[]; /** Biggest size of the photo */ get bigSize(): PhotoSize; /** Medium size of the photo */ get mediumSize(): PhotoSize; /** Smallest size of the photo */ get smallSize(): PhotoSize; } /** This object represents a Telegram user or bot. */ declare class User { payload: TelegramObjects.TelegramUser; constructor(payload: TelegramObjects.TelegramUser); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Unique identifier for this user or bot */ get id(): number; /** `true`, if this user is a bot */ isBot(): boolean; /** User's or bot's first name */ get firstName(): string; /** User's or bot's last name */ get lastName(): string | undefined; /** User's or bot's username */ get username(): string | undefined; /** * [IETF language tag](https://en.wikipedia.org/wiki/IETF_language_tag) * of the user's language */ get languageCode(): string | undefined; /** `true`, if this user is a Telegram Premium user */ isPremium(): true | undefined; /** `true`, if this user added the bot to the attachment menu */ get addedToAttachmentMenu(): true | undefined; /** * `true`, if the bot can be invited to groups. * * Returned only in `getMe`. */ canJoinGroups(): boolean | undefined; /** * `true`, if privacy mode is disabled for the bot. * * Returned only in `getMe`. */ canReadAllGroupMessages(): boolean | undefined; /** * `true`, if the bot supports guest queries from chats it is not a member of. * * Returned only in `getMe`. */ supportsGuestQueries(): boolean | undefined; /** * `true`, if the bot supports inline queries. * * Returned only in `getMe`. */ supportsInlineQueries(): boolean | undefined; /** * `true`, if the bot can be connected to a Telegram Business account to receive its messages. * * Returned only in `getMe`. */ canConnectToBusiness(): boolean | undefined; /** * `true`, if the bot allows users to create and delete topics in private chats. * * Returned only in `getMe`. */ allowsUsersToCreateTopics(): boolean | undefined; /** * `true`, if other bots can be created to be controlled by the bot. * * Returned only in `getMe`. */ canManageBots(): boolean | undefined; } /** * This object represents one special entity in a text message. * For example, hashtags, usernames, URLs, etc. */ declare class MessageEntity { payload: TelegramObjects.TelegramMessageEntity; constructor(payload: TelegramObjects.TelegramMessageEntity); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the entity. * * Can be `mention` (`@username`), `hashtag` (`#hashtag`), `cashtag` * (`$USD`), `bot_command` (`/start@jobs_bot`), `url` * (`https://telegram.org`), `email` (`do-not-reply@telegram.org`), * `phone_number` (`+1-212-555-0123`), `bold` (**bold text**), `italic` * (_italic text_), `underline` (underlined text), `strikethrough` * (~~strikethrough text~~), “spoiler” (spoiler message), `code` (`monowidth string`), * `pre` (`monowidth block`), `text_link` (for clickable text URLs), `text_mention` * (for users without usernames) */ get type(): TelegramObjects.TelegramMessageEntityType; /** Offset in UTF-16 code units to the start of the entity */ get offset(): number; /** Length of the entity in UTF-16 code units */ get length(): number; /** * For `text_link` only, url that will be opened after user taps on the text */ get url(): string | undefined; /** For `text_mention` only, the mentioned user */ get user(): User | undefined; /** For `pre` only, the programming language of the entity text */ get language(): string | undefined; /** * For `custom_emoji` only, unique identifier of the custom emoji. * * Use `getCustomEmojiStickers` to get full information about the sticker */ get customEmojiId(): string | undefined; /** For `date_time` only, the Unix time associated with the entity */ get unixTime(): number | undefined; /** For `date_time` only, the string that defines the formatting of the date and time */ get dateTimeFormat(): string | undefined; } /** This object represents a file ready to be downloaded. The file can be downloaded via the link `https://api.telegram.org/file/bot<token>/<file_path>`. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling `getFile`. */ declare class File { payload: TelegramObjects.TelegramFile; constructor(payload: TelegramObjects.TelegramFile); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Identifier for this file, which can be used to download or reuse the file */ get fileId(): string; /** * Unique identifier for this file, which is supposed to be the same over * time and for different bots. Can't be used to download or reuse the file. */ get fileUniqueId(): string; /** File size, if known */ get fileSize(): number | undefined; /** * File path. * Use `https://api.telegram.org/file/bot<token>/<file_path>` to get the * file. */ get filePath(): string | undefined; } /** * This object describes the position on faces where a mask should be placed * by default. */ declare class MaskPosition { payload: TelegramObjects.TelegramMaskPosition; constructor(payload: TelegramObjects.TelegramMaskPosition); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * The part of the face relative to which the mask should be placed. * One of `forehead`, `eyes`, `mouth`, or `chin`. */ get point(): TelegramObjects.TelegramMaskPositionPoint; /** * Shift by X-axis measured in widths of the mask scaled to the face size, * from left to right. For example, choosing `-1.0` will place mask just to * the left of the default mask position. */ get xShift(): number; /** * Shift by Y-axis measured in heights of the mask scaled to the face size, * from top to bottom. For example, `1.0` will place the mask just below the * default mask position. */ get yShift(): number; /** Mask scaling coefficient. For example, `2.0` means double size. */ get scale(): number; } /** This object represents a sticker. */ declare class StickerAttachment extends FileAttachment<TelegramObjects.TelegramSticker> { attachmentType: AttachmentType; /** * Type of the sticker, currently one of `regular`, `mask`, `custom_emoji`. * * The type of the sticker is independent from its format, which is determined by the fields `is_animated` and `is_video`. */ get type(): TelegramObjects.TelegramStickerType; /** Sticker width */ get width(): number; /** Sticker height */ get height(): number; /** `true`, if the sticker is animated */ isAnimated(): boolean; /** `true`, if the sticker is a video sticker */ isVideo(): boolean; /** Sticker thumbnail in the .WEBP or .JPG format */ get thumbnail(): PhotoSize | undefined; /** Emoji associated with the sticker */ get emoji(): string | undefined; /** Name of the sticker set to which the sticker belongs */ get setName(): string | undefined; /** Is this sticker a premium one? */ isPremium(): this is Require<this, "premiumAnimation">; /** Premium animation for the sticker, if the sticker is premium */ get premiumAnimation(): File | undefined; /** For mask stickers, the position where the mask should be placed */ get maskPosition(): MaskPosition | undefined; /** For custom emoji stickers, unique identifier of the custom emoji */ get customEmojiId(): string | undefined; /** `true`, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places */ get needs_repainting(): true | undefined; /** File size */ get fileSize(): number | undefined; } /** * This object represents a video file of a specific quality. * * [Documentation](https://core.telegram.org/bots/api/#videoquality) */ declare class VideoQuality { payload: TelegramObjects.TelegramVideoQuality; constructor(payload: TelegramObjects.TelegramVideoQuality); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Identifier for this file, which can be used to download or reuse the file */ get fileId(): string; /** * Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file. */ get fileUniqueId(): string; /** * Video width */ get width(): number; /** * Video height */ get height(): number; /** * Codec that was used to encode the video, for example, "h264", "h265", or "av01" */ get codec(): TelegramObjects.TelegramVideoQualityCodec; /** * *Optional*. File size in bytes */ get fileSize(): number | undefined; } /** This object represents a video file. */ declare class VideoAttachment extends FileAttachment<TelegramObjects.TelegramVideo> { attachmentType: AttachmentType; /** Video width as defined by sender */ get width(): number; /** Video height as defined by sender */ get height(): number; /** Duration of the video in seconds as defined by sender */ get duration(): number; /** Video thumbnail */ get thumbnail(): PhotoSize | undefined; /** Original filename as defined by sender */ get fileName(): string | undefined; /** Mime type of a file as defined by sender */ get mimeType(): string | undefined; /** File size */ get fileSize(): number | undefined; /** Video cover */ get cover(): PhotoSize[] | undefined; /** Start timestamp */ get startTimestamp(): number | undefined; /** *Optional*. List of available qualities of the video */ get qualities(): VideoQuality[] | undefined; } /** This object represents a venue. */ declare class Venue { payload: TelegramObjects.TelegramVenue; constructor(payload: TelegramObjects.TelegramVenue); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Venue location */ get location(): Location; /** Name of the venue */ get title(): string; /** Address of the venue */ get address(): string; /** Foursquare identifier of the venue */ get foursquareId(): string | undefined; /** Foursquare type of the venue */ get foursquareType(): string | undefined; /** Google Places identifier of the venue */ get googlePlaceId(): string | undefined; /** * Google Places type of the venue. * (See [supported types](https://developers.google.com/places/web-service/supported_types).) */ get googlePlaceType(): string | undefined; } /** * Describes media attached to a poll, poll option, or quiz explanation. * * [Documentation](https://core.telegram.org/bots/api/#pollmedia) */ declare class PollMedia { payload: TelegramObjects.TelegramPollMedia; constructor(payload: TelegramObjects.TelegramPollMedia); get [Symbol.toStringTag](): string; /** Media is an animation, information about the animation */ get animation(): AnimationAttachment | undefined; /** Media is an audio file, information about the file */ get audio(): AudioAttachment | undefined; /** Media is a general file, information about the file */ get document(): DocumentAttachment | undefined; /** Media is a live photo, information about the live photo */ get livePhoto(): LivePhotoAttachment | undefined; /** Media is a shared location, information about the location */ get location(): Location | undefined; /** Media is a photo, available sizes of the photo */ get photo(): PhotoSize[] | undefined; /** Media is a sticker, information about the sticker */ get sticker(): StickerAttachment | undefined; /** Media is a venue, information about the venue */ get venue(): Venue | undefined; /** Media is a video, information about the video */ get video(): VideoAttachment | undefined; } /** * This object represents a chat. * * [Documentation](https://core.telegram.org/bots/api/#chat) */ declare class Chat { payload: TelegramObjects.TelegramChat; constructor(payload: TelegramObjects.TelegramChat); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Unique identifier for this chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for storing this identifier. */ get id(): number; /** * Type of the chat, can be either “private”, “group”, “supergroup” or “channel” */ get type(): TelegramObjects.TelegramChatType; /** * *Optional*. Title, for supergroups, channels and group chats */ get title(): string | undefined; /** * *Optional*. Username, for private chats, supergroups and channels if available */ get username(): string | undefined; /** * *Optional*. First name of the other party in a private chat */ get firstName(): string | undefined; /** * *Optional*. Last name of the other party in a private chat */ get lastName(): string | undefined; /** * *Optional*. *True*, if the supergroup chat is a forum (has [topics](https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups) enabled) */ get isForum(): true | undefined; /** * *Optional*. *True*, if the chat is the direct messages chat of a channel */ get isDirectMessages(): true | undefined; } /** * This object contains information about one answer option in a poll. * * [Documentation](https://core.telegram.org/bots/api/#polloption) */ declare class PollOption { payload: TelegramObjects.TelegramPollOption; constructor(payload: TelegramObjects.TelegramPollOption); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Unique identifier of the option, persistent on option addition and deletion */ get persistentId(): string; /** * Option text, 1-100 characters */ get text(): string; /** * *Optional*. Special entities that appear in the option *text*. Currently, only custom emoji entities are allowed in poll option texts */ get textEntities(): MessageEntity[] | undefined; /** *Optional*. Media added to the poll option */ get media(): PollMedia | undefined; /** * Number of users who voted for this option; may be 0 if unknown */ get voterCount(): number; /** * *Optional*. User who added the option; omitted if the option wasn't added by a user after poll creation */ get addedByUser(): User | undefined; /** * *Optional*. Chat that added the option; omitted if the option wasn't added by a chat after poll creation */ get addedByChat(): Chat | undefined; /** * *Optional*. Point in time (Unix timestamp) when the option was added; omitted if the option existed in the original poll */ get additionDate(): number | undefined; } /** This object contains information about a poll. */ declare class Poll { payload: TelegramObjects.TelegramPoll; constructor(payload: TelegramObjects.TelegramPoll); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Unique poll identifier */ get id(): string; /** Poll question, `1-300` characters */ get question(): string; /** * *Optional*. Special entities that appear in the *question*. Currently, only custom emoji entities are allowed in poll questions */ get questionEntities(): MessageEntity[] | undefined; /** List of poll options */ get options(): PollOption[]; /** Total number of users that voted in the poll */ get totalVoterCount(): number; /** `true`, if the poll is closed */ isClosed(): boolean; /** `true`, if the poll is anonymous */ isAnonymous(): boolean; /** Poll type, currently can be `regular` or `quiz` */ get type(): TelegramObjects.TelegramPollType; /** `true`, if the poll allows multiple answers */ get allowsMultipleAnswers(): boolean; /** `true`, if the poll allows to change the chosen answer options */ get allowsRevoting(): boolean; /** `true` if voting is limited to users who have been members of the chat where the poll was originally sent for more than 24 hours */ get membersOnly(): boolean; /** *Optional*. A list of two-letter ISO 3166-1 alpha-2 country codes indicating the countries from which users can vote in the poll. If omitted, then users from any country can participate in the poll. */ get countryCodes(): string[] | undefined; /** * Array of 0-based identifiers of the correct answer options. Available only for polls * in quiz mode which are closed or were sent (not forwarded) by the bot or to the * private chat with the bot. */ get correctOptionIds(): number[] | undefined; /** * Text that is shown when a user chooses an incorrect answer or taps on the * lamp icon in a quiz-style poll, 0-200 characters */ get explanation(): string | undefined; /** * Special entities like usernames, URLs, bot commands, etc. that appear in * the explanation */ get explanationEntities(): MessageEntity[] | undefined; /** *Optional*. Media added to the quiz explanation */ get explanationMedia(): PollMedia | undefined; /** Amount of time in seconds the poll will be active after creation */ get openPeriod(): number | undefined; /** * Point in time (Unix timestamp) when the poll will be automatically closed */ get closeDate(): number | undefined; /** * *Optional*. Description of the poll; for polls inside the Message object only */ get description(): string | undefined; /** * *Optional*. Special entities like usernames, URLs, bot commands, etc. that appear in * the description */ get descriptionEntities(): MessageEntity[] | undefined; /** *Optional*. Media added to the poll description; for polls inside the Message object only */ get media(): PollMedia | undefined; } /** This object contains information about a poll. */ declare class PollAttachment extends Poll { attachmentType: AttachmentType; } interface PollAttachment extends Attachment { } /** * This object represents a story. * * [Documentation](https://core.telegram.org/bots/api/#story) */ declare class Story { payload: TelegramObjects.TelegramStory; constructor(payload: TelegramObjects.TelegramStory); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** Unique identifier for the story in the chat */ get id(): number; /** Chat that posted the story */ get chat(): Chat; } /** * This object represents a story. * * [Documentation](https://core.telegram.org/bots/api/#story) */ declare class StoryAttachment extends Story { attachmentType: AttachmentType; } interface StoryAttachment extends Attachment { } /** * This object represents a venue. * * [Documentation](https://core.telegram.org/bots/api/#venue) */ declare class VenueAttachment extends Venue { attachmentType: AttachmentType; } interface VenueAttachment extends Attachment { } /** This object represents a video message. */ declare class VideoNoteAttachment extends FileAttachment<TelegramObjects.TelegramVideoNote> { attachmentType: AttachmentType; /** * Video width and height (diameter of the video message) as defined by * sender */ get length(): number; /** Duration of the video in seconds as defined by sender */ get duration(): number; /** Video thumbnail */ get thumbnail(): PhotoSize | undefined; /** File size */ get fileSize(): number | undefined; } /** This object represents a voice note. */ declare class VoiceAttachment extends FileAttachment<TelegramObjects.TelegramVoice> { attachmentType: AttachmentType; /** Duration of the audio in seconds as defined by sender */ get duration(): number; /** MIME type of the file as defined by sender */ get mimeType(): string | undefined; /** File size */ get fileSize(): number | undefined; } /** * The background is a freeform gradient that rotates after every message in the chat. * * [Documentation](https://core.telegram.org/bots/api/#backgroundfillfreeformgradient) */ declare class BackgroundFillFreeformGradient { payload: TelegramObjects.TelegramBackgroundFillFreeformGradient; constructor(payload: TelegramObjects.TelegramBackgroundFillFreeformGradient); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background fill, always “freeform\_gradient” */ get type(): "freeform_gradient"; /** * A list of the 3 or 4 base colors that are used to generate the freeform gradient in the RGB24 format */ get colors(): number[]; } /** * The background is a gradient fill. * * [Documentation](https://core.telegram.org/bots/api/#backgroundfillgradient) */ declare class BackgroundFillGradient { payload: TelegramObjects.TelegramBackgroundFillGradient; constructor(payload: TelegramObjects.TelegramBackgroundFillGradient); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background fill, always “gradient” */ get type(): "gradient"; /** * Top color of the gradient in the RGB24 format */ get topColor(): number; /** * Bottom color of the gradient in the RGB24 format */ get bottomColor(): number; /** * Clockwise rotation angle of the background fill in degrees; 0-359 */ get rotationAngle(): number; } /** * The background is filled using the selected color. * * [Documentation](https://core.telegram.org/bots/api/#backgroundfillsolid) */ declare class BackgroundFillSolid { payload: TelegramObjects.TelegramBackgroundFillSolid; constructor(payload: TelegramObjects.TelegramBackgroundFillSolid); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background fill, always “solid” */ get type(): "solid"; /** * The color of the background fill in the RGB24 format */ get color(): number; } /** * This object describes the way a background is filled based on the selected colors. Currently, it can be one of * * * [BackgroundFillSolid](https://core.telegram.org/bots/api/#backgroundfillsolid) * * [BackgroundFillGradient](https://core.telegram.org/bots/api/#backgroundfillgradient) * * [BackgroundFillFreeformGradient](https://core.telegram.org/bots/api/#backgroundfillfreeformgradient) * * [Documentation](https://core.telegram.org/bots/api/#backgroundfill) */ declare const backgroundFillMap: { solid: typeof BackgroundFillSolid; gradient: typeof BackgroundFillGradient; freeform_gradient: typeof BackgroundFillFreeformGradient; }; /** * The background is taken directly from a built-in chat theme. * * [Documentation](https://core.telegram.org/bots/api/#backgroundtypechattheme) */ declare class BackgroundTypeChatTheme { payload: TelegramObjects.TelegramBackgroundTypeChatTheme; constructor(payload: TelegramObjects.TelegramBackgroundTypeChatTheme); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background, always “chat\_theme” */ get type(): "chat_theme"; /** * Name of the chat theme, which is usually an emoji */ get themeName(): string; } /** * The background is automatically filled based on the selected colors. * * [Documentation](https://core.telegram.org/bots/api/#backgroundtypefill) */ declare class BackgroundTypeFill { payload: TelegramObjects.TelegramBackgroundTypeFill; constructor(payload: TelegramObjects.TelegramBackgroundTypeFill); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background, always “fill” */ get type(): "fill"; /** * The background fill */ get fill(): (typeof backgroundFillMap)[keyof typeof backgroundFillMap]; /** * Dimming of the background in dark themes, as a percentage; 0-100 */ get darkThemeDimming(): number; } /** * The background is a PNG or TGV (gzipped subset of SVG with MIME type “application/x-tgwallpattern”) pattern to be combined with the background fill chosen by the user. * * [Documentation](https://core.telegram.org/bots/api/#backgroundtypepattern) */ declare class BackgroundTypePattern { payload: TelegramObjects.TelegramBackgroundTypePattern; constructor(payload: TelegramObjects.TelegramBackgroundTypePattern); /** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */ get [Symbol.toStringTag](): string; /** * Type of the background, always “pattern” */ get type(): "pattern"; /** * Document with the pattern */ get document(): DocumentAttachment; /** * The background fill that is combined with the pattern */ get fill(): (typeof backgroundFillMap)[keyof typeof backgroundFillMap]; /** * Intensity of the pattern when it is shown above the filled background; 0-100 */ get intensity(): number