mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Add InlineQueryResultContact and InlineQueryResultDocument
This commit is contained in:
parent
70d5f22e0d
commit
e3419f0f3d
@ -24,8 +24,11 @@ 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_photo import InlineQueryResultPhoto
|
from .inline_query_result_photo import InlineQueryResultPhoto
|
||||||
from .inline_query_result_video import InlineQueryResultVideo
|
from .inline_query_result_video import InlineQueryResultVideo
|
||||||
|
from .inline_query_result_contact import InlineQueryResultContact
|
||||||
|
from .inline_query_result_document import InlineQueryResultDocument
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
|
"InlineQuery", "InlineQueryResult", "InlineQueryResultArticle", "InlineQueryResultPhoto",
|
||||||
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult"
|
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
|
||||||
|
"InlineQueryResultContact", "InlineQueryResultDocument"
|
||||||
]
|
]
|
||||||
|
@ -49,8 +49,12 @@ class InlineQueryResult(Object):
|
|||||||
Pyrogram currently supports results of the following types:
|
Pyrogram currently supports results of the following types:
|
||||||
|
|
||||||
- :obj:`~pyrogram.types.InlineQueryResultArticle`
|
- :obj:`~pyrogram.types.InlineQueryResultArticle`
|
||||||
- :obj:`~pyrogram.types.InlineQueryResultPhoto`
|
- :obj:`~pyrogram.types.InlineQueryResultAudio`
|
||||||
- :obj:`~pyrogram.types.InlineQueryResultAnimation`
|
- :obj:`~pyrogram.types.InlineQueryResultAnimation`
|
||||||
|
- :obj:`~pyrogram.types.InlineQueryResultContact`
|
||||||
|
- :obj:`~pyrogram.types.InlineQueryResultDocument`
|
||||||
|
- :obj:`~pyrogram.types.InlineQueryResultPhoto`
|
||||||
|
- :obj:`~pyrogram.types.InlineQueryResultVideo`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
114
pyrogram/types/inline_mode/inline_query_result_contact.py
Normal file
114
pyrogram/types/inline_mode/inline_query_result_contact.py
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
from pyrogram import raw, types
|
||||||
|
from .inline_query_result import InlineQueryResult
|
||||||
|
|
||||||
|
|
||||||
|
class InlineQueryResultContact(InlineQueryResult):
|
||||||
|
"""Contact with a phone number
|
||||||
|
|
||||||
|
By default, this contact will be sent by the user.
|
||||||
|
Alternatively, you can use *input_message_content* to send a message with the specified content instead of the
|
||||||
|
contact.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
phone_number (``str``):
|
||||||
|
Contact's phone number.
|
||||||
|
|
||||||
|
first_name (``str``):
|
||||||
|
Contact's first name.
|
||||||
|
|
||||||
|
last_name (``str``, *optional*):
|
||||||
|
Contact's last name.
|
||||||
|
|
||||||
|
vcard (``str``, *optional*):
|
||||||
|
Additional data about the contact in the form of a `vCard <https://en.wikipedia.org/wiki/VCard>`_.
|
||||||
|
|
||||||
|
id (``str``, *optional*):
|
||||||
|
Unique identifier for this result, 1-64 bytes.
|
||||||
|
Defaults to a randomly generated UUID4.
|
||||||
|
|
||||||
|
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||||
|
Inline keyboard attached to the message.
|
||||||
|
|
||||||
|
input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*):
|
||||||
|
Content of the message to be sent instead of the contact.
|
||||||
|
|
||||||
|
thumb_url (``str``, *optional*):
|
||||||
|
Url of the thumbnail for the result.
|
||||||
|
|
||||||
|
thumb_width (``int``, *optional*):
|
||||||
|
Thumbnail width.
|
||||||
|
|
||||||
|
thumb_height (``int``, *optional*):
|
||||||
|
Thumbnail height.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
phone_number: str,
|
||||||
|
first_name: str,
|
||||||
|
last_name: str = "",
|
||||||
|
vcard: str = "",
|
||||||
|
id: str = None,
|
||||||
|
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||||
|
input_message_content: "types.InputMessageContent" = None,
|
||||||
|
thumb_url: str = None,
|
||||||
|
thumb_width: int = 0,
|
||||||
|
thumb_height: int = 0
|
||||||
|
):
|
||||||
|
super().__init__("contact", id, input_message_content, reply_markup)
|
||||||
|
|
||||||
|
self.phone_number = phone_number
|
||||||
|
self.first_name = first_name
|
||||||
|
self.last_name = last_name
|
||||||
|
self.vcard = vcard
|
||||||
|
self.thumb_url = thumb_url
|
||||||
|
self.thumb_width = thumb_width
|
||||||
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
|
async def write(self, client: "pyrogram.Client"):
|
||||||
|
return raw.types.InputBotInlineResult(
|
||||||
|
id=self.id,
|
||||||
|
type=self.type,
|
||||||
|
title=self.first_name,
|
||||||
|
send_message=(
|
||||||
|
await self.input_message_content.write(client, self.reply_markup)
|
||||||
|
if self.input_message_content
|
||||||
|
else raw.types.InputBotInlineMessageMediaContact(
|
||||||
|
phone_number=self.phone_number,
|
||||||
|
first_name=self.first_name,
|
||||||
|
last_name=self.last_name,
|
||||||
|
vcard=self.vcard,
|
||||||
|
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
|
||||||
|
)
|
||||||
|
),
|
||||||
|
thumb=raw.types.InputWebDocument(
|
||||||
|
url=self.thumb_url,
|
||||||
|
size=0,
|
||||||
|
mime_type="image/jpg",
|
||||||
|
attributes=[
|
||||||
|
raw.types.DocumentAttributeImageSize(
|
||||||
|
w=self.thumb_width,
|
||||||
|
h=self.thumb_height
|
||||||
|
)
|
||||||
|
]
|
||||||
|
) if self.thumb_url else None
|
||||||
|
)
|
145
pyrogram/types/inline_mode/inline_query_result_document.py
Normal file
145
pyrogram/types/inline_mode/inline_query_result_document.py
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
class InlineQueryResultDocument(InlineQueryResult):
|
||||||
|
"""Link to a file.
|
||||||
|
|
||||||
|
By default, this file 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 file.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
document_url (``str``):
|
||||||
|
A valid URL for the file.
|
||||||
|
|
||||||
|
title (``str``):
|
||||||
|
Title for the result.
|
||||||
|
|
||||||
|
mime_type (``str``, *optional*):
|
||||||
|
Mime type of the content of the file, either “application/pdf” or “application/zip”.
|
||||||
|
Defaults to "application/zip".
|
||||||
|
|
||||||
|
id (``str``, *optional*):
|
||||||
|
Unique identifier for this result, 1-64 bytes.
|
||||||
|
Defaults to a randomly generated UUID4.
|
||||||
|
|
||||||
|
caption (``str``, *optional*):
|
||||||
|
Caption of the video 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*.
|
||||||
|
|
||||||
|
description (``str``, *optional*):
|
||||||
|
Short description of the result.
|
||||||
|
|
||||||
|
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||||
|
Inline keyboard attached to the message.
|
||||||
|
|
||||||
|
input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
|
||||||
|
Content of the message to be sent instead of the file.
|
||||||
|
|
||||||
|
thumb_url (``str``, *optional*):
|
||||||
|
Url of the thumbnail for the result.
|
||||||
|
|
||||||
|
thumb_width (``int``, *optional*):
|
||||||
|
Thumbnail width.
|
||||||
|
|
||||||
|
thumb_height (``int``, *optional*):
|
||||||
|
Thumbnail height.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
document_url: str,
|
||||||
|
title: str,
|
||||||
|
mime_type: str = "application/zip",
|
||||||
|
id: str = None,
|
||||||
|
caption: str = "",
|
||||||
|
parse_mode: Optional["enums.ParseMode"] = None,
|
||||||
|
caption_entities: List["types.MessageEntity"] = None,
|
||||||
|
description: str = "",
|
||||||
|
reply_markup: "types.InlineKeyboardMarkup" = None,
|
||||||
|
input_message_content: "types.InputMessageContent" = None,
|
||||||
|
thumb_url: str = None,
|
||||||
|
thumb_width: int = 0,
|
||||||
|
thumb_height: int = 0
|
||||||
|
):
|
||||||
|
super().__init__("file", id, input_message_content, reply_markup)
|
||||||
|
|
||||||
|
self.document_url = document_url
|
||||||
|
self.title = title
|
||||||
|
self.mime_type = mime_type
|
||||||
|
self.caption = caption
|
||||||
|
self.parse_mode = parse_mode
|
||||||
|
self.caption_entities = caption_entities
|
||||||
|
self.description = description
|
||||||
|
self.thumb_url = thumb_url
|
||||||
|
self.thumb_width = thumb_width
|
||||||
|
self.thumb_height = thumb_height
|
||||||
|
|
||||||
|
async def write(self, client: "pyrogram.Client"):
|
||||||
|
document = raw.types.InputWebDocument(
|
||||||
|
url=self.document_url,
|
||||||
|
size=0,
|
||||||
|
mime_type=self.mime_type,
|
||||||
|
attributes=[]
|
||||||
|
)
|
||||||
|
|
||||||
|
thumb = raw.types.InputWebDocument(
|
||||||
|
url=self.thumb_url,
|
||||||
|
size=0,
|
||||||
|
mime_type="image/jpeg",
|
||||||
|
attributes=[
|
||||||
|
raw.types.DocumentAttributeImageSize(
|
||||||
|
w=self.thumb_width,
|
||||||
|
h=self.thumb_height
|
||||||
|
)
|
||||||
|
]
|
||||||
|
) if self.thumb_url else None
|
||||||
|
|
||||||
|
message, entities = (await utils.parse_text_entities(
|
||||||
|
client, self.caption, self.parse_mode, self.caption_entities
|
||||||
|
)).values()
|
||||||
|
|
||||||
|
return raw.types.InputBotInlineResult(
|
||||||
|
id=self.id,
|
||||||
|
type=self.type,
|
||||||
|
title=self.title,
|
||||||
|
description=self.description,
|
||||||
|
thumb=thumb,
|
||||||
|
content=document,
|
||||||
|
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