Merge pull request #294 from aiogram/dev-2.x-api-4.7

Updated API 4.7 for dev-2.x branch
This commit is contained in:
Alex Root Junior 2020-04-07 00:41:27 +03:00 committed by GitHub
commit a565251d4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 300 additions and 133 deletions

View file

@ -181,6 +181,7 @@ class Methods(Helper):
SEND_VENUE = Item() # sendVenue
SEND_CONTACT = Item() # sendContact
SEND_POLL = Item() # sendPoll
SEND_DICE = Item() # sendDice
SEND_CHAT_ACTION = Item() # sendChatAction
GET_USER_PROFILE_PHOTOS = Item() # getUserProfilePhotos
GET_FILE = Item() # getFile
@ -205,6 +206,8 @@ class Methods(Helper):
SET_CHAT_STICKER_SET = Item() # setChatStickerSet
DELETE_CHAT_STICKER_SET = Item() # deleteChatStickerSet
ANSWER_CALLBACK_QUERY = Item() # answerCallbackQuery
SET_MY_COMMANDS = Item() # setMyCommands
GET_MY_COMMANDS = Item() # getMyCommands
# Updating messages
EDIT_MESSAGE_TEXT = Item() # editMessageText
@ -222,6 +225,7 @@ class Methods(Helper):
ADD_STICKER_TO_SET = Item() # addStickerToSet
SET_STICKER_POSITION_IN_SET = Item() # setStickerPositionInSet
DELETE_STICKER_FROM_SET = Item() # deleteStickerFromSet
SET_STICKER_SET_THUMB = Item() # setStickerSetThumb
# Inline mode
ANSWER_INLINE_QUERY = Item() # answerInlineQuery

View file

@ -916,6 +916,41 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.SEND_POLL, payload)
return types.Message(**result)
async def send_dice(self, chat_id: typing.Union[base.Integer, base.String],
disable_notification: typing.Union[base.Boolean, None] = None,
reply_to_message_id: typing.Union[base.Integer, None] = None,
reply_markup: typing.Union[types.InlineKeyboardMarkup,
types.ReplyKeyboardMarkup,
types.ReplyKeyboardRemove,
types.ForceReply, None] = None) -> types.Message:
"""
Use this method to send a dice, which will have a random value from 1 to 6.
On success, the sent Message is returned.
(Yes, we're aware of the “proper” singular of die.
But it's awkward, and we decided to help it change. One dice at a time!)
Source: https://core.telegram.org/bots/api#senddice
:param chat_id: Unique identifier for the target chat or username of the target channel
:type chat_id: :obj:`typing.Union[base.Integer, base.String]`
:param disable_notification: Sends the message silently. Users will receive a notification with no sound
:type disable_notification: :obj:`typing.Union[base.Boolean, None]`
:param reply_to_message_id: If the message is a reply, ID of the original message
:type reply_to_message_id: :obj:`typing.Union[base.Integer, None]`
:param reply_markup: 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
:type reply_markup: :obj:`typing.Union[types.InlineKeyboardMarkup,
types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, None]`
:return: On success, the sent Message is returned
:rtype: :obj:`types.Message`
"""
reply_markup = prepare_arg(reply_markup)
payload = generate_payload(**locals())
result = await self.request(api.Methods.SEND_DICE, payload)
return types.Message(**result)
async def send_chat_action(self, chat_id: typing.Union[base.Integer, base.String],
action: base.String) -> base.Boolean:
"""
@ -1136,8 +1171,9 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.PROMOTE_CHAT_MEMBER, payload)
return result
async def set_chat_administrator_custom_title(self, chat_id: typing.Union[base.Integer, base.String], user_id: base.Integer, custom_title: base.String) -> base.Boolean:
async def set_chat_administrator_custom_title(self, chat_id: typing.Union[base.Integer, base.String],
user_id: base.Integer, custom_title: base.String) -> base.Boolean:
"""
Use this method to set a custom title for an administrator in a supergroup promoted by the bot.
@ -1486,6 +1522,37 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.ANSWER_CALLBACK_QUERY, payload)
return result
async def set_my_commands(self, commands: typing.List[types.BotCommand]) -> base.Boolean:
"""
Use this method to change the list of the bot's commands.
Source: https://core.telegram.org/bots/api#setmycommands
:param commands: A JSON-serialized list of bot commands to be set as the list of the bot's commands.
At most 100 commands can be specified.
:type commands: :obj: `typing.List[types.BotCommand]`
:return: Returns True on success.
:rtype: :obj:`base.Boolean`
"""
commands = prepare_arg(commands)
payload = generate_payload(**locals())
result = await self.request(api.Methods.SET_MY_COMMANDS, payload)
return result
async def get_my_commands(self) -> typing.List[types.BotCommand]:
"""
Use this method to get the current list of the bot's commands.
Source: https://core.telegram.org/bots/api#getmycommands
:return: Returns Array of BotCommand on success.
:rtype: :obj:`typing.List[types.BotCommand]`
"""
payload = generate_payload(**locals())
result = await self.request(api.Methods.GET_MY_COMMANDS, payload)
return [types.BotCommand(**bot_command_data) for bot_command_data in result]
async def edit_message_text(self, text: base.String,
chat_id: typing.Union[base.Integer, base.String, None] = None,
message_id: typing.Union[base.Integer, None] = None,
@ -1772,24 +1839,40 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.UPLOAD_STICKER_FILE, payload, files)
return types.File(**result)
async def create_new_sticker_set(self, user_id: base.Integer, name: base.String, title: base.String,
png_sticker: typing.Union[base.InputFile, base.String], emojis: base.String,
async def create_new_sticker_set(self,
user_id: base.Integer,
name: base.String,
title: base.String,
emojis: base.String,
png_sticker: typing.Union[base.InputFile, base.String] = None,
tgs_sticker: base.InputFile = None,
contains_masks: typing.Union[base.Boolean, None] = None,
mask_position: typing.Union[types.MaskPosition, None] = None) -> base.Boolean:
"""
Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set.
Use this method to create a new sticker set owned by a user.
The bot will be able to edit the sticker set thus created.
You must use exactly one of the fields png_sticker or tgs_sticker.
Source: https://core.telegram.org/bots/api#createnewstickerset
:param user_id: User identifier of created sticker set owner
:type user_id: :obj:`base.Integer`
:param name: Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals)
:param name: Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals).
Can contain only english letters, digits and underscores.
Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”.
<bot_username> is case insensitive. 1-64 characters.
:type name: :obj:`base.String`
:param title: Sticker set title, 1-64 characters
:type title: :obj:`base.String`
:param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size,
:param png_sticker: 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.
Pass a file_id as a String to send a file that already exists on the Telegram servers,
pass an HTTP URL as a String for Telegram to get a file from the Internet, or
upload a new one using multipart/form-data. More info on https://core.telegram.org/bots/api#sending-files
:type png_sticker: :obj:`typing.Union[base.InputFile, base.String]`
:param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
:type tgs_sticker: :obj:`base.InputFile`
:param emojis: One or more emoji corresponding to the sticker
:type emojis: :obj:`base.String`
:param contains_masks: Pass True, if a set of mask stickers should be created
@ -1800,19 +1883,28 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
:rtype: :obj:`base.Boolean`
"""
mask_position = prepare_arg(mask_position)
payload = generate_payload(**locals(), exclude=['png_sticker'])
payload = generate_payload(**locals(), exclude=['png_sticker', 'tgs_sticker'])
files = {}
prepare_file(payload, files, 'png_sticker', png_sticker)
prepare_file(payload, files, 'tgs_sticker', tgs_sticker)
result = await self.request(api.Methods.CREATE_NEW_STICKER_SET, payload, files)
return result
async def add_sticker_to_set(self, user_id: base.Integer, name: base.String,
png_sticker: typing.Union[base.InputFile, base.String], emojis: base.String,
async def add_sticker_to_set(self,
user_id: base.Integer,
name: base.String,
emojis: base.String,
png_sticker: typing.Union[base.InputFile, base.String] = None,
tgs_sticker: base.InputFile = None,
mask_position: typing.Union[types.MaskPosition, None] = None) -> base.Boolean:
"""
Use this method to add a new sticker to a set created by the bot.
You must use exactly one of the fields png_sticker or tgs_sticker.
Animated stickers can be added to animated sticker sets and only to them.
Animated sticker sets can have up to 50 stickers.
Static sticker sets can have up to 120 stickers.
Source: https://core.telegram.org/bots/api#addstickertoset
@ -1820,9 +1912,15 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
:type user_id: :obj:`base.Integer`
:param name: Sticker set name
:type name: :obj:`base.String`
:param png_sticker: Png image with the sticker, must be up to 512 kilobytes in size,
:param png_sticker: 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.
Pass a file_id as a String to send a file that already exists on the Telegram servers,
pass an HTTP URL as a String for Telegram to get a file from the Internet, or
upload a new one using multipart/form-data. More info on https://core.telegram.org/bots/api#sending-files
:type png_sticker: :obj:`typing.Union[base.InputFile, base.String]`
:param tgs_sticker: TGS animation with the sticker, uploaded using multipart/form-data.
See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
:type tgs_sticker: :obj:`base.InputFile`
:param emojis: One or more emoji corresponding to the sticker
:type emojis: :obj:`base.String`
:param mask_position: A JSON-serialized object for position where the mask should be placed on faces
@ -1831,10 +1929,11 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
:rtype: :obj:`base.Boolean`
"""
mask_position = prepare_arg(mask_position)
payload = generate_payload(**locals(), exclude=['png_sticker'])
payload = generate_payload(**locals(), exclude=['png_sticker', 'tgs_sticker'])
files = {}
prepare_file(payload, files, 'png_sticker', png_sticker)
prepare_file(payload, files, 'tgs_sticker', png_sticker)
result = await self.request(api.Methods.ADD_STICKER_TO_SET, payload, files)
return result
@ -1873,6 +1972,39 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.DELETE_STICKER_FROM_SET, payload)
return result
async def set_sticker_set_thumb(self,
name: base.String,
user_id: base.Integer,
thumb: typing.Union[base.InputFile, base.String] = None) -> base.Boolean:
"""
Use this method to set the thumbnail of a sticker set.
Animated thumbnails can be set for animated sticker sets only.
Source: https://core.telegram.org/bots/api#setstickersetthumb
:param name: Sticker set name
:type name: :obj:`base.String`
:param user_id: User identifier of the sticker set owner
:type user_id: :obj:`base.Integer`
:param thumb: A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height
exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size;
see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker technical
requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers,
pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using
multipart/form-data. More info on https://core.telegram.org/bots/api#sending-files.
Animated sticker set thumbnail can't be uploaded via HTTP URL.
:type thumb: :obj:`typing.Union[base.InputFile, base.String]`
:return: Returns True on success
:rtype: :obj:`base.Boolean`
"""
payload = generate_payload(**locals(), exclude=['thumb'])
files = {}
prepare_file(payload, files, 'thumb', thumb)
result = await self.request(api.Methods.SET_STICKER_SET_THUMB, payload, files)
return result
async def answer_inline_query(self, inline_query_id: base.String,
results: typing.List[types.InlineQueryResult],
cache_time: typing.Union[base.Integer, None] = None,

View file

@ -3,6 +3,7 @@ from . import fields
from .animation import Animation
from .audio import Audio
from .auth_widget_data import AuthWidgetData
from .bot_command import BotCommand
from .callback_game import CallbackGame
from .callback_query import CallbackQuery
from .chat import Chat, ChatActions, ChatType
@ -11,6 +12,7 @@ from .chat_permissions import ChatPermissions
from .chat_photo import ChatPhoto
from .chosen_inline_result import ChosenInlineResult
from .contact import Contact
from .dice import Dice
from .document import Document
from .encrypted_credentials import EncryptedCredentials
from .encrypted_passport_element import EncryptedPassportElement
@ -69,6 +71,7 @@ __all__ = (
'Animation',
'Audio',
'AuthWidgetData',
'BotCommand',
'CallbackGame',
'CallbackQuery',
'Chat',
@ -81,6 +84,7 @@ __all__ = (
'Contact',
'ContentType',
'ContentTypes',
'Dice',
'Document',
'EncryptedCredentials',
'EncryptedPassportElement',

View file

@ -0,0 +1,15 @@
from . import base
from . import fields
class BotCommand(base.TelegramObject):
"""
This object represents a bot command.
https://core.telegram.org/bots/api#botcommand
"""
command: base.String = fields.Field()
description: base.String = fields.Field()
def __init__(self, command: base.String, description: base.String):
super(BotCommand, self).__init__(command=command, description=description)

13
aiogram/types/dice.py Normal file
View file

@ -0,0 +1,13 @@
from . import base, fields
class Dice(base.TelegramObject):
"""
This object represents a dice with random value from 1 to 6.
(Yes, we're aware of the “proper” singular of die.
But it's awkward, and we decided to help it change. One dice at a time!)
https://core.telegram.org/bots/api#dice
"""
value: base.Integer = fields.Field()

View file

@ -10,6 +10,7 @@ from .animation import Animation
from .audio import Audio
from .chat import Chat, ChatType
from .contact import Contact
from .dice import Dice
from .document import Document
from .force_reply import ForceReply
from .game import Game
@ -70,6 +71,8 @@ class Message(base.TelegramObject):
contact: Contact = fields.Field(base=Contact)
location: Location = fields.Field(base=Location)
venue: Venue = fields.Field(base=Venue)
poll: Poll = fields.Field(base=Poll)
dice: Dice = fields.Field(base=Dice)
new_chat_members: typing.List[User] = fields.ListField(base=User)
left_chat_member: User = fields.Field(base=User)
new_chat_title: base.String = fields.Field()
@ -85,7 +88,6 @@ class Message(base.TelegramObject):
successful_payment: SuccessfulPayment = fields.Field(base=SuccessfulPayment)
connected_website: base.String = fields.Field()
passport_data: PassportData = fields.Field(base=PassportData)
poll: Poll = fields.Field(base=Poll)
reply_markup: InlineKeyboardMarkup = fields.Field(base=InlineKeyboardMarkup)
@property
@ -117,6 +119,10 @@ class Message(base.TelegramObject):
return ContentType.VENUE
if self.location:
return ContentType.LOCATION
if self.poll:
return ContentType.POLL
if self.dice:
return ContentType.DICE
if self.new_chat_members:
return ContentType.NEW_CHAT_MEMBERS
if self.left_chat_member:
@ -143,8 +149,7 @@ class Message(base.TelegramObject):
return ContentType.GROUP_CHAT_CREATED
if self.passport_data:
return ContentType.PASSPORT_DATA
if self.poll:
return ContentType.POLL
return ContentType.UNKNOWN
@ -1685,6 +1690,8 @@ class ContentType(helper.Helper):
CONTACT = helper.Item() # contact
LOCATION = helper.Item() # location
VENUE = helper.Item() # venue
POLL = helper.Item() # poll
DICE = helper.Item() # dice
NEW_CHAT_MEMBERS = helper.Item() # new_chat_member
LEFT_CHAT_MEMBER = helper.Item() # left_chat_member
INVOICE = helper.Item() # invoice
@ -1698,7 +1705,6 @@ class ContentType(helper.Helper):
DELETE_CHAT_PHOTO = helper.Item() # delete_chat_photo
GROUP_CHAT_CREATED = helper.Item() # group_chat_created
PASSPORT_DATA = helper.Item() # passport_data
POLL = helper.Item()
UNKNOWN = helper.Item() # unknown
ANY = helper.Item() # any

View file

@ -2,6 +2,7 @@ import typing
from . import base
from . import fields
from .photo_size import PhotoSize
from .sticker import Sticker
@ -16,3 +17,4 @@ class StickerSet(base.TelegramObject):
is_animated: base.Boolean = fields.Field()
contains_masks: base.Boolean = fields.Field()
stickers: typing.List[Sticker] = fields.ListField(base=Sticker)
thumb: PhotoSize = fields.Field(base=PhotoSize)