@gramio/contexts
Version:
Contexts for GramIO framework
1,236 lines (1,192 loc) • 300 kB
TypeScript
import * as _gramio_types from '@gramio/types';
import { TelegramObjects, TelegramUpdate, APIMethods, APIMethodParams, TelegramResponseParameters, APIMethodReturn, TelegramInputMedia, 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;
}
/** 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;
}
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>> = 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>;
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>;
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: 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>;
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>;
unique_gift: UniqueGiftContext<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" | "unique_gift" | "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";
/** 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;
location: LocationAttachment;
photo: PhotoAttachment;
poll: PollAttachment;
sticker: StickerAttachment;
story: StoryAttachment;
venue: VenueAttachment;
video_note: VideoNoteAttachment;
video: VideoAttachment;
voice: VoiceAttachment;
}
/** 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"
}
/** 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 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 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;
}
/**
* 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;
}
/**
* 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;
/**
* 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;
/**
* Number of users that voted for this option
*/
get voterCount(): number;
}
/** 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;
/**
* 0-based identifier of the correct answer option. Available only for polls
* in the quiz mode, which are closed, or was sent (not forwarded) by the bot
* or to the private chat with the bot.
*/
get correctOptionId(): 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;
/** 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;
}
/** This object contains information about a poll. */
declare class PollAttachment extends Poll {
attachmentType: AttachmentType;
}
interface PollAttachment extends Attachment {
}
/** 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 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(): boolean | undefined;
}
/**
* 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. */
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;
}
/**
* 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 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;
}
/** 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;
/**
* *Optional*. *True*, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only
*/
get isInverted(): boolean | undefined;
/**
* *Optional*. *True*, if the background moves slightly when the device is tilted
*/
get isMoving(): boolean | undefined;
}
/**
* The background is a wallpaper in the JPEG format.
*
* [Documentation](https://core.telegram.org/bots/api/#backgroundtypewallpaper)
*/
declare class BackgroundTypeWallpaper {
payload: TelegramObjects.TelegramBackgroundTypeWallpaper;
constructor(payload: TelegramObjects.TelegramBackgroundTypeWallpaper);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/**
* Type of the background, always “wallpaper”
*/
get type(): "wallpaper";
/**
* Document with the wallpaper
*/
get document(): DocumentAttachment;
/**
* Dimming of the background in dark themes, as a percentage; 0-100
*/
get darkThemeDimming(): number;
/**
* *Optional*. *True*, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with radius 12
*/
get isBlurred(): boolean | undefined;
/**
* *Optional*. *True*, if the background moves slightly when the device is tilted
*/
get isMoving(): boolean | undefined;
}
/**
* This object describes the type of a background. Currently, it can be one of
*
* * [BackgroundTypeFill](https://core.telegram.org/bots/api/#backgroundtypefill)
* * [BackgroundTypeWallpaper](https://core.telegram.org/bots/api/#backgroundtypewallpaper)
* * [BackgroundTypePattern](https://core.telegram.org/bots/api/#backgroundtypepattern)
* * [BackgroundTypeChatTheme](https://core.telegram.org/bots/api/#backgroundtypechattheme)
*
* [Documentation](https://core.telegram.org/bots/api/#backgroundtype)
*/
declare const backgroundTypeMap: {
fill: typeof BackgroundTypeFill;
wallpaper: typeof BackgroundTypeWallpaper;
pattern: typeof BackgroundTypePattern;
chat_theme: typeof BackgroundTypeChatTheme;
};
/**
* Describes the birthdate of a user.
*
* [Documentation](https://core.telegram.org/bots/api/#birthdate)
*/
declare class Birthdate {
payload: TelegramObjects.TelegramBirthdate;
constructor(payload: TelegramObjects.TelegramBirthdate);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/**
* Day of the user's birth; 1-31
*/
get day(): number;
/**
* Month of the user's birth; 1-12
*/
get month(): number;
/**
* *Optional*. Year of the user's birth
*/
get year(): number | undefined;
}
/** This object represents a bot command */
declare class BotCommand {
payload: TelegramObjects.TelegramBotCommand;
constructor(payload: TelegramObjects.TelegramBotCommand);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/** Text of the command; 1-32 characters. Can contain only lowercase English letters, digits and underscores. */
get command(): string;
/** Description of the command; 1-256 characters */
get description(): string;
}
/** This object represents the bot's description. */
declare class BotDescription {
payload: TelegramObjects.TelegramBotDescription;
constructor(payload: TelegramObjects.TelegramBotDescription);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/** The bot's description */
get description(): string;
}
/** This object represents the bot's short description. */
declare class BotShortDescription {
payload: TelegramObjects.TelegramBotShortDescription;
constructor(payload: TelegramObjects.TelegramBotShortDescription);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/** The bot's short description */
get description(): string;
}
/**
* Represents the rights of a business bot.
*
* [Documentation](https://core.telegram.org/bots/api/#businessbotrights)
*/
declare class BusinessBotRights {
payload: TelegramObjects.TelegramBusinessBotRights;
constructor(payload: TelegramObjects.TelegramBusinessBotRights);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/**
* True, if the bot can send and edit messages in the private chats that had incoming messages in the last 24 hours
*/
get canReply(): boolean;
/**
* True, if the bot can read messages in the private chats that had incoming messages in the last 24 hours
*/
get canReadMessages(): boolean;
/**
* True, if the bot can delete messages sent by the bot
* @deprecated Use `canDeleteSentMessages` instead
*/
get canDeleteOutgoingMessages(): boolean;
/**
* True, if the bot can delete messages sent by the bot
*/
get canDeleteSentMessages(): boolean;
/**
* True, if the bot can delete all private messages in managed chats
*/
get canDeleteAllMessages(): boolean;
/**
* True, if the bot can edit the first and last name of the business account
*/
get canEditName(): boolean;
/**
* True, if the bot can edit the bio of the business account
*/
get canEditBio(): boolean;
/**
* True, if the bot can edit the profile photo of the business account
*/
get canEditProfilePhoto(): boolean;
/**
* True, if the bot can edit the username of the business account
*/
get canEditUsername(): boolean;
/**
* True, if the bot can change the privacy settings pertaining to gifts for the business account
*/
get canChangeGiftSettings(): boolean;
/**
* True, if the bot can view gifts and the amount of Telegram Stars owned by the business account
*/
get canViewGiftsAndStars(): boolean;
/**
* True, if the bot can convert regular gifts owned by the business account to Telegram Stars
*/
get canConvertGiftsToStars(): boolean;
/**
* True, if the bot can transfer and upgrade gifts owned by the business account
*/
get canTransferAndUpgradeGifts(): boolean;
/**
* True, if the bot can transfer Telegram Stars received by the business account to its own account, or use them to upgrade and transfer gifts
*/
get canTransferStars(): boolean;
/**
* True, if the bot can post, edit and delete stories on behalf of the business account
*/
get canManageStories(): boolean;
}
/**
* Describes the connection of the bot with a business account.
*
* [Documentation](https://core.telegram.org/bots/api/#businessconnection)
*/
declare class BusinessConnection {
payload: TelegramObjects.TelegramBusinessConnection;
constructor(payload: TelegramObjects.TelegramBusinessConnection);
/** [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag) */
get [Symbol.toStringTag](): string;
/**
* Unique identifier of the business connection
*/
get id(): string;
/**
* Business account user that created the business connection
*/
get user(): User;
/**
* Identifier of a private chat with the user who created the business connection. 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 64-bit integer or double-precision float type are safe for storing this identifier.
*/
get userChatId(): number;
/**
* Date the connection was established in Unix time
*/
get date(): number;
/**
* True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours
*/
get canReply(): boolean;
/**
* True, if the connection is active
*/
get isEn