Bot object

Low level API

Subclass of this class used only for splitting network interface from all of API methods.

class aiogram.bot.base.BaseBot(token: String, loop: Union[asyncio.base_events.BaseEventLoop, asyncio.events.AbstractEventLoop, None] = None, connections_limit: Optional[Integer] = None, proxy: Optional[String] = None, proxy_auth: Optional[aiohttp.helpers.BasicAuth] = None, validate_token: Optional[Boolean] = True, parse_mode: Optional[String] = None, timeout: Union[Integer, Float, aiohttp.client.ClientTimeout, None] = None)[source]

Bases: object

Base class for bot. It’s raw bot.

Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-bot

Parameters
  • token (str) – token from @BotFather

  • loop (Optional Union asyncio.BaseEventLoop, asyncio.AbstractEventLoop) – event loop

  • connections_limit (int) – connections limit for aiohttp.ClientSession

  • proxy (str) – HTTP proxy URL

  • proxy_auth (Optional aiohttp.BasicAuth) – Authentication information

  • validate_token (bool) – Validate token.

  • parse_mode (str) – You can set default parse mode

  • timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeout

Raise

when token is invalid throw an aiogram.utils.exceptions.ValidationError

request_timeout(timeout: Union[Integer, Float, aiohttp.client.ClientTimeout])[source]

Context manager implements opportunity to change request timeout in current context

Parameters

timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeout

Returns

async close()[source]

Close all client sessions

async request(method: String, data: Optional[Dict] = None, files: Optional[Dict] = None, **kwargs) → Union[List, Dict, Boolean][source]

Make an request to Telegram Bot API

https://core.telegram.org/bots/api#making-requests

Parameters
  • method (str) – API method

  • data (dict) – request parameters

  • files (dict) – files

Returns

result

Return type

Union[List, Dict]

Raise

aiogram.exceptions.TelegramApiError

async download_file(file_path: String, destination: Optional[InputFile] = None, timeout: Optional[Integer] = <object object>, chunk_size: Optional[Integer] = 65536, seek: Optional[Boolean] = True) → Union[_io.BytesIO, _io.FileIO][source]

Download file by file_path to destination

if You want to automatically create destination (io.BytesIO) use default value of destination and handle result of this method.

Parameters
  • file_path (str) – file path on telegram server (You can get it from aiogram.types.File)

  • destination – filename or instance of io.IOBase. For e. g. io.BytesIO

  • timeout – Integer

  • chunk_size – Integer

  • seek – Boolean - go to start of file when downloading is finished.

Returns

destination

async send_file(file_type, method, file, payload) → Union[Dict, Boolean][source]

Send file

https://core.telegram.org/bots/api#inputfile

Parameters
  • file_type – field name

  • method – API method

  • file – String or io.IOBase

  • payload – request payload

Returns

response

Telegram Bot

This class based on aiogram.bot.base.BaseBot

class aiogram.bot.bot.Bot(token: String, loop: Union[asyncio.base_events.BaseEventLoop, asyncio.events.AbstractEventLoop, None] = None, connections_limit: Optional[Integer] = None, proxy: Optional[String] = None, proxy_auth: Optional[aiohttp.helpers.BasicAuth] = None, validate_token: Optional[Boolean] = True, parse_mode: Optional[String] = None, timeout: Union[Integer, Float, aiohttp.client.ClientTimeout, None] = None)[source]

Bases: aiogram.bot.base.BaseBot, aiogram.utils.mixins.DataMixin, aiogram.utils.mixins.ContextInstanceMixin

Base bot class

Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-bot

Parameters
  • token (str) – token from @BotFather

  • loop (Optional Union asyncio.BaseEventLoop, asyncio.AbstractEventLoop) – event loop

  • connections_limit (int) – connections limit for aiohttp.ClientSession

  • proxy (str) – HTTP proxy URL

  • proxy_auth (Optional aiohttp.BasicAuth) – Authentication information

  • validate_token (bool) – Validate token.

  • parse_mode (str) – You can set default parse mode

  • timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeout

Raise

when token is invalid throw an aiogram.utils.exceptions.ValidationError

property me

Alias for self.get_me() but lazy and with caching.

Returns

aiogram.types.User

async download_file_by_id(file_id: String, destination=None, timeout: Integer = 30, chunk_size: Integer = 65536, seek: Boolean = True)[source]

Download file by file_id to destination

if You want to automatically create destination (io.BytesIO) use default value of destination and handle result of this method.

Parameters
  • file_id – str

  • destination – filename or instance of io.IOBase. For e. g. io.BytesIO

  • timeout – int

  • chunk_size – int

  • seek – bool - go to start of file when downloading is finished

Returns

destination

async get_updates(offset: Optional[Integer] = None, limit: Optional[Integer] = None, timeout: Optional[Integer] = None, allowed_updates: Optional[List[String]] = None) → List[aiogram.types.update.Update][source]

Use this method to receive incoming updates using long polling (wiki).

Notes 1. This method will not work if an outgoing webhook is set up. 2. In order to avoid getting duplicate updates, recalculate offset after each server response.

Source: https://core.telegram.org/bots/api#getupdates

Parameters
  • offset (typing.Union[base.Integer, None]) – Identifier of the first update to be returned

  • limit (typing.Union[base.Integer, None]) – Limits the number of updates to be retrieved

  • timeout (typing.Union[base.Integer, None]) – Timeout in seconds for long polling

  • allowed_updates (typing.Union[typing.List[base.String], None]) – List the types of updates you want your bot to receive

Returns

An Array of Update objects is returned

Return type

typing.List[types.Update]

async set_webhook(url: String, certificate: Optional[InputFile] = None, max_connections: Optional[Integer] = None, allowed_updates: Optional[List[String]] = None) → Boolean[source]

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts.

Source: https://core.telegram.org/bots/api#setwebhook

Parameters
  • url (base.String) – HTTPS url to send updates to. Use an empty string to remove webhook integration

  • certificate (typing.Union[base.InputFile, None]) – Upload your public key certificate so that the root certificate in use can be checked

  • max_connections (typing.Union[base.Integer, None]) – Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100.

  • allowed_updates (typing.Union[typing.List[base.String], None]) – List the types of updates you want your bot to receive

Returns

Returns true

Return type

base.Boolean

async delete_webhook() → Boolean[source]

Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters.

Source: https://core.telegram.org/bots/api#deletewebhook

Returns

Returns True on success

Return type

base.Boolean

async get_webhook_info() → aiogram.types.webhook_info.WebhookInfo[source]

Use this method to get current webhook status. Requires no parameters.

If the bot is using getUpdates, will return an object with the url field empty.

Source: https://core.telegram.org/bots/api#getwebhookinfo

Returns

On success, returns a WebhookInfo object

Return type

types.WebhookInfo

async get_me() → aiogram.types.user.User[source]

A simple method for testing your bot’s auth token. Requires no parameters.

Source: https://core.telegram.org/bots/api#getme

Returns

Returns basic information about the bot in form of a User object

Return type

types.User

async send_message(chat_id: Union[Integer, String], text: String, parse_mode: Optional[String] = None, disable_web_page_preview: Optional[Boolean] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send text messages.

Source: https://core.telegram.org/bots/api#sendmessage

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • text (base.String) – Text of the message to be sent

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • disable_web_page_preview (typing.Union[base.Boolean, None]) – Disables link previews for links in this message

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async forward_message(chat_id: Union[Integer, String], from_chat_id: Union[Integer, String], message_id: Integer, disable_notification: Optional[Boolean] = None) → aiogram.types.message.Message[source]

Use this method to forward messages of any kind.

Source: https://core.telegram.org/bots/api#forwardmessage

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • from_chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the chat where the original message was sent

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • message_id (base.Integer) – Message identifier in the chat specified in from_chat_id

Returns

On success, the sent Message is returned

Return type

types.Message

async send_photo(chat_id: Union[Integer, String], photo: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send photos.

Source: https://core.telegram.org/bots/api#sendphoto

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • photo (typing.Union[base.InputFile, base.String]) – Photo to send

  • caption (typing.Union[base.String, None]) – Photo caption (may also be used when resending photos by file_id), 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_audio(chat_id: Union[Integer, String], audio: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, duration: Optional[Integer] = None, performer: Optional[String] = None, title: Optional[String] = None, thumb: Union[InputFile, String, None] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format.

For sending voice messages, use the sendVoice method instead.

Source: https://core.telegram.org/bots/api#sendaudio

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • audio (typing.Union[base.InputFile, base.String]) – Audio file to send

  • caption (typing.Union[base.String, None]) – Audio caption, 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • duration (typing.Union[base.Integer, None]) – Duration of the audio in seconds

  • performer (typing.Union[base.String, None]) – Performer

  • title (typing.Union[base.String, None]) – Track name

  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_document(chat_id: Union[Integer, String], document: Union[InputFile, String], thumb: Union[InputFile, String, None] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send general files.

Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.

Source: https://core.telegram.org/bots/api#senddocument

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • document (typing.Union[base.InputFile, base.String]) – File to send

  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent

  • caption (typing.Union[base.String, None]) – Document caption (may also be used when resending documents by file_id), 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply], None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_video(chat_id: Union[Integer, String], video: Union[InputFile, String], duration: Optional[Integer] = None, width: Optional[Integer] = None, height: Optional[Integer] = None, thumb: Union[InputFile, String, None] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, supports_streaming: Optional[Boolean] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).

Source: https://core.telegram.org/bots/api#sendvideo

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • video (typing.Union[base.InputFile, base.String]) – Video to send

  • duration (typing.Union[base.Integer, None]) – Duration of sent video in seconds

  • width (typing.Union[base.Integer, None]) – Video width

  • height (typing.Union[base.Integer, None]) – Video height

  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent

  • caption (typing.Union[base.String, None]) – Video caption (may also be used when resending videos by file_id), 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • supports_streaming (typing.Union[base.Boolean, None]) – Pass True, if the uploaded video is suitable for streaming

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_animation(chat_id: Union[Integer, String], animation: Union[InputFile, String], duration: Optional[Integer] = None, width: Optional[Integer] = None, height: Optional[Integer] = None, thumb: Union[InputFile, String, None] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).

On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.

Source https://core.telegram.org/bots/api#sendanimation

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • animation (typing.Union[base.InputFile, base.String]) – Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data

  • duration (typing.Union[base.Integer, None]) – Duration of sent animation in seconds

  • width (typing.Union[base.Integer, None]) – Animation width

  • height (typing.Union[base.Integer, None]) – Animation height

  • thumb (typing.Union[typing.Union[base.InputFile, base.String], None]) – Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 90.

  • caption (typing.Union[base.String, None]) – Animation caption (may also be used when resending animation by file_id), 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply], None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_voice(chat_id: Union[Integer, String], voice: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, duration: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.

For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document).

Source: https://core.telegram.org/bots/api#sendvoice

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • voice (typing.Union[base.InputFile, base.String]) – Audio file to send

  • caption (typing.Union[base.String, None]) – Voice message caption, 0-1024 characters

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • duration (typing.Union[base.Integer, None]) – Duration of the voice message in seconds

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_video_note(chat_id: Union[Integer, String], video_note: Union[InputFile, String], duration: Optional[Integer] = None, length: Optional[Integer] = None, thumb: Union[InputFile, String, None] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages.

Source: https://core.telegram.org/bots/api#sendvideonote

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • video_note (typing.Union[base.InputFile, base.String]) – Video note to send

  • duration (typing.Union[base.Integer, None]) – Duration of sent video in seconds

  • length (typing.Union[base.Integer, None]) – Video width and height

  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_media_group(chat_id: Union[Integer, String], media: Union[aiogram.types.input_media.MediaGroup, List], disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None) → List[aiogram.types.message.Message][source]

Use this method to send a group of photos or videos as an album.

Source: https://core.telegram.org/bots/api#sendmediagroup

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • media (typing.Union[types.MediaGroup, typing.List]) – A JSON-serialized array describing photos and videos to be sent

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

Returns

On success, an array of the sent Messages is returned

Return type

typing.List[types.Message]

async send_location(chat_id: Union[Integer, String], latitude: Float, longitude: Float, live_period: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send point on the map.

Source: https://core.telegram.org/bots/api#sendlocation

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • latitude (base.Float) – Latitude of the location

  • longitude (base.Float) – Longitude of the location

  • live_period (typing.Union[base.Integer, None]) – Period in seconds for which the location will be updated

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async edit_message_live_location(latitude: Float, longitude: Float, chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation.

Source: https://core.telegram.org/bots/api#editmessagelivelocation

Parameters
  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • latitude (base.Float) – Latitude of new location

  • longitude (base.Float) – Longitude of new location

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

Return type

typing.Union[types.Message, base.Boolean]

async stop_message_live_location(chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires.

Source: https://core.telegram.org/bots/api#stopmessagelivelocation

Parameters
  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.

Return type

typing.Union[types.Message, base.Boolean]

async send_venue(chat_id: Union[Integer, String], latitude: Float, longitude: Float, title: String, address: String, foursquare_id: Optional[String] = None, foursquare_type: Optional[String] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send information about a venue.

Source: https://core.telegram.org/bots/api#sendvenue

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • latitude (base.Float) – Latitude of the venue

  • longitude (base.Float) – Longitude of the venue

  • title (base.String) – Name of the venue

  • address (base.String) – Address of the venue

  • foursquare_id (typing.Union[base.String, None]) – Foursquare identifier of the venue

  • foursquare_type (typing.Union[base.String, None]) – Foursquare type of the venue, if known

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_contact(chat_id: Union[Integer, String], phone_number: String, first_name: String, last_name: Optional[String] = None, vcard: Optional[String] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send phone contacts.

Source: https://core.telegram.org/bots/api#sendcontact

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • phone_number (base.String) – Contact’s phone number

  • first_name (base.String) – Contact’s first name

  • last_name (typing.Union[base.String, None]) – Contact’s last name

  • vcard (typing.Union[base.String, None]) – vcard

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_poll(chat_id: Union[Integer, String], question: String, options: List[String], disable_notification: Optional[Boolean], reply_to_message_id: Optional[Integer], reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send a native poll. A native poll can’t be sent to a private chat. On success, the sent Message is returned.

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername). A native poll can’t be sent to a private chat.

  • question (base.String) – Poll question, 1-255 characters

  • options – List of answer options, 2-10 strings 1-100 characters each

  • optionstyping.List[base.String]

  • disable_notification (typing.Optional[Boolean]) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (typing.Optional[Integer]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async send_chat_action(chat_id: Union[Integer, String], action: String) → Boolean[source]

Use this method when you need to tell the user that something is happening on the bot’s side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status).

We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.

Source: https://core.telegram.org/bots/api#sendchataction

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • action (base.String) – Type of action to broadcast

Returns

Returns True on success

Return type

base.Boolean

async get_user_profile_photos(user_id: Integer, offset: Optional[Integer] = None, limit: Optional[Integer] = None) → aiogram.types.user_profile_photos.UserProfilePhotos[source]

Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.

Source: https://core.telegram.org/bots/api#getuserprofilephotos

Parameters
  • user_id (base.Integer) – Unique identifier of the target user

  • offset (typing.Union[base.Integer, None]) – Sequential number of the first photo to be returned. By default, all photos are returned

  • limit (typing.Union[base.Integer, None]) – Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100

Returns

Returns a UserProfilePhotos object

Return type

types.UserProfilePhotos

async get_file(file_id: String) → aiogram.types.file.File[source]

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.

Note: This function may not preserve the original file name and MIME type. You should save the file’s MIME type and name (if available) when the File object is received.

Source: https://core.telegram.org/bots/api#getfile

Parameters

file_id (base.String) – File identifier to get info about

Returns

On success, a File object is returned

Return type

types.File

async kick_chat_member(chat_id: Union[Integer, String], user_id: Integer, until_date: Optional[Integer] = None) → Boolean[source]

Use this method to kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first.

The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group. Otherwise members may only be removed by the group’s creator or by the member that added them.

Source: https://core.telegram.org/bots/api#kickchatmember

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target group or username of the target supergroup or channel

  • user_id (base.Integer) – Unique identifier of the target user

  • until_date (typing.Union[base.Integer, None]) – Date when the user will be unbanned, unix time

Returns

Returns True on success

Return type

base.Boolean

async unban_chat_member(chat_id: Union[Integer, String], user_id: Integer) → Boolean[source]

Use this method to unban a previously kicked user in a supergroup or channel. ` The user will not return to the group or channel automatically, but will be able to join via link, etc.

The bot must be an administrator for this to work.

Source: https://core.telegram.org/bots/api#unbanchatmember

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target group or username of the target supergroup or channel

  • user_id (base.Integer) – Unique identifier of the target user

Returns

Returns True on success

Return type

base.Boolean

async restrict_chat_member(chat_id: Union[Integer, String], user_id: Integer, until_date: Optional[Integer] = None, can_send_messages: Optional[Boolean] = None, can_send_media_messages: Optional[Boolean] = None, can_send_other_messages: Optional[Boolean] = None, can_add_web_page_previews: Optional[Boolean] = None) → Boolean[source]

Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.

Source: https://core.telegram.org/bots/api#restrictchatmember

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup

  • user_id (base.Integer) – Unique identifier of the target user

  • until_date (typing.Union[base.Integer, None]) – Date when restrictions will be lifted for the user, unix time

  • can_send_messages (typing.Union[base.Boolean, None]) – Pass True, if the user can send text messages, contacts, locations and venues

  • can_send_media_messages (typing.Union[base.Boolean, None]) – Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages

  • can_send_other_messages (typing.Union[base.Boolean, None]) – Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages

  • can_add_web_page_previews (typing.Union[base.Boolean, None]) – Pass True, if the user may add web page previews to their messages, implies can_send_media_messages

Returns

Returns True on success

Return type

base.Boolean

async promote_chat_member(chat_id: Union[Integer, String], user_id: Integer, can_change_info: Optional[Boolean] = None, can_post_messages: Optional[Boolean] = None, can_edit_messages: Optional[Boolean] = None, can_delete_messages: Optional[Boolean] = None, can_invite_users: Optional[Boolean] = None, can_restrict_members: Optional[Boolean] = None, can_pin_messages: Optional[Boolean] = None, can_promote_members: Optional[Boolean] = None) → Boolean[source]

Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.

Source: https://core.telegram.org/bots/api#promotechatmember

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • user_id (base.Integer) – Unique identifier of the target user

  • can_change_info (typing.Union[base.Boolean, None]) – Pass True, if the administrator can change chat title, photo and other settings

  • can_post_messages (typing.Union[base.Boolean, None]) – Pass True, if the administrator can create channel posts, channels only

  • can_edit_messages (typing.Union[base.Boolean, None]) – Pass True, if the administrator can edit messages of other users, channels only

  • can_delete_messages (typing.Union[base.Boolean, None]) – Pass True, if the administrator can delete messages of other users

  • can_invite_users (typing.Union[base.Boolean, None]) – Pass True, if the administrator can invite new users to the chat

  • can_restrict_members (typing.Union[base.Boolean, None]) – Pass True, if the administrator can restrict, ban or unban chat members

  • can_pin_messages (typing.Union[base.Boolean, None]) – Pass True, if the administrator can pin messages, supergroups only

  • can_promote_members (typing.Union[base.Boolean, None]) – Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)

Returns

Returns True on success

Return type

base.Boolean

Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#exportchatinvitelink

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

Returns

Returns exported invite link as String on success

Return type

base.String

async set_chat_photo(chat_id: Union[Integer, String], photo: InputFile) → Boolean[source]

Use this method to set a new profile photo for the chat. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#setchatphoto

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • photo (base.InputFile) – New chat photo, uploaded using multipart/form-data

Returns

Returns True on success

Return type

base.Boolean

async delete_chat_photo(chat_id: Union[Integer, String]) → Boolean[source]

Use this method to delete a chat photo. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#deletechatphoto

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

Returns

Returns True on success

Return type

base.Boolean

async set_chat_title(chat_id: Union[Integer, String], title: String) → Boolean[source]

Use this method to change the title of a chat. Titles can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#setchattitle

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • title (base.String) – New chat title, 1-255 characters

Returns

Returns True on success

Return type

base.Boolean

async set_chat_description(chat_id: Union[Integer, String], description: Optional[String] = None) → Boolean[source]

Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#setchatdescription

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • description (typing.Union[base.String, None]) – New chat description, 0-255 characters

Returns

Returns True on success

Return type

base.Boolean

async pin_chat_message(chat_id: Union[Integer, String], message_id: Integer, disable_notification: Optional[Boolean] = None) → Boolean[source]

Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#pinchatmessage

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup

  • message_id (base.Integer) – Identifier of a message to pin

  • disable_notification (typing.Union[base.Boolean, None]) – Pass True, if it is not necessary to send a notification to all group members about the new pinned message

Returns

Returns True on success

Return type

base.Boolean

async unpin_chat_message(chat_id: Union[Integer, String]) → Boolean[source]

Use this method to unpin a message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#unpinchatmessage

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup

Returns

Returns True on success

Return type

base.Boolean

async leave_chat(chat_id: Union[Integer, String]) → Boolean[source]

Use this method for your bot to leave a group, supergroup or channel.

Source: https://core.telegram.org/bots/api#leavechat

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel

Returns

Returns True on success

Return type

base.Boolean

async get_chat(chat_id: Union[Integer, String]) → aiogram.types.chat.Chat[source]

Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).

Source: https://core.telegram.org/bots/api#getchat

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel

Returns

Returns a Chat object on success

Return type

types.Chat

async get_chat_administrators(chat_id: Union[Integer, String]) → List[aiogram.types.chat_member.ChatMember][source]

Use this method to get a list of administrators in a chat.

Source: https://core.telegram.org/bots/api#getchatadministrators

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel

Returns

On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.

Return type

typing.List[types.ChatMember]

async get_chat_members_count(chat_id: Union[Integer, String]) → Integer[source]

Use this method to get the number of members in a chat.

Source: https://core.telegram.org/bots/api#getchatmemberscount

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel

Returns

Returns Int on success

Return type

base.Integer

async get_chat_member(chat_id: Union[Integer, String], user_id: Integer) → aiogram.types.chat_member.ChatMember[source]

Use this method to get information about a member of a chat.

Source: https://core.telegram.org/bots/api#getchatmember

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel

  • user_id (base.Integer) – Unique identifier of the target user

Returns

Returns a ChatMember object on success

Return type

types.ChatMember

async set_chat_sticker_set(chat_id: Union[Integer, String], sticker_set_name: String) → Boolean[source]

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.

Source: https://core.telegram.org/bots/api#setchatstickerset

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup

  • sticker_set_name (base.String) – Name of the sticker set to be set as the group sticker set

Returns

Returns True on success

Return type

base.Boolean

async delete_chat_sticker_set(chat_id: Union[Integer, String]) → Boolean[source]

Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.

Source: https://core.telegram.org/bots/api#deletechatstickerset

Parameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup

Returns

Returns True on success

Return type

base.Boolean

async answer_callback_query(callback_query_id: String, text: Optional[String] = None, show_alert: Optional[Boolean] = None, url: Optional[String] = None, cache_time: Optional[Integer] = None) → Boolean[source]

Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.

Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

Source: https://core.telegram.org/bots/api#answercallbackquery

Parameters
  • callback_query_id (base.String) – Unique identifier for the query to be answered

  • text (typing.Union[base.String, None]) – Text of the notification. If not specified, nothing will be shown to the user, 0-1024 characters

  • show_alert (typing.Union[base.Boolean, None]) – If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.

  • url (typing.Union[base.String, None]) – URL that will be opened by the user’s client

  • cache_time (typing.Union[base.Integer, None]) – The maximum amount of time in seconds that the result of the callback query may be cached client-side.

Returns

On success, True is returned

Return type

base.Boolean

async edit_message_text(text: String, chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, parse_mode: Optional[String] = None, disable_web_page_preview: Optional[Boolean] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagetext

Parameters
  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • text (base.String) – New text of the message

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • disable_web_page_preview (typing.Union[base.Boolean, None]) – Disables link previews for links in this message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

Return type

typing.Union[types.Message, base.Boolean]

async edit_message_caption(chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagecaption

Parameters
  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • caption (typing.Union[base.String, None]) – New caption of the message

  • parse_mode (typing.Union[base.String, None]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

Return type

typing.Union[types.Message, base.Boolean]

async edit_message_media(media: aiogram.types.input_media.InputMedia, chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → Union[aiogram.types.message.Message, Boolean][source]

Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can’t be uploaded. Use previously uploaded file via its file_id or specify a URL.

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

Source https://core.telegram.org/bots/api#editmessagemedia

Parameters
  • chat_id (typing.Union[typing.Union[base.Integer, base.String], None]) – Required if inline_message_id is not specified

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • media (types.InputMedia) – A JSON-serialized object for a new media content of the message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned

Return type

typing.Union[types.Message, base.Boolean]

async edit_message_reply_markup(chat_id: Union[Integer, String, None] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagereplymarkup

Parameters
  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.

Return type

typing.Union[types.Message, base.Boolean]

async stop_poll(chat_id: Union[String, Integer], message_id: Integer, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.poll.Poll[source]

Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.

Parameters
  • chat_id (typing.Union[base.String, base.Integer]) – Unique identifier for the target chat or username of the target channel

  • message_id (base.Integer) – Identifier of the original message with the poll

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for a new message inline keyboard.

Returns

On success, the stopped Poll with the final results is returned.

Return type

types.Poll

async delete_message(chat_id: Union[Integer, String], message_id: Integer) → Boolean[source]

Use this method to delete a message, including service messages, with the following limitations: - A message can only be deleted if it was sent less than 48 hours ago. - Bots can delete outgoing messages in private chats, groups, and supergroups. - Bots can delete incoming messages in private chats. - Bots granted can_post_messages permissions can delete outgoing messages in channels. - If the bot is an administrator of a group, it can delete any message there. - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.

Source: https://core.telegram.org/bots/api#deletemessage

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • message_id (base.Integer) – Identifier of the message to delete

Returns

Returns True on success

Return type

base.Boolean

async send_sticker(chat_id: Union[Integer, String], sticker: Union[InputFile, String], disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Union[aiogram.types.inline_keyboard.InlineKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardMarkup, aiogram.types.reply_keyboard.ReplyKeyboardRemove, aiogram.types.force_reply.ForceReply, None] = None) → aiogram.types.message.Message[source]

Use this method to send .webp stickers.

Source: https://core.telegram.org/bots/api#sendsticker

Parameters
  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel

  • sticker (typing.Union[base.InputFile, base.String]) – Sticker to send

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

Returns

On success, the sent Message is returned

Return type

types.Message

async get_sticker_set(name: String) → aiogram.types.sticker_set.StickerSet[source]

Use this method to get a sticker set.

Source: https://core.telegram.org/bots/api#getstickerset

Parameters

name (base.String) – Name of the sticker set

Returns

On success, a StickerSet object is returned

Return type

types.StickerSet

async upload_sticker_file(user_id: Integer, png_sticker: InputFile) → aiogram.types.file.File[source]

Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).

Source: https://core.telegram.org/bots/api#uploadstickerfile

Parameters
  • user_id (base.Integer) – User identifier of sticker file owner

  • png_sticker (base.InputFile) – Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

Returns

Returns the uploaded File on success

Return type

types.File

async create_new_sticker_set(user_id: Integer, name: String, title: String, png_sticker: Union[InputFile, String], emojis: String, contains_masks: Optional[Boolean] = None, mask_position: Optional[aiogram.types.mask_position.MaskPosition] = None) → Boolean[source]

Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.

Source: https://core.telegram.org/bots/api#createnewstickerset

Parameters
  • user_id (base.Integer) – User identifier of created sticker set owner

  • name (base.String) – Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals)

  • title (base.String) – Sticker set title, 1-64 characters

  • png_sticker (typing.Union[base.InputFile, base.String]) – Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

  • emojis (base.String) – One or more emoji corresponding to the sticker

  • contains_masks (typing.Union[base.Boolean, None]) – Pass True, if a set of mask stickers should be created

  • mask_position (typing.Union[types.MaskPosition, None]) – A JSON-serialized object for position where the mask should be placed on faces

Returns

Returns True on success

Return type

base.Boolean

async add_sticker_to_set(user_id: Integer, name: String, png_sticker: Union[InputFile, String], emojis: String, mask_position: Optional[aiogram.types.mask_position.MaskPosition] = None) → Boolean[source]

Use this method to add a new sticker to a set created by the bot.

Source: https://core.telegram.org/bots/api#addstickertoset

Parameters
  • user_id (base.Integer) – User identifier of sticker set owner

  • name (base.String) – Sticker set name

  • png_sticker (typing.Union[base.InputFile, base.String]) – Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

  • emojis (base.String) – One or more emoji corresponding to the sticker

  • mask_position (typing.Union[types.MaskPosition, None]) – A JSON-serialized object for position where the mask should be placed on faces

Returns

Returns True on success

Return type

base.Boolean

async set_sticker_position_in_set(sticker: String, position: Integer) → Boolean[source]

Use this method to move a sticker in a set created by the bot to a specific position.

Source: https://core.telegram.org/bots/api#setstickerpositioninset

Parameters
  • sticker (base.String) – File identifier of the sticker

  • position (base.Integer) – New sticker position in the set, zero-based

Returns

Returns True on success

Return type

base.Boolean

async delete_sticker_from_set(sticker: String) → Boolean[source]

Use this method to delete a sticker from a set created by the bot.

The following methods and objects allow your bot to work in inline mode.

Source: https://core.telegram.org/bots/api#deletestickerfromset

Parameters

sticker (base.String) – File identifier of the sticker

Returns

Returns True on success

Return type

base.Boolean

async answer_inline_query(inline_query_id: String, results: List[aiogram.types.inline_query_result.InlineQueryResult], cache_time: Optional[Integer] = None, is_personal: Optional[Boolean] = None, next_offset: Optional[String] = None, switch_pm_text: Optional[String] = None, switch_pm_parameter: Optional[String] = None) → Boolean[source]

Use this method to send answers to an inline query. No more than 50 results per query are allowed.

Source: https://core.telegram.org/bots/api#answerinlinequery

Parameters
  • inline_query_id (base.String) – Unique identifier for the answered query

  • results (typing.List[types.InlineQueryResult]) – A JSON-serialized array of results for the inline query

  • cache_time (typing.Union[base.Integer, None]) – The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.

  • is_personal (typing.Union[base.Boolean, None]) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query

  • next_offset (typing.Union[base.String, None]) – Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.

  • switch_pm_text (typing.Union[base.String, None]) – If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter

  • switch_pm_parameter (typing.Union[base.String, None]) – Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.

Returns

On success, True is returned

Return type

base.Boolean

async send_invoice(chat_id: Integer, title: String, description: String, payload: String, provider_token: String, start_parameter: String, currency: String, prices: List[aiogram.types.labeled_price.LabeledPrice], provider_data: Optional[Dict] = None, photo_url: Optional[String] = None, photo_size: Optional[Integer] = None, photo_width: Optional[Integer] = None, photo_height: Optional[Integer] = None, need_name: Optional[Boolean] = None, need_phone_number: Optional[Boolean] = None, need_email: Optional[Boolean] = None, need_shipping_address: Optional[Boolean] = None, is_flexible: Optional[Boolean] = None, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to send invoices.

Source: https://core.telegram.org/bots/api#sendinvoice

Parameters
  • chat_id (base.Integer) – Unique identifier for the target private chat

  • title (base.String) – Product name, 1-32 characters

  • description (base.String) – Product description, 1-255 characters

  • payload (base.String) – Bot-defined invoice payload, 1-128 bytes This will not be displayed to the user, use for your internal processes.

  • provider_token (base.String) – Payments provider token, obtained via Botfather

  • start_parameter (base.String) – Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter

  • currency (base.String) – Three-letter ISO 4217 currency code, see more on currencies

  • prices (typing.List[types.LabeledPrice]) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)

  • provider_data (typing.Union[typing.Dict, None]) – JSON-encoded data about the invoice, which will be shared with the payment provider

  • photo_url (typing.Union[base.String, None]) – URL of the product photo for the invoice

  • photo_size (typing.Union[base.Integer, None]) – Photo size

  • photo_width (typing.Union[base.Integer, None]) – Photo width

  • photo_height (typing.Union[base.Integer, None]) – Photo height

  • need_name (typing.Union[base.Boolean, None]) – Pass True, if you require the user’s full name to complete the order

  • need_phone_number (typing.Union[base.Boolean, None]) – Pass True, if you require the user’s phone number to complete the order

  • need_email (typing.Union[base.Boolean, None]) – Pass True, if you require the user’s email to complete the order

  • need_shipping_address (typing.Union[base.Boolean, None]) – Pass True, if you require the user’s shipping address to complete the order

  • is_flexible (typing.Union[base.Boolean, None]) – Pass True, if the final price depends on the shipping method

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for an inline keyboard If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button.

Returns

On success, the sent Message is returned

Return type

types.Message

async answer_shipping_query(shipping_query_id: String, ok: Boolean, shipping_options: Optional[List[aiogram.types.shipping_option.ShippingOption]] = None, error_message: Optional[String] = None) → Boolean[source]

If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot.

Source: https://core.telegram.org/bots/api#answershippingquery

Parameters
  • shipping_query_id (base.String) – Unique identifier for the query to be answered

  • ok (base.Boolean) – Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)

  • shipping_options (typing.Union[typing.List[types.ShippingOption], None]) – Required if ok is True. A JSON-serialized array of available shipping options

  • error_message (typing.Union[base.String, None]) – Required if ok is False Error message in human readable form that explains why it is impossible to complete the order (e.g. “Sorry, delivery to your desired address is unavailable’). Telegram will display this message to the user.

Returns

On success, True is returned

Return type

base.Boolean

async answer_pre_checkout_query(pre_checkout_query_id: String, ok: Boolean, error_message: Optional[String] = None) → Boolean[source]

Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries.

Source: https://core.telegram.org/bots/api#answerprecheckoutquery

Parameters
  • pre_checkout_query_id (base.String) – Unique identifier for the query to be answered

  • ok (base.Boolean) – Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.

  • error_message (typing.Union[base.String, None]) – Required if ok is False Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. “Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!”). Telegram will display this message to the user.

Returns

On success, True is returned

Return type

base.Boolean

async set_passport_data_errors(user_id: Integer, errors: List[aiogram.types.passport_element_error.PassportElementError]) → Boolean[source]

Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.

Use this if the data submitted by the user doesn’t satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.

Source https://core.telegram.org/bots/api#setpassportdataerrors

Parameters
  • user_id (base.Integer) – User identifier

  • errors (typing.List[types.PassportElementError]) – A JSON-serialized array describing the errors

Returns

Returns True on success

Return type

base.Boolean

async send_game(chat_id: Integer, game_short_name: String, disable_notification: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, reply_markup: Optional[aiogram.types.inline_keyboard.InlineKeyboardMarkup] = None) → aiogram.types.message.Message[source]

Use this method to send a game.

Source: https://core.telegram.org/bots/api#sendgame

Parameters
  • chat_id (base.Integer) – Unique identifier for the target chat

  • game_short_name (base.String) – Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.

  • disable_notification (typing.Union[base.Boolean, None]) – Sends the message silently. Users will receive a notification with no sound

  • reply_to_message_id (typing.Union[base.Integer, None]) – If the message is a reply, ID of the original message

  • reply_markup (typing.Union[types.InlineKeyboardMarkup, None]) – A JSON-serialized object for an inline keyboard If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.

Returns

On success, the sent Message is returned

Return type

types.Message

async set_game_score(user_id: Integer, score: Integer, force: Optional[Boolean] = None, disable_edit_message: Optional[Boolean] = None, chat_id: Optional[Integer] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None) → aiogram.types.message.Message[source]

Use this method to set the score of the specified user in a game.

Source: https://core.telegram.org/bots/api#setgamescore

Parameters
  • user_id (base.Integer) – User identifier

  • score (base.Integer) – New score, must be non-negative

  • force (typing.Union[base.Boolean, None]) – Pass True, if the high score is allowed to decrease This can be useful when fixing mistakes or banning cheaters

  • disable_edit_message (typing.Union[base.Boolean, None]) – Pass True, if the game message should not be automatically edited to include the current scoreboard

  • chat_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Unique identifier for the target chat

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns

On success, if the message was sent by the bot, returns the edited Message, otherwise returns True Returns an error, if the new score is not greater than the user’s current score in the chat and force is False.

Return type

typing.Union[types.Message, base.Boolean]

async get_game_high_scores(user_id: Integer, chat_id: Optional[Integer] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None) → List[aiogram.types.game_high_score.GameHighScore][source]

Use this method to get data for high score tables.

This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.

Source: https://core.telegram.org/bots/api#getgamehighscores

Parameters
  • user_id (base.Integer) – Target user id

  • chat_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Unique identifier for the target chat

  • message_id (typing.Union[base.Integer, None]) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (typing.Union[base.String, None]) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns

Will return the score of the specified user and several of his neighbors in a game On success, returns an Array of GameHighScore objects. This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them.

Return type

typing.List[types.GameHighScore]

API Helpers

aiogram.bot.api.check_token(token: str) → bool[source]

Validate BOT token

Parameters

token

Returns

aiogram.bot.api.check_result(method_name: str, content_type: str, status_code: int, body: str)[source]

Checks whether result is a valid API response. A result is considered invalid if: - The server returned an HTTP response code other than 200 - The content of the result is invalid JSON. - The method call was unsuccessful (The JSON ‘ok’ field equals False)

Parameters
  • method_name – The name of the method called

  • status_code – status code

  • content_type – content type of result

  • body – result body

Returns

The result parsed to a JSON dictionary

Raises

ApiException – if one of the above listed cases is applicable

aiogram.bot.api.guess_filename(obj)[source]

Get file name from object

Parameters

obj

Returns

aiogram.bot.api.compose_data(params=None, files=None)[source]

Prepare request data

Parameters
  • params

  • files

Returns

class aiogram.bot.api.Methods[source]

Bases: aiogram.utils.helper.Helper

Helper for Telegram API Methods listed on https://core.telegram.org/bots/api

List is updated to Bot API 4.3

static api_url(token, method)[source]

Generate API URL with included token and method name

Parameters
  • token

  • method

Returns

static file_url(token, path)[source]

Generate File URL with included token and file path

Parameters
  • token

  • path

Returns