Skip to content

Instantly share code, notes, and snippets.

@untodesu
Last active February 2, 2023 14:22
Show Gist options
  • Save untodesu/fccb6c78a5dd3c536c29b5ba0b648f7b to your computer and use it in GitHub Desktop.
Save untodesu/fccb6c78a5dd3c536c29b5ba0b648f7b to your computer and use it in GitHub Desktop.
/* SPDX-License-Identifier: BSD-2-Clause */
/* Copyright (c), 2023, Kirill GPRB */
/**
* Implements a Telegram Bot.
* @see https://core.telegram.org/bots/api
*/
export class BotClient {
token: string;
secret?: string;
/**
* Creates a new Telegram Bot.
* @param token Bot token.
*/
constructor(token: string, secret?: string) {
this.token = token;
this.secret = secret;
};
async apiMethod(method: string, params: any): Promise<any> {
let url = [];
url.push("https://api.telegram.org/bot");
url.push(this.token, "/");
url.push(method, "?");
for(let key in params) {
if(params.hasOwnProperty(key)) {
url.push(key, "=", params[key], "&");
}
}
return await (await fetch(url.join(""))).json();
};
async getMe(): Promise<User> {
return await this.apiMethod("getMe", {});
};
async sendMessage(chat_id: number, text: string, params?: any): Promise<Message> {
params = params || {};
params.chat_id = chat_id;
params.text = text;
return await this.apiMethod("sendMessage", params);
}
};
/**
* Represents a Telegram user or bot.
* @see https://core.telegram.org/bots/api#user
*/
export interface User {
id: number;
is_bot: true;
first_name: string;
last_name?: string;
username?: string;
language_code?: string;
is_premium?: true;
added_to_attachment_menu?: true;
can_join_groups?: true;
can_read_all_group_messages?: true;
supports_inline_queries?: true;
};
/**
* Represents a chat.
* @see https://core.telegram.org/bots/api#chat
*/
export interface Chat {
id: number;
type: string;
title?: string;
username?: string;
first_name?: string;
last_name?: string;
is_forum?: true;
photo?: ChatPhoto;
active_usernames?: string[];
emoji_status_custom_emoji_id?: string;
bio?: string;
has_private_forwards?: true;
has_restricted_voice_and_video_messages?: true;
join_to_send_messages?: true;
join_by_request?: true;
description?: string;
invite_link?: string;
pinned_message?: Message;
permissions?: ChatPermissions;
slow_mode_delay?: number;
message_auto_delete_time?: number;
has_aggresive_spam_filter?: true;
has_hidden_members?: true;
has_protected_content?: true;
sticker_set_name?: string;
can_set_sticker_set?: true;
linked_chat_id?: number;
location?: ChatLocation;
};
/**
* Represents a message.
* @see https://core.telegram.org/bots/api#message
*/
export interface Message {
message_id: number;
message_thread_id?: number;
from?: User;
sender_chat?: Chat;
date: number;
chat: Chat;
forward_from?: User;
forward_from_chat?: Chat;
forward_from_message_id?: number;
forward_signature?: string;
forward_sender_name?: string;
forward_date?: number;
is_topic_message?: true;
is_automatic_forward?: true;
reply_to_message?: Message;
via_bot?: User;
edit_date?: number;
has_protected_content?: true;
media_group_id?: string;
author_signature?: string;
text?: string;
entities?: MessageEntity[];
animation?: Animation;
audio?: Audio;
document?: Document;
photo?: PhotoSize[];
sticker?: Sticker;
video?: Video;
video_note?: VideoNote;
voice?: VoiceNote;
caption?: string;
caption_entities?: MessageEntity[];
has_media_spoiler?: true;
contact?: Contact;
dice?: Dice;
game?: Game;
poll?: Poll;
venue?: Venue;
location?: Location;
new_chat_members?: User[];
left_chat_member?: User;
new_chat_title?: string;
new_chat_photo?: PhotoSize[];
delete_chat_photo?: true;
group_chat_created?: true;
supergroup_chat_created?: true;
channel_chat_created?: true;
message_auto_delete_timer_changed?: MessageAutoDeleteTimerChanged;
migrate_to_chat_id?: number;
migrate_from_chat_id?: number;
pinned_message?: Message;
invoice?: Invoice;
successful_payment?: SuccessfulPayment;
connected_website?: string;
write_access_allowed?: WriteAccessAllowed;
passport_data?: PassportData;
proximity_alert_triggered?: ProximityAlertTriggered;
forum_topic_created?: ForumTopicCreated;
forum_topic_edited?: ForumTopicEdited;
forum_topic_closed?: ForumTopicClosed;
forum_topic_reopened?: ForumTopicReopened;
general_forum_topic_hidden?: GeneralForumTopicHidden;
general_forum_topic_unhidden?: GeneralForumTopicUnhidden;
video_chat_scheduled?: VideoChatScheduled;
video_chat_started?: VideoChatStarted;
video_chat_ended?: VideoChatEnded;
video_chat_participants_invited?: VideoChatParticipantsInvited;
reply_markup?: InlineKeyboardMarkup;
};
/**
* Represents a unique message identifier.
* @see https://core.telegram.org/bots/api#messageid
*/
export interface MessageId {
message_id: number;
};
/**
* Represents one special entity in a text message.
* For example, hashtags, usernames, URLs, etc.
* @see https://core.telegram.org/bots/api#messageentity
*/
export interface MessageEntity {
type: string;
offset: number;
length: number;
url?: string;
user?: User;
language?: string;
custom_emoji_id?: string;
};
/**
* Contains basic information about an invoice.
* @see https://core.telegram.org/bots/api#invoice
*/
export interface Invoice {
title: string;
description: string;
start_parameter: string;
currency: string;
total_amount: number;
};
/**
* Contains basic information about a successful payment.
* @see https://core.telegram.org/bots/api#successfulpayment
*/
export interface SuccessfulPayment {
currency: string;
total_amount: number;
invoice_payload: string;
shipping_option_id?: string;
order_info?: OrderInfo;
telegram_payment_charge_id: string;
provider_payment_charge_id: string;
};
/**
* Represents information about an order.
* @see https://core.telegram.org/bots/api#orderinfo
*/
export interface OrderInfo {
name?: string;
phone_number?: string;
email?: string;
shipping_address?: ShippingAddress;
};
/**
* Represents a shipping address.
* @see https://core.telegram.org/bots/api#shippingaddress
*/
export interface ShippingAddress {
country_code: string;
state: string;
city: string;
street_line1: string;
street_line2: string;
post_code: string;
};
/**
* Describes Telegram Passport data shared with the bot by the user.
* @see https://core.telegram.org/bots/api#passportdata
*/
export interface PassportData {
data: EncryptedPassportElement[];
credentials: EncryptedCredentials;
};
/**
* Describes documents or other Telegram Passport
* elements shared with the bot by the user.
* @see https://core.telegram.org/bots/api#encryptedpassportelement
*/
export interface EncryptedPassportElement {
type: string;
data?: string;
phone_number?: string;
email?: string;
files?: PassportFile[];
front_side?: PassportFile;
reverse_side?: PassportFile;
selfie?: PassportFile;
translation?: PassportFile[];
hash: string;
};
/**
* Represents a file uploaded to Telegram Passport. Currently all
* Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
* @see https://core.telegram.org/bots/api#passportfile
*/
export interface PassportFile {
file_id: string;
file_unique_id: string;
file_size: number;
file_date: number;
};
/**
* Describes data required for decrypting and
* authenticating @interface EncryptedPassportElement .
* @see https://core.telegram.org/bots/api#encryptedcredentials
*/
export interface EncryptedCredentials {
data: string;
hash: string;
secret: string;
};
/**
* Describes the position on faces where a mask should be placed by default.
* @see https://core.telegram.org/bots/api#maskposition
*/
export interface MaskPosition {
point: string;
x_shift: number;
y_shift: number;
scale: number;
};
/**
* Represents a sticker.
* @see https://core.telegram.org/bots/api#sticker
*/
export interface Sticker {
file_id: string;
file_unique_id: string;
type: string;
width: number;
height: number;
is_animated: boolean;
is_video: boolean;
thumb?: PhotoSize;
emoji?: string;
set_name?: string;
premium_animation?: File;
mask_position?: MaskPosition;
custom_emoji_id?: string;
file_size?: number;
};
/**
* Represents one size of a photo or a file / sticker thumbnail.
* @see https://core.telegram.org/bots/api#photosize
*/
export interface PhotoSize {
file_id: string;
file_unique_id: string;
width: number;
height: number;
file_size?: number;
};
/**
* Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound).
* @see https://core.telegram.org/bots/api#animation
*/
export interface Animation {
file_id: string;
file_unique_id: string;
width: number;
height: number;
duration: number;
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
file_size?: number;
};
/**
* Represents an audio file to be treated as music by the Telegram clients.
* @see https://core.telegram.org/bots/api#audio
*/
export interface Audio {
file_id: string;
file_unique_id: string;
duration: number;
performer?: string;
title?: string;
file_name?: string;
mime_type?: string;
file_size?: number;
thumb?: PhotoSize;
};
/**
* Represents a general file (as opposed
* to photos, voice messages and audio files).
* @see https://core.telegram.org/bots/api#document
*/
export interface Document {
file_id: string;
file_unique_id: string;
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
file_size?: number;
};
/**
* Represents a video file.
* @see https://core.telegram.org/bots/api#video
*/
export interface Video {
file_id: string;
file_unique_id: string;
width: number;
height: number;
duration: number;
thumb?: PhotoSize;
file_name?: string;
mime_type?: string;
file_size?: number;
};
/**
* Represents a video message (available in Telegram apps as of v.4.0).
* @see https://core.telegram.org/bots/api#videonote
*/
export interface VideoNote {
file_id: string;
file_unique_id: string;
length: number;
duration: number;
thumb?: PhotoSize;
file_size?: number;
};
/**
* Represents a voice note.
* @see https://core.telegram.org/bots/api#voice
*/
export interface VoiceNote {
file_id: string;
file_unique_id: string;
duration: number;
mime_type?: string;
file_size?: number;
};
/**
* Represents a phone contact.
* @see https://core.telegram.org/bots/api#contact
*/
export interface Contact {
phone_number: string;
first_name: string;
last_name?: string;
user_id?: number;
vcard?: string;
};
/**
* Represents an animated emoji that displays a random value.
* @see https://core.telegram.org/bots/api#dice
*/
export interface Dice {
emoji: string;
value: number;
};
/**
* epresents a game. Use BotFather to create and edit
* games, their short names will act as unique identifiers.
* @see https://core.telegram.org/bots/api#game
*/
export interface Game {
title: string;
description: string;
photo: PhotoSize[];
text?: string;
text_entities?: MessageEntity[];
animation?: Animation;
};
/**
* Contains information about one answer option in a poll.
* @see https://core.telegram.org/bots/api#polloption
*/
export interface PollOption {
text: string;
voter_count: number;
};
/**
* Represents an answer of a user in a non-anonymous poll.
* @see https://core.telegram.org/bots/api#pollanswer
*/
export interface PollAnswer {
poll_id: string;
user: User;
option_ids: number[];
};
/**
* Contains information about a poll.
* @see https://core.telegram.org/bots/api#poll
*/
export interface Poll {
id: string;
question: string;
options: PollOption[];
total_voter_count: number;
is_closed: boolean;
is_anonymous: boolean;
type: string;
allows_multiple_answers: boolean;
correct_option_id?: number;
explanation?: string;
explanation_entities?: MessageEntity[];
open_period?: number;
close_date?: number;
};
/**
* Represents a point on the map.
* @see https://core.telegram.org/bots/api#location
*/
export interface Location {
longitude: number;
latitude: number;
horizontal_accuracy?: number;
live_period?: number;
heading?: number;
proximity_alert_radius?: number;
};
/**
* Represents a venue.
* @see https://core.telegram.org/bots/api#venue
*/
export interface Venue {
location: Location;
title: string;
address: string;
foursquare_id?: string;
foursquare_type?: string;
google_place_id?: string;
google_place_type?: string;
};
/**
* Represents the content of a service message, sent whenever a user in
* the chat triggers a proximity alert set by another user.
* @see https://core.telegram.org/bots/api#proximityalerttriggered
*/
export interface ProximityAlertTriggered {
traveler: User;
watcher: User;
distance: number;
};
/**
* Represents a service message about a change in auto-delete timer settings.
* @see https://core.telegram.org/bots/api#messageautodeletetimerchanged
*/
export interface MessageAutoDeleteTimerChanged {
message_auto_delete_time: number;
};
/**
* Represents a service message about a new forum topic created in the chat.
* @see https://core.telegram.org/bots/api#forumtopiccreated
*/
export interface ForumTopicCreated {
name: string;
icon_color: number;
icon_custom_emoji_id?: string;
};
/**
* Represents a service message about a forum topic closed
* in the chat. Currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#forumtopicclosed
*/
export interface ForumTopicClosed {};
/**
* Represents a service message about an edited forum topic.
* @see https://core.telegram.org/bots/api#forumtopicedited
*/
export interface ForumTopicEdited {
name?: string;
icon_custom_emoji_id?: string;
};
/**
* Represents a service message about a forum topic reopened
* in the chat. Currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#forumtopicreopened
*/
export interface ForumTopicReopened {};
/**
* Represents a service message about General forum topic hidden
* in the chat. Currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#generalforumtopichidden
*/
export interface GeneralForumTopicHidden {};
/**
* Represents a service message about General forum topic
* unhidden in the chat. Currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#generalforumtopicunhidden
*/
export interface GeneralForumTopicUnhidden {};
/**
* Represents a service message about a user allowing a bot
* added to the attachment menu to write messages. Currently
* holds no information. Too bad!
* @see https://core.telegram.org/bots/api#writeaccessallowed
*/
export interface WriteAccessAllowed {};
/**
* Represents a service message about a video chat scheduled in the chat.
* @see https://core.telegram.org/bots/api#videochatscheduled
*/
export interface VideoChatScheduled {
start_date: number;
};
/**
* Represents a service message about a video chat started in
* the chat. Currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#videochatstarted
*/
export interface VideoChatStarted {};
/**
* Represents a service message about a video chat ended in the chat.
* @see https://core.telegram.org/bots/api#videochatended
*/
export interface VideoChatEnded {
duration: number;
};
/**
* Represents a service message about new members invited to a video chat.
* @see https://core.telegram.org/bots/api#videochatparticipantsinvited
*/
export interface VideoChatParticipantsInvited {
users: User[];
};
/**
* Represents a user's profile pictures.
* @see https://core.telegram.org/bots/api#userprofilephotos
*/
export interface UserProfilePhotos {
total_count: number;
photos: PhotoSize[][];
};
/**
* 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.
* @see https://core.telegram.org/bots/api#file
*/
export interface File {
file_id: string;
file_unique_id: string;
file_size?: number;
file_path?: string;
};
/**
* Represents a custom keyboard with reply options.
* @see https://core.telegram.org/bots/api#replykeyboardmarkup
*/
export interface ReplyKeyboardMarkup {
keyboard: KeyboardButton[][];
is_persistent?: boolean;
resize_keyboard?: boolean;
one_time_keyboard?: boolean;
input_field_placeholder?: string;
selective?: boolean;
};
/**
* Represents one button of the reply keyboard.
* @see https://core.telegram.org/bots/api#keyboardbutton
*/
export interface KeyboardButton {
text: string;
request_contact?: boolean;
request_location?: boolean;
request_poll?: KeyboardButtonPollType;
};
/**
* Represents type of a poll, which is
* allowed to be created and sent when the corresponding button is pressed.
* @see https://core.telegram.org/bots/api#keyboardbuttonpolltype
*/
export interface KeyboardButtonPollType {
type: "quiz" | "regular";
};
/**
* Upon receiving a message with this object,
* Telegram clients will remove the current custom
* keyboard and display the default letter-keyboard.
* @see https://core.telegram.org/bots/api#replykeyboardremove
*/
export interface ReplyKeyboardRemove {
remove_keyboard: true;
selective?: boolean;
};
/**
* Represents an inline keyboard that appears
* right next to the message it belongs to.
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
*/
export interface InlineKeyboardMarkup {
inline_keyboard: InlineKeyboardButton[][];
};
/**
* Represents one button of an inline keyboard.
* You MUST use EXACTLY ONE of the optional fields.
* @see https://core.telegram.org/bots/api#inlinekeyboardbutton
*/
export interface InlineKeyboardButton {
text: string;
url?: string;
callback_data?: string;
login_url?: LoginUrl;
switch_inline_query?: string;
switch_inline_query_current_chat?: string;
callback_game?: CallbackGame;
pay?: boolean;
};
/**
* Represents a parameter of the inline keyboard
* button used to automatically authorize a user.
* @see https://core.telegram.org/bots/api#loginurl
*/
export interface LoginUrl {
url: string;
forward_text?: string;
bot_username?: string;
request_write_access?: boolean;
};
/**
* A placeholder, currently holds no information. Too bad!
* @see https://core.telegram.org/bots/api#callbackgame
*/
export interface CallbackGame {};
/**
* Represents an incoming callback query from a
* callback button in an inline keyboard.
* @see https://core.telegram.org/bots/api#callbackquery
*/
export interface CallbackQuery {
id: string;
from: User;
message?: Message;
inline_message_id?: string;
chat_instance: string;
data?: string;
game_short_name?: string;
};
/**
* Upon receiving a message with this object, Telegram
* clients will display a reply interface to the user
* (act as if the user has selected the bot's message
* and tapped 'Reply').
* @see https://core.telegram.org/bots/api#forcereply
*/
export interface ForceReply {
force_reply: true;
input_field_placeholder?: string;
selective?: boolean;
};
/**
* Represents a chat photo.
* @see https://core.telegram.org/bots/api#chatphoto
*/
export interface ChatPhoto {
small_file_id: string;
small_file_unique_id: string;
big_file_id: string;
big_file_unique_id: string;
};
/**
* Represents an invite link for a chat.
* @see https://core.telegram.org/bots/api#chatinvitelink
*/
export interface ChatInviteLink {
invite_link: string;
creator: User;
creates_join_request: boolean;
is_primary: boolean;
is_revoked: boolean;
name?: string;
expire_date?: number;
member_limit?: number;
pending_members_count?: number;
};
/**
* Represents the rights of an administrator in a chat.
* @see https://core.telegram.org/bots/api#chatadministratorrights
*/
export interface ChatAdministratorRights {
is_anonymous: boolean;
can_manage_chat: boolean;
can_delete_messages: boolean;
can_manage_video_chats: boolean;
can_restrict_members: boolean;
can_promote_members: boolean;
can_change_info: boolean;
can_invite_users: boolean;
can_post_messages?: boolean;
can_edit_messages?: boolean;
can_pin_messages?: boolean;
can_manage_topics?: boolean;
};
/**
* Contains information about one member of a chat.
* @see https://core.telegram.org/bots/api#chatmember
*/
export type ChatMember =
| ChatMemberOwner
| ChatMemberAdministrator
| ChatMemberMember
| ChatMemberRestricted
| ChatMemberLeft
| ChatMemberBanned;
/**
* Represents a chat member that owns the chat and has all administrator privileges.
* @see https://core.telegram.org/bots/api#chatmemberowner
*/
export interface ChatMemberOwner {
status: "creator";
user: User;
is_anonymous: boolean;
custom_title?: string;
};
/**
* Represents a chat member that has some additional privileges.
* @see https://core.telegram.org/bots/api#chatmemberadministrator
*/
export interface ChatMemberAdministrator {
status: "administrator";
user: User;
can_be_edited: boolean;
is_anonymous: boolean;
can_manage_chat: boolean;
can_delete_messages: boolean;
can_manage_video_chats: boolean;
can_restrict_members: boolean;
can_promote_members: boolean;
can_change_info: boolean;
can_invite_users: boolean;
can_post_messages?: boolean;
can_edit_messages?: boolean;
can_pin_messages?: boolean;
can_manage_topics?: boolean;
custom_title?: string;
};
/**
* Represents a chat member that has no additional privileges or restrictions.
* @see https://core.telegram.org/bots/api#chatmemberowner
*/
export interface ChatMemberMember {
status: "member";
user: User;
};
/**
* Represents a chat member that is under certain
* restrictions in the chat. Supergroups only.
* @see https://core.telegram.org/bots/api#chatmemberrestricted
*/
export interface ChatMemberRestricted {
status: "restricted";
user: User;
is_member: boolean;
can_change_info?: boolean;
can_invite_users?: boolean;
can_pin_messages?: boolean;
can_manage_topics?: boolean;
can_send_messages?: boolean;
can_send_media_messages?: boolean;
can_send_polls?: boolean;
can_send_other_messages?: boolean;
can_add_web_page_previews?: boolean;
until_date?: number;
};
/**
* Represents a chat member that isn't currently a
* member of the chat, but may join it themselves.
* @see https://core.telegram.org/bots/api#chatmemberinvited
*/
export interface ChatMemberLeft {
status: "left";
user: User;
};
/**
* Represents a chat member that was banned in the chat
* and can't return to the chat or view chat messages.
* @see https://core.telegram.org/bots/api#chatmemberbanned
*/
export interface ChatMemberBanned {
status: "kicked";
user: User;
until_date: number;
};
/**
* Represents changes in the status of a chat member.
* @see https://core.telegram.org/bots/api#chatmemberupdated
*/
export interface ChatMemberUpdated {
chat: Chat;
from: User;
date: number;
old_chat_member: ChatMember;
new_chat_member: ChatMember;
invite_link?: ChatInviteLink;
};
/**
* Represents a join request to a chat.
* @see https://core.telegram.org/bots/api#chatjoinrequest
*/
export interface ChatJoinRequest {
chat: Chat;
from: User;
date: number;
bio?: string;
invite_link?: ChatInviteLink;
};
/**
* Describes actions that a non-administrator user is allowed to take in a chat.
* @see https://core.telegram.org/bots/api#chatpermissions
*/
export interface ChatPermissions {
can_send_messages?: boolean;
can_send_media_messages?: boolean;
can_send_polls?: boolean;
can_send_other_messages?: boolean;
can_add_web_page_previews?: boolean;
can_change_info?: boolean;
can_invite_users?: boolean;
can_pin_messages?: boolean;
can_manage_topics?: boolean;
};
/**
* Represents a chat's location.
* @see https://core.telegram.org/bots/api#chatlocation
*/
export interface ChatLocation {
location: Location;
address: string;
};
/**
* Represents a foum topic.
* @see https://core.telegram.org/bots/api#forumtopic
*/
export interface ForumTopic {
message_thread_id: number;
name: string;
icon_color: number;
icon_custom_emoji_id?: string;
};
/**
* Represents a bot command.
* @see https://core.telegram.org/bots/api#botcommand
*/
export interface BotCommand {
command: string;
description: string;
};
/**
* Represents the scope to which bot commands are applied.
* @see https://core.telegram.org/bots/api#botcommandscope
*/
export type BotCommandScope =
| BotCommandScopeDefault
| BotCommandScopeAllPrivateChats
| BotCommandScopeAllGroupChats
| BotCommandScopeAllChatAdministrators
| BotCommandScopeChat
| BotCommandScopeChatAdministrators
| BotCommandScopeChatMember;
/**
* Represents the default scope of bot commands. Default commands
* are used if no commands with a narrower scope are specified for the user.
* @see https://core.telegram.org/bots/api#botcommandscopedefault
*/
export interface BotCommandScopeDefault {
type: "default";
};
/**
* Represents the scope of bot commands, covering all private chats.
* @see https://core.telegram.org/bots/api#botcommandscopeallprivatechats
*/
export interface BotCommandScopeAllPrivateChats {
type: "all_private_chats";
};
/**
* Represents the scope of bot commands, covering all group and supergroup chats.
* @see https://core.telegram.org/bots/api#botcommandscopeallgroupchats
*/
export interface BotCommandScopeAllGroupChats {
type: "all_group_chats";
};
/**
* Represents the scope of bot commands, covering all
* group and supergroup chat administrators.
* @see https://core.telegram.org/bots/api#botcommandscopeallchatadministrators
*/
export interface BotCommandScopeAllChatAdministrators {
type: "all_chat_administrators";
};
/**
* Represents the scope of bot commands, covering a specific chat.
* @see https://core.telegram.org/bots/api#botcommandscope
*/
export interface BotCommandScopeChat {
type: "chat";
chat_id: number|string;
};
/**
* Represents the scope of bot commands, covering all
* administrators of a specific group or supergroup chat.
* @see https://core.telegram.org/bots/api#botcommandscopechatadministrators
*/
export interface BotCommandScopeChatAdministrators {
type: "chat_administrators";
chat_id: number|string;
};
/**
* Represents the scope of bot commands, covering
* a specific member of a group or a supergroup chat.
* @see https://core.telegram.org/bots/api#botcommandscopechatmember
*/
export interface BotCommandScopeChatMember {
type: "chat_member";
chat_id: number|string;
user_id: number;
};
/**
* Describes the bot's menu button in a private chat.
* @see https://core.telegram.org/bots/api#menubutton
*/
export type MenuButton =
| MenuButtonCommands
| MenuButtonDefault;
/**
* Represents a menu button, which opens the bot's list of commands.
* @see https://core.telegram.org/bots/api#menubuttoncommands
*/
export interface MenuButtonCommands {
type: "commands";
};
/**
* Describes that no specific value for the menu button was set.
* @see https://core.telegram.org/bots/api#menubuttondefault
*/
export interface MenuButtonDefault {
type: "default";
};
/**
* Decsribes why a request was unsuccessful.
* @see https://core.telegram.org/bots/api#responseparameters
*/
export interface ResponseParameters {
migrate_to_chat_id?: number;
retry_after?: number;
};
/**
* Represents the content of a media message to be sent.
* @see https://core.telegram.org/bots/api#inputmedia
*/
export type InputMedia =
| InputMediaPhoto
| InputMediaVideo
| InputMediaAnimation
| InputMediaAudio
| InputMediaDocument;
/**
* Represents a photo to be sent.
* @see https://core.telegram.org/bots/api#inputmediaphoto
*/
export interface InputMediaPhoto {
type: string;
media: string;
caption?: string;
parse_mode?: string;
caption_entities?: MessageEntity[];
has_spoiler?: boolean;
};
/**
* Represents a video to be sent.
* @see https://core.telegram.org/bots/api#inputmediavideo
*/
export interface InputMediaVideo {
type: string;
media: string;
thumb?: string;
caption?: string;
parse_mode?: string;
caption_entities?: MessageEntity[];
width?: number;
height?: number;
duration?: number;
supports_streaming?: boolean;
has_spoiler?: boolean;
};
/**
* Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.
* @see https://core.telegram.org/bots/api#inputmediaanimation
*/
export interface InputMediaAnimation {
type: string;
media: string;
thumb?: string;
caption?: string;
parse_mode?: string;
caption_entities?: MessageEntity[];
width?: number;
height?: number;
duration?: number;
has_spoiler?: boolean;
};
/**
* Represents an audio file to be treated as music to be sent.
* @see https://core.telegram.org/bots/api#inputmediaaudio
*/
export interface InputMediaAudio {
type: string;
media: string;
thumb?: string;
caption?: string;
parse_mode?: string;
caption_entities?: MessageEntity[];
duration?: number;
performer?: string;
title?: string;
};
/**
* Represents a general file to be sent.
* @see https://core.telegram.org/bots/api#inputmediadocument
*/
export interface InputMediaDocument {
type: string;
media: string;
thumb?: string;
caption?: string;
parse_mode?: string;
caption_entities?: MessageEntity[];
disable_content_type_detection?: boolean;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment