Chat
- class aiogram.types.chat.Chat(conf: Optional[Dict[str, Any]] = None, **kwargs: Any)[source]
Bases:
TelegramObject
This object represents a chat.
https://core.telegram.org/bots/api#chat
Deserialize object
- Parameters
conf –
kwargs –
- property mention: Optional[String]
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: int
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 set_photo(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
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.Optional[base.String]
) – 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, timedelta]] = None, revoke_messages: Optional[Boolean] = 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 chat 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.
Source: https://core.telegram.org/bots/api#kickchatmember
- Parameters
user_id (
base.Integer
) – Unique identifier of the target useruntil_date (
typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]
) – Date when the user will be unbanned. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.revoke_messages (
typing.Optional[base.Boolean]
) – Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.
- Returns
Returns True on success
- Return type
base.Boolean
- async unban(user_id: Integer, only_if_banned: Optional[Boolean] = None) 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. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don’t want this, use the parameter only_if_banned. Returns True on success.
Source: https://core.telegram.org/bots/api#unbanchatmember
- Parameters
user_id (
base.Integer
) – Unique identifier of the target useronly_if_banned (
typing.Optional[base.Boolean]
) – Do nothing if the user is not banned
- Returns
Returns True on success.
- Return type
base.Boolean
- async restrict(user_id: Integer, permissions: Optional[ChatPermissions] = None, until_date: Optional[Union[Integer, 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 userpermissions (
ChatPermissions
) – New user permissionsuntil_date (
typing.Optional[base.Integer]
) – Date when restrictions will be lifted for the user, unix time.can_send_messages (
typing.Optional[base.Boolean]
) – Pass True, if the user can send text messages, contacts, locations and venuescan_send_media_messages (
typing.Optional[base.Boolean]
) – Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messagescan_send_other_messages (
typing.Optional[base.Boolean]
) – Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messagescan_add_web_page_previews (
typing.Optional[base.Boolean]
) – 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, is_anonymous: Optional[Boolean] = None, can_manage_chat: Optional[Boolean] = None, 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_manage_voice_chats: 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, can_manage_video_chats: Optional[Boolean] = None, can_manage_topics: 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 useris_anonymous (
typing.Optional[base.Boolean]
) – Pass True, if the administrator’s presence in the chat is hiddencan_change_info (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can change chat title, photo and other settingscan_post_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can create channel posts, channels onlycan_edit_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can edit messages of other users, channels onlycan_delete_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can delete messages of other userscan_invite_users (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can invite new users to the chatcan_restrict_members (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can restrict, ban or unban chat memberscan_pin_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can pin messages, supergroups onlycan_promote_members (
typing.Optional[base.Boolean]
) – 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: 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: Optional[Boolean] = False) Boolean [source]
Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.
Source: https://core.telegram.org/bots/api#pinchatmessage
- Parameters
message_id (
base.Integer
) – Identifier of a message to pindisable_notification (
typing.Optional[base.Boolean]
) – 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(message_id: Optional[Integer] = None) Boolean [source]
Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.
Source: https://core.telegram.org/bots/api#unpinchatmessage
- Parameters
message_id (
typing.Optional[base.Integer]
) – Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.- Returns
Returns True on success
- Return type
base.Boolean
- async unpin_all_messages()[source]
Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.
Source: https://core.telegram.org/bots/api#unpinallchatmessages
- 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[Union[ChatMemberOwner, ChatMemberAdministrator]] [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[typing.Union[types.ChatMemberOwner, types.ChatMemberAdministrator]]
- async get_member_count() Integer [source]
Use this method to get the number of members in a chat.
Source: https://core.telegram.org/bots/api#getchatmembercount
- Returns
Returns Int on success.
- Return type
base.Integer
- async get_member(user_id: Integer) 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, message_thread_id: Optional[Integer] = None) 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.message_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread; supergroups only
- Returns
Returns True on success.
- Return type
base.Boolean
- async export_invite_link() String [source]
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
- async create_invite_link(expire_date: Optional[Union[Integer, datetime, timedelta]] = None, member_limit: Optional[Integer] = None, name: Optional[String] = None, creates_join_request: Optional[Boolean] = None) ChatInviteLink [source]
Shortcut for createChatInviteLink method.
- async edit_invite_link(invite_link: String, expire_date: Optional[Union[Integer, datetime, timedelta]] = None, member_limit: Optional[Integer] = None, name: Optional[String] = None, creates_join_request: Optional[Boolean] = None) ChatInviteLink [source]
Shortcut for editChatInviteLink method.
ChatType
ChatActions
- class aiogram.types.chat.ChatActions[source]
Bases:
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 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 record_voice(sleep=None)[source]
Do record voice
- Parameters
sleep – sleep timeout
- Returns
- async classmethod upload_voice(sleep=None)[source]
Do upload voice
- 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