mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Send photo
This commit is contained in:
parent
6f40b9c0cf
commit
3263a286e1
2 changed files with 68 additions and 4 deletions
|
|
@ -43,8 +43,8 @@ class AIOGramBot:
|
|||
setattr(self, '_me', await self.get_me())
|
||||
return getattr(self, '_me')
|
||||
|
||||
async def request(self, method, data=None):
|
||||
return await api.request(self.session, self.__token, method, data)
|
||||
async def request(self, method, data=None, files=None):
|
||||
return await api.request(self.session, self.__token, method, data, files)
|
||||
|
||||
async def get_me(self) -> User:
|
||||
raw = await self.request(ApiMethods.GET_ME)
|
||||
|
|
@ -110,3 +110,34 @@ class AIOGramBot:
|
|||
payload = generate_payload(**locals())
|
||||
message = await self.request(ApiMethods.FORWARD_MESSAGE, payload)
|
||||
return self.prepare_object(Message.de_json(message))
|
||||
|
||||
async def send_photo(self, chat_id, photo, caption=None, disable_notification=None, reply_to_message_id=None,
|
||||
reply_markup=None) -> Message:
|
||||
"""
|
||||
chat_id Integer or String Yes Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||
photo InputFile or String Yes Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. More info on Sending Files »
|
||||
caption String Optional Photo caption (may also be used when resending photos by file_id), 0-200 characters
|
||||
disable_notification Boolean Optional Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
|
||||
reply_to_message_id Integer Optional If the message is a reply, ID of the original message
|
||||
reply_markup InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply Optional 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.
|
||||
|
||||
:return:
|
||||
"""
|
||||
|
||||
if reply_markup and hasattr(reply_markup, 'to_json'):
|
||||
reply_markup = json.dumps(reply_markup.to_json())
|
||||
|
||||
if hasattr(reply_to_message_id, 'message_id'):
|
||||
reply_to_message_id = reply_to_message_id.message_id
|
||||
|
||||
payload = generate_payload(**locals(), exclude=['photo'])
|
||||
|
||||
if isinstance(photo, str):
|
||||
payload['photo'] = photo
|
||||
file = None
|
||||
else:
|
||||
file = photo
|
||||
|
||||
message = await self.request(ApiMethods.SEND_PHOTO, payload, {'photo': file})
|
||||
|
||||
return self.prepare_object(Message.de_json(message))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue