Chat¶
-
class
aiogram.types.chat.Chat(conf=None, **kwargs)[source]¶ Bases:
aiogram.types.base.TelegramObjectThis 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
-
async
get_url()[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)[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()[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)[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)[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[Integer] = None)[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 useruntil_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)[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[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
user_id (
base.Integer) – Unique identifier of the target userpermissions (
ChatPermissions) – New user permissionsuntil_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 venuescan_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_messagescan_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_messagescan_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 usercan_change_info (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can change chat title, photo and other settingscan_post_messages (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can create channel posts, channels onlycan_edit_messages (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can edit messages of other users, channels onlycan_delete_messages (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can delete messages of other userscan_invite_users (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can invite new users to the chatcan_restrict_members (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can restrict, ban or unban chat memberscan_pin_messages (
typing.Union[base.Boolean, None]) – Pass True, if the administrator can pin messages, supergroups onlycan_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
pin_message(message_id: int, disable_notification: bool = False)[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 pindisable_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()[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()[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()[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()[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)[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
do(action)[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
-
async
export_invite_link()[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
ChatType¶
ChatActions¶
-
class
aiogram.types.chat.ChatActions[source]¶ Bases:
aiogram.utils.helper.HelperList 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
-
classmethod
upload_photo(sleep=None)[source]¶ Do upload_photo
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
record_video(sleep=None)[source]¶ Do record video
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
upload_video(sleep=None)[source]¶ Do upload video
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
record_audio(sleep=None)[source]¶ Do record audio
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
upload_audio(sleep=None)[source]¶ Do upload audio
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
upload_document(sleep=None)[source]¶ Do upload document
- Parameters
sleep – sleep timeout
- Returns
-
classmethod
find_location(sleep=None)[source]¶ Do find location
- Parameters
sleep – sleep timeout
- Returns