Skip to content

Commit 8e8972d

Browse files
committed
Add InlineQueryResultCachedVoice
1 parent b2643e9 commit 8e8972d

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

pyrogram/types/inline_mode/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .inline_query_result_cached_photo import InlineQueryResultCachedPhoto
2828
from .inline_query_result_cached_sticker import InlineQueryResultCachedSticker
2929
from .inline_query_result_cached_video import InlineQueryResultCachedVideo
30+
from .inline_query_result_cached_voice import InlineQueryResultCachedVoice
3031
from .inline_query_result_contact import InlineQueryResultContact
3132
from .inline_query_result_document import InlineQueryResultDocument
3233
from .inline_query_result_location import InlineQueryResultLocation
@@ -40,5 +41,6 @@
4041
"InlineQueryResultAnimation", "InlineQueryResultAudio", "InlineQueryResultVideo", "ChosenInlineResult",
4142
"InlineQueryResultContact", "InlineQueryResultDocument", "InlineQueryResultVoice", "InlineQueryResultLocation",
4243
"InlineQueryResultVenue", "InlineQueryResultCachedPhoto", "InlineQueryResultCachedAnimation",
43-
"InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo"
44+
"InlineQueryResultCachedSticker", "InlineQueryResultCachedDocument", "InlineQueryResultCachedVideo",
45+
"InlineQueryResultCachedVoice"
4446
]
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Optional, List
20+
21+
import pyrogram
22+
from pyrogram import raw, types, utils, enums
23+
from .inline_query_result import InlineQueryResult
24+
from ...file_id import FileId
25+
26+
27+
class InlineQueryResultCachedVoice(InlineQueryResult):
28+
"""A link to a voice message stored on the Telegram servers.
29+
30+
By default, this voice message will be sent by the user.
31+
Alternatively, you can use *input_message_content* to send a message with the specified content instead of the voice
32+
message.
33+
34+
Parameters:
35+
voice_file_id (``str``):
36+
A valid file identifier for the voice message.
37+
38+
id (``str``, *optional*):
39+
Unique identifier for this result, 1-64 bytes.
40+
Defaults to a randomly generated UUID4.
41+
42+
title (``str``, *optional*):
43+
Title for the result.
44+
45+
caption (``str``, *optional*):
46+
Caption of the photo to be sent, 0-1024 characters.
47+
48+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
49+
By default, texts are parsed using both Markdown and HTML styles.
50+
You can combine both syntaxes together.
51+
52+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
53+
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
54+
55+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
56+
An InlineKeyboardMarkup object.
57+
58+
input_message_content (:obj:`~pyrogram.types.InputMessageContent`):
59+
Content of the message to be sent instead of the photo.
60+
"""
61+
62+
def __init__(
63+
self,
64+
voice_file_id: str,
65+
id: str = None,
66+
title: str = None,
67+
caption: str = "",
68+
parse_mode: Optional["enums.ParseMode"] = None,
69+
caption_entities: List["types.MessageEntity"] = None,
70+
reply_markup: "types.InlineKeyboardMarkup" = None,
71+
input_message_content: "types.InputMessageContent" = None
72+
):
73+
super().__init__("voice", id, input_message_content, reply_markup)
74+
75+
self.voice_file_id = voice_file_id
76+
self.title = title
77+
self.caption = caption
78+
self.parse_mode = parse_mode
79+
self.caption_entities = caption_entities
80+
self.reply_markup = reply_markup
81+
self.input_message_content = input_message_content
82+
83+
async def write(self, client: "pyrogram.Client"):
84+
message, entities = (await utils.parse_text_entities(
85+
client, self.caption, self.parse_mode, self.caption_entities
86+
)).values()
87+
88+
file_id = FileId.decode(self.voice_file_id)
89+
90+
return raw.types.InputBotInlineResultDocument(
91+
id=self.id,
92+
type=self.type,
93+
title=self.title,
94+
document=raw.types.InputDocument(
95+
id=file_id.media_id,
96+
access_hash=file_id.access_hash,
97+
file_reference=file_id.file_reference,
98+
),
99+
send_message=(
100+
await self.input_message_content.write(client, self.reply_markup)
101+
if self.input_message_content
102+
else raw.types.InputBotInlineMessageMediaAuto(
103+
reply_markup=await self.reply_markup.write(client) if self.reply_markup else None,
104+
message=message,
105+
entities=entities
106+
)
107+
)
108+
)

0 commit comments

Comments
 (0)