Chat

class aiogram.types.chat.Chat(conf: Optional[Dict[str, Any]] = None, **kwargs: Any)[source]

Bases: aiogram.types.base.TelegramObject

This object represents a chat.

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

Deserialize object

Parameters
  • conf

  • kwargs

property mention

Get mention if a Chat has a username, or get full name if this is a Private Chat, otherwise None is returned

property shifted_id

Get shifted id of chat, e.g. for private links

For example: -1001122334455 -> 1122334455

async get_url() → String[source]

Use this method to get chat link. Private chat returns user link. Other chat types return either username link (if they are public) or invite link (if they are private). :return: link :rtype: base.String

async update_chat()[source]

User this method to update Chat data

Returns

None

async set_photo(photo: aiogram.types.input_file.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

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

Returns

Returns True on success.

Return type

base.Boolean

async delete_photo() → 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

Returns

Returns True on success.

Return type

base.Boolean

async set_title(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

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

Returns

Returns True on success.

Return type

base.Boolean

async set_description(description: String) → 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

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

Returns

Returns True on success.

Return type

base.Boolean

async kick(user_id: Integer, until_date: Optional[Union[Integer, datetime.datetime, datetime.timedelta]] = 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
  • 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(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

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

Returns

Returns True on success.

Return type

base.Boolean

async restrict(user_id: Integer, permissions: Optional[aiogram.types.chat_permissions.ChatPermissions] = None, until_date: Optional[Union[Integer, datetime.datetime, datetime.timedelta]] = 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
  • user_id (base.Integer) – Unique identifier of the target user

  • permissions (ChatPermissions) – New user permissions

  • 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(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
  • 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

async set_permissions(permissions: aiogram.types.chat_permissions.ChatPermissions) → Boolean[source]

Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights.

Returns True on success.

Parameters

permissions – New default chat permissions

Returns

True on success.

async set_administrator_custom_title(user_id: Integer, custom_title: String) → Boolean[source]

Use this method to set a custom title for an administrator in a supergroup promoted by the bot.

Returns True on success.

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

Parameters
  • user_id – Unique identifier of the target user

  • custom_title – New custom title for the administrator; 0-16 characters, emoji are not allowed

Returns

True on success.

async pin_message(message_id: Integer, disable_notification: Boolean = False) → 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
  • 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_message() → 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

Returns

Returns True on success.

Return type

base.Boolean

async leave() → Boolean[source]

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

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

Returns

Returns True on success.

Return type

base.Boolean

async get_administrators() → 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

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_members_count() → Integer[source]

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

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

Returns

Returns Int on success.

Return type

base.Integer

async get_member(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

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

Returns

Returns a ChatMember object on success.

Return type

types.ChatMember

async set_sticker_set(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

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_sticker_set() → 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

Returns

Returns True on success

Return type

base.Boolean

async do(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

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

Returns

Returns True on success.

Return type

base.Boolean

Use this method to export an invite link to 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#exportchatinvitelink

Returns

Returns exported invite link as String on success.

Return type

base.String

ChatType

class aiogram.types.chat.ChatType[source]

Bases: aiogram.utils.helper.Helper

List of chat types

Key

PRIVATE

Key

GROUP

Key

SUPER_GROUP

Key

CHANNEL

classmethod is_private(obj) → bool[source]

Check chat is private

Parameters

obj

Returns

classmethod is_group(obj) → bool[source]

Check chat is group

Parameters

obj

Returns

classmethod is_super_group(obj) → bool[source]

Check chat is super-group

Parameters

obj

Returns

classmethod is_group_or_super_group(obj) → bool[source]

Check chat is group or super-group

Parameters

obj

Returns

classmethod is_channel(obj) → bool[source]

Check chat is channel

Parameters

obj

Returns

ChatActions

class aiogram.types.chat.ChatActions[source]

Bases: aiogram.utils.helper.Helper

List of chat actions

Key

TYPING

Key

UPLOAD_PHOTO

Key

RECORD_VIDEO

Key

UPLOAD_VIDEO

Key

RECORD_AUDIO

Key

UPLOAD_AUDIO

Key

UPLOAD_DOCUMENT

Key

FIND_LOCATION

Key

RECORD_VIDEO_NOTE

Key

UPLOAD_VIDEO_NOTE

classmethod calc_timeout(text, timeout=0.8)[source]

Calculate timeout for text

Parameters
  • text

  • timeout

Returns

async classmethod typing(sleep=None)[source]

Do typing

Parameters

sleep – sleep timeout

Returns

async classmethod upload_photo(sleep=None)[source]

Do upload_photo

Parameters

sleep – sleep timeout

Returns

async classmethod record_video(sleep=None)[source]

Do record video

Parameters

sleep – sleep timeout

Returns

async classmethod upload_video(sleep=None)[source]

Do upload video

Parameters

sleep – sleep timeout

Returns

async classmethod record_audio(sleep=None)[source]

Do record audio

Parameters

sleep – sleep timeout

Returns

async classmethod upload_audio(sleep=None)[source]

Do upload audio

Parameters

sleep – sleep timeout

Returns

async classmethod upload_document(sleep=None)[source]

Do upload document

Parameters

sleep – sleep timeout

Returns

async classmethod find_location(sleep=None)[source]

Do find location

Parameters

sleep – sleep timeout

Returns

async classmethod record_video_note(sleep=None)[source]

Do record video note

Parameters

sleep – sleep timeout

Returns

async classmethod upload_video_note(sleep=None)[source]

Do upload video note

Parameters

sleep – sleep timeout

Returns