Modern and fully asynchronous framework for Telegram Bot API
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete coverage of all 162+ Telegram Bot API methods for sending messages, managing chats, handling payments, games, stickers, and webhooks. All methods are accessible through the Bot instance with automatic serialization and type safety.
Methods for sending, editing, and managing messages.
async def send_message(
chat_id: int | str,
text: str,
business_connection_id: str | None = None,
message_thread_id: int | None = None,
direct_messages_topic_id: int | None = None,
parse_mode: str | None = None,
entities: list[MessageEntity] | None = None,
link_preview_options: LinkPreviewOptions | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
allow_paid_broadcast: bool | None = None,
message_effect_id: str | None = None,
reply_parameters: ReplyParameters | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send text messages"""
async def send_photo(
chat_id: int | str,
photo: InputFile | str,
business_connection_id: str | None = None,
message_thread_id: int | None = None,
direct_messages_topic_id: int | None = None,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
show_caption_above_media: bool | None = None,
has_spoiler: bool | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
allow_paid_broadcast: bool | None = None,
message_effect_id: str | None = None,
suggested_post_parameters: SuggestedPostParameters | None = None,
reply_parameters: ReplyParameters | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send photos"""
async def send_audio(
chat_id: int | str,
audio: InputFile | str,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
duration: int | None = None,
performer: str | None = None,
title: str | None = None,
thumbnail: InputFile | str | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send audio files"""
async def send_document(
chat_id: int | str,
document: InputFile | str,
thumbnail: InputFile | str | None = None,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
disable_content_type_detection: bool | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send general files"""
async def send_video(
chat_id: int | str,
video: InputFile | str,
duration: int | None = None,
width: int | None = None,
height: int | None = None,
thumbnail: InputFile | str | None = None,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
has_spoiler: bool | None = None,
supports_streaming: bool | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send video files"""
async def send_animation(
chat_id: int | str,
animation: InputFile | str,
duration: int | None = None,
width: int | None = None,
height: int | None = None,
thumbnail: InputFile | str | None = None,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
has_spoiler: bool | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send animation files (GIF or H.264/MPEG-4 AVC video without sound)"""
async def send_voice(
chat_id: int | str,
voice: InputFile | str,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
duration: int | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send voice messages"""
async def send_video_note(
chat_id: int | str,
video_note: InputFile | str,
duration: int | None = None,
length: int | None = None,
thumbnail: InputFile | str | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send video messages (circular videos)"""
async def send_media_group(
chat_id: int | str,
media: list[InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo],
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None
) -> list[Message]:
"""Send a group of photos, videos, documents or audios as an album"""
async def send_location(
chat_id: int | str,
latitude: float,
longitude: float,
horizontal_accuracy: float | None = None,
live_period: int | None = None,
heading: int | None = None,
proximity_alert_radius: int | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send point on the map"""
async def send_venue(
chat_id: int | str,
latitude: float,
longitude: float,
title: str,
address: str,
foursquare_id: str | None = None,
foursquare_type: str | None = None,
google_place_id: str | None = None,
google_place_type: str | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send information about a venue"""
async def send_contact(
chat_id: int | str,
phone_number: str,
first_name: str,
last_name: str | None = None,
vcard: str | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send phone contacts"""
async def send_poll(
chat_id: int | str,
question: str,
options: list[str],
is_anonymous: bool | None = None,
type: str | None = None,
allows_multiple_answers: bool | None = None,
correct_option_id: int | None = None,
explanation: str | None = None,
explanation_parse_mode: str | None = None,
explanation_entities: list[MessageEntity] | None = None,
open_period: int | None = None,
close_date: datetime.datetime | None = None,
is_closed: bool | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send native polls"""
async def send_dice(
chat_id: int | str,
emoji: str | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> Message:
"""Send animated emoji that will display a random value"""Methods for editing existing messages.
async def edit_message_text(
text: str,
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
parse_mode: str | None = None,
entities: list[MessageEntity] | None = None,
disable_web_page_preview: bool | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Edit text and game messages"""
async def edit_message_caption(
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Edit captions of messages"""
async def edit_message_media(
media: InputMedia,
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Edit animation, audio, document, photo, or video messages"""
async def edit_message_reply_markup(
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Edit only the reply markup of messages"""
async def edit_message_live_location(
latitude: float,
longitude: float,
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
horizontal_accuracy: float | None = None,
heading: int | None = None,
proximity_alert_radius: int | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Edit live location messages"""
async def stop_message_live_location(
chat_id: int | str | None = None,
message_id: int | None = None,
inline_message_id: str | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message | bool:
"""Stop updating a live location message"""Methods for managing messages (delete, forward, copy).
async def delete_message(chat_id: int | str, message_id: int) -> bool:
"""Delete a message"""
async def delete_messages(chat_id: int | str, message_ids: list[int]) -> bool:
"""Delete multiple messages simultaneously"""
async def forward_message(
chat_id: int | str,
from_chat_id: int | str,
message_id: int,
disable_notification: bool | None = None,
protect_content: bool | None = None
) -> Message:
"""Forward messages of any kind"""
async def forward_messages(
chat_id: int | str,
from_chat_id: int | str,
message_ids: list[int],
disable_notification: bool | None = None,
protect_content: bool | None = None
) -> list[MessageId]:
"""Forward multiple messages of any kind"""
async def copy_message(
chat_id: int | str,
from_chat_id: int | str,
message_id: int,
caption: str | None = None,
parse_mode: str | None = None,
caption_entities: list[MessageEntity] | None = None,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None
) -> MessageId:
"""Copy messages of any kind"""
async def copy_messages(
chat_id: int | str,
from_chat_id: int | str,
message_ids: list[int],
disable_notification: bool | None = None,
protect_content: bool | None = None,
remove_caption: bool | None = None
) -> list[MessageId]:
"""Copy multiple messages of any kind"""Methods for retrieving chat and member information.
async def get_chat(chat_id: int | str) -> Chat:
"""Get up to date information about the chat"""
async def get_chat_administrators(chat_id: int | str) -> list[ChatMember]:
"""Get a list of administrators in a chat"""
async def get_chat_member_count(chat_id: int | str) -> int:
"""Get the number of members in a chat"""
async def get_chat_member(chat_id: int | str, user_id: int) -> ChatMember:
"""Get information about a member of a chat"""
async def get_chat_menu_button(chat_id: int | None = None) -> MenuButton:
"""Get the current value of the bot's menu button in a private chat"""Methods for managing chat members and permissions.
async def ban_chat_member(
chat_id: int | str,
user_id: int,
until_date: datetime.datetime | None = None,
revoke_messages: bool | None = None
) -> bool:
"""Ban a user in a group, a supergroup or a channel"""
async def unban_chat_member(
chat_id: int | str,
user_id: int,
only_if_banned: bool | None = None
) -> bool:
"""Unban a previously banned user in a supergroup or channel"""
async def restrict_chat_member(
chat_id: int | str,
user_id: int,
permissions: ChatPermissions,
use_independent_chat_permissions: bool | None = None,
until_date: datetime.datetime | None = None
) -> bool:
"""Restrict a user in a supergroup"""
async def promote_chat_member(
chat_id: int | str,
user_id: int,
is_anonymous: bool | None = None,
can_manage_chat: bool | None = None,
can_delete_messages: bool | None = None,
can_manage_video_chats: bool | None = None,
can_restrict_members: bool | None = None,
can_promote_members: bool | None = None,
can_change_info: bool | None = None,
can_invite_users: bool | None = None,
can_post_messages: bool | None = None,
can_edit_messages: bool | None = None,
can_pin_messages: bool | None = None,
can_manage_topics: bool | None = None
) -> bool:
"""Promote or demote a user in a supergroup or a channel"""
async def set_chat_administrator_custom_title(
chat_id: int | str,
user_id: int,
custom_title: str
) -> bool:
"""Set a custom title for an administrator in a supergroup promoted by the bot"""
async def set_chat_permissions(
chat_id: int | str,
permissions: ChatPermissions,
use_independent_chat_permissions: bool | None = None
) -> bool:
"""Set default chat permissions for all members"""Methods for configuring chat settings.
async def set_chat_title(chat_id: int | str, title: str) -> bool:
"""Change the title of a chat"""
async def set_chat_description(chat_id: int | str, description: str | None = None) -> bool:
"""Change the description of a group, a supergroup or a channel"""
async def set_chat_photo(chat_id: int | str, photo: InputFile) -> bool:
"""Set a new profile photo for the chat"""
async def delete_chat_photo(chat_id: int | str) -> bool:
"""Delete a chat photo"""
async def pin_chat_message(
chat_id: int | str,
message_id: int,
disable_notification: bool | None = None
) -> bool:
"""Add a message to the list of pinned messages in a chat"""
async def unpin_chat_message(chat_id: int | str, message_id: int | None = None) -> bool:
"""Remove a message from the list of pinned messages in a chat"""
async def unpin_all_chat_messages(chat_id: int | str) -> bool:
"""Clear the list of pinned messages in a chat"""
async def leave_chat(chat_id: int | str) -> bool:
"""Leave a group, supergroup or channel"""Methods for configuring bot settings and information.
async def get_me() -> User:
"""Get basic info about the bot"""
async def log_out() -> bool:
"""Log out from the cloud Bot API server"""
async def close() -> bool:
"""Close the bot instance"""
async def set_my_commands(
commands: list[BotCommand],
scope: BotCommandScope | None = None,
language_code: str | None = None
) -> bool:
"""Change the list of the bot's commands"""
async def get_my_commands(
scope: BotCommandScope | None = None,
language_code: str | None = None
) -> list[BotCommand]:
"""Get the current list of the bot's commands"""
async def delete_my_commands(
scope: BotCommandScope | None = None,
language_code: str | None = None
) -> bool:
"""Delete the list of the bot's commands"""
async def set_my_name(name: str | None = None, language_code: str | None = None) -> bool:
"""Change the bot's name"""
async def get_my_name(language_code: str | None = None) -> BotName:
"""Get the current bot name"""
async def set_my_description(
description: str | None = None,
language_code: str | None = None
) -> bool:
"""Change the bot's description"""
async def get_my_description(language_code: str | None = None) -> BotDescription:
"""Get the current bot description"""
async def set_my_short_description(
short_description: str | None = None,
language_code: str | None = None
) -> bool:
"""Change the bot's short description"""
async def get_my_short_description(language_code: str | None = None) -> BotShortDescription:
"""Get the current bot short description"""
async def set_chat_menu_button(
chat_id: int | None = None,
menu_button: MenuButton | None = None
) -> bool:
"""Change the bot's menu button in a private chat"""Methods for managing webhooks.
async def set_webhook(
url: str,
certificate: InputFile | None = None,
ip_address: str | None = None,
max_connections: int | None = None,
allowed_updates: list[str] | None = None,
drop_pending_updates: bool | None = None,
secret_token: str | None = None
) -> bool:
"""Specify a URL and receive incoming updates via an outgoing webhook"""
async def delete_webhook(drop_pending_updates: bool | None = None) -> bool:
"""Remove webhook integration"""
async def get_webhook_info() -> WebhookInfo:
"""Get current webhook status"""Methods for handling inline queries and callback queries.
async def answer_inline_query(
inline_query_id: str,
results: list[InlineQueryResult],
cache_time: int | None = None,
is_personal: bool | None = None,
next_offset: str | None = None,
button: InlineQueryResultsButton | None = None
) -> bool:
"""Send answers to an inline query"""
async def answer_callback_query(
callback_query_id: str,
text: str | None = None,
show_alert: bool | None = None,
url: str | None = None,
cache_time: int | None = None
) -> bool:
"""Send answers to callback queries sent from inline keyboards"""Methods for working with files.
async def get_file(file_id: str) -> File:
"""Get basic info about a file and prepare it for downloading"""
async def get_user_profile_photos(
user_id: int,
offset: int | None = None,
limit: int | None = None
) -> UserProfilePhotos:
"""Get a list of profile pictures for a user"""Methods for handling games.
async def send_game(
chat_id: int,
game_short_name: str,
disable_notification: bool | None = None,
protect_content: bool | None = None,
reply_to_message_id: int | None = None,
allow_sending_without_reply: bool | None = None,
reply_markup: InlineKeyboardMarkup | None = None
) -> Message:
"""Send a game"""
async def set_game_score(
user_id: int,
score: int,
force: bool | None = None,
disable_edit_message: bool | None = None,
chat_id: int | None = None,
message_id: int | None = None,
inline_message_id: str | None = None
) -> Message | bool:
"""Set the score of the specified user in a game message"""
async def get_game_high_scores(
user_id: int,
chat_id: int | None = None,
message_id: int | None = None,
inline_message_id: str | None = None
) -> list[GameHighScore]:
"""Get data for high score tables"""from aiogram import Bot
from aiogram.types import FSInputFile, InlineKeyboardMarkup, InlineKeyboardButton
bot = Bot(token="YOUR_TOKEN")
# Text message
await bot.send_message(chat_id, "Hello, World!")
# Photo with caption
photo = FSInputFile("photo.jpg")
await bot.send_photo(chat_id, photo, caption="Beautiful photo!")
# Document
document = FSInputFile("document.pdf")
await bot.send_document(chat_id, document)
# Message with inline keyboard
keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Click me!", callback_data="button_clicked")]
])
await bot.send_message(chat_id, "Choose an option:", reply_markup=keyboard)# Edit message text
message = await bot.send_message(chat_id, "Original text")
await bot.edit_message_text(
chat_id=chat_id,
message_id=message.message_id,
text="Updated text"
)
# Edit message with new keyboard
new_keyboard = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="New button", callback_data="new_action")]
])
await bot.edit_message_reply_markup(
chat_id=chat_id,
message_id=message.message_id,
reply_markup=new_keyboard
)# Get chat info
chat = await bot.get_chat(chat_id)
print(f"Chat title: {chat.title}")
# Ban user
await bot.ban_chat_member(chat_id, user_id)
# Promote user to admin
await bot.promote_chat_member(
chat_id=chat_id,
user_id=user_id,
can_delete_messages=True,
can_invite_users=True
)
# Set chat title
await bot.set_chat_title(chat_id, "New Chat Title")Install with Tessl CLI
npx tessl i tessl/pypi-aiogram