mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-25 19:38:31 +00:00
Add InlineQueryResultCachedPhoto
This commit is contained in:
parent
d209074e44
commit
c0dc882f2c
@ -22,6 +22,7 @@ from .inline_query_result import InlineQueryResult
|
|||||||
from .inline_query_result_animation import InlineQueryResultAnimation
|
from .inline_query_result_animation import InlineQueryResultAnimation
|
||||||
from .inline_query_result_article import InlineQueryResultArticle
|
from .inline_query_result_article import InlineQueryResultArticle
|
||||||
from .inline_query_result_audio import InlineQueryResultAudio
|
from .inline_query_result_audio import InlineQueryResultAudio
|
||||||
|
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
|
||||||
from .inline_query_result_contact import InlineQueryResultContact
|
from .inline_query_result_contact import InlineQueryResultContact
|
||||||
from .inline_query_result_document import InlineQueryResultDocument
|
from .inline_query_result_document import InlineQueryResultDocument
|
||||||
from .inline_query_result_location import InlineQueryResultLocation
|
from .inline_query_result_location import InlineQueryResultLocation
|
||||||
@ -34,5 +35,5 @@ __all__ = [
|
|||||||
"InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
|
"InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
|
||||||
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
|
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
|
||||||
"InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation",
|
"InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation",
|
||||||
"InlineQueryResultVenue"
|
"InlineQueryResultVenue", "InlineQueryResultCachedPhoto"
|
||||||
]
|
]
|
||||||
|
111
pyrogram/types/inline_mode/inline_query_result_cached_photo.py
Normal file
111
pyrogram/types/inline_mode/inline_query_result_cached_photo.py
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||||
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
#
|
||||||
|
# This file is part of Pyrogram.
|
||||||
|
#
|
||||||
|
# Pyrogram is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Lesser General Public License as published
|
||||||
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Pyrogram is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Lesser General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, types, utils, enums
|
||||||
|
from .inline_query_result import InlineQueryResult
|
||||||
|
from ...file_id import FileId
|
||||||
|
|
||||||
|
|
||||||
|
class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||||
|
"""A link to a photo stored on the Telegram servers.
|
||||||
|
|
||||||
|
By default, this photo will be sent by the user with an optional caption. Alternatively, you can use
|
||||||
|
*input_message_content* to send a message with the specified content instead of the photo.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
photo_file_id (``str``):
|
||||||
|
A valid file identifier of the photo.
|
||||||
|
|
||||||
|
id (``str``, *optional*):
|
||||||
|
Unique identifier for this result, 1-64 bytes.
|
||||||
|
Defaults to a randomly generated UUID4.
|
||||||
|
|
||||||
|
title (``str``, *optional*):
|
||||||
|
Title for the result.
|
||||||
|
|
||||||
|
description (``str``, *optional*):
|
||||||
|
Short description of the result.
|
||||||
|
|
||||||
|
caption (``str``, *optional*):
|
||||||
|
Caption of the photo to be sent, 0-1024 characters.
|
||||||
|
|
||||||
|
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
|
||||||
|
By default, texts are parsed using both Markdown and HTML styles.
|
||||||
|
You can combine both syntaxes together.
|
||||||
|
|
||||||
|
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
|
||||||
|
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
|
||||||
|
|
||||||
|
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||||
|
An InlineKeyboardMarkup object.
|
||||||
|
|
||||||
|
input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
|
||||||
|
Content of the message to be sent instead of the photo.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
photo_file_id: str,
|
||||||
|
id: str = None,
|
||||||
|
title: str = None,
|
||||||
|
description: str = None,
|
||||||
|
caption: str = "",
|
||||||
|
parse_mode: Optional["enums.ParseMode"] = None,
|
||||||
|
caption_entities: List["types.MessageEntity"] = None,
|
||||||
|
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||||
|
input_message_content: "types.InputMessageContent" = None
|
||||||
|
):
|
||||||
|
super().__init__("photo", id, input_message_content, reply_markup)
|
||||||
|
|
||||||
|
self.photo_file_id = photo_file_id
|
||||||
|
self.title = title
|
||||||
|
self.description = description
|
||||||
|
self.caption = caption
|
||||||
|
self.parse_mode = parse_mode
|
||||||
|
self.caption_entities = caption_entities
|
||||||
|
self.reply_markup = reply_markup
|
||||||
|
self.input_message_content = input_message_content
|
||||||
|
|
||||||
|
async def write(self, client: "pyrogram.Client"):
|
||||||
|
message, entities = (await utils.parse_text_entities(
|
||||||
|
client, self.caption, self.parse_mode, self.caption_entities
|
||||||
|
)).values()
|
||||||
|
|
||||||
|
file_id = FileId.decode(self.photo_file_id)
|
||||||
|
|
||||||
|
return raw.types.InputBotInlineResultPhoto(
|
||||||
|
id=self.id,
|
||||||
|
type=self.type,
|
||||||
|
photo=raw.types.InputPhoto(
|
||||||
|
id=file_id.media_id,
|
||||||
|
access_hash=file_id.access_hash,
|
||||||
|
file_reference=file_id.file_reference,
|
||||||
|
),
|
||||||
|
send_message=(
|
||||||
|
await self.input_message_content.write(client, self.reply_markup)
|
||||||
|
if self.input_message_content
|
||||||
|
else raw.types.InputBotInlineMessageMediaAuto(
|
||||||
|
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
|
||||||
|
message=message,
|
||||||
|
entities=entities
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
Loading…
x
Reference in New Issue
Block a user