Skip to content

Commit 5af164b

Browse files
committed
fix: correct parsing and client binding for AI message types
1 parent 30b3706 commit 5af164b

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

pyrogram/methods/messages/transcribe_audio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def transcribe_audio(
2626
chat_id: str,
2727
message_id: int,
2828
) -> "types.TranscribedAudio":
29-
"""Transcribe an audio message to text.
29+
"""Transcribe an audio or voice message to text.
3030
3131
.. include:: /_includes/usable-by/users.rst
3232
@@ -37,7 +37,7 @@ async def transcribe_audio(
3737
For a contact that exists in your Telegram address book you can use his phone number (str).
3838
3939
message_id (``int``):
40-
Identifier of the audio message.
40+
Identifier of the audio or voice message.
4141
4242
Returns:
4343
:obj:`~pyrogram.types.TranscribedAudio`: On success, the transcription result is returned.
@@ -53,4 +53,4 @@ async def transcribe_audio(
5353
)
5454
)
5555

56-
return types.TranscribedAudio._parse(r)
56+
return types.TranscribedAudio._parse(self, r)

pyrogram/types/messages_and_media/composed_message_with_ai.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ class ComposedMessageWithAI(Object):
3838
def __init__(
3939
self,
4040
*,
41+
client: "pyrogram.Client" = None,
4142
result_text: "types.FormattedText",
4243
diff_text: Optional["types.FormattedText"] = None,
4344
):
44-
super().__init__()
45+
super().__init__(client)
4546

4647
self.result_text = result_text
4748
self.diff_text = diff_text
@@ -55,6 +56,7 @@ def _parse(
5556
return None
5657

5758
return ComposedMessageWithAI(
59+
client=client,
5860
result_text=types.FormattedText._parse(
5961
client, composed_message.result_text
6062
),

pyrogram/types/messages_and_media/message_entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def write(self):
175175
args["collapsed"] = self.expandable
176176

177177
if self.old_text is None:
178-
args.pop("old_text")
178+
args.pop("old_text", None)
179179

180180
entity = self.type.value
181181

pyrogram/types/messages_and_media/transcribed_audio.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
from typing import Optional
2020

21+
import pyrogram
22+
from pyrogram import raw
23+
2124
from ..object import Object
2225

2326

@@ -44,13 +47,14 @@ class TranscribedAudio(Object):
4447
def __init__(
4548
self,
4649
*,
50+
client: "pyrogram.Client" = None,
4751
transcription_id: int,
4852
text: str,
4953
pending: Optional[bool] = None,
5054
trial_remains_num: Optional[int] = None,
5155
trial_remains_until_date: Optional[int] = None,
5256
):
53-
super().__init__()
57+
super().__init__(client)
5458

5559
self.transcription_id = transcription_id
5660
self.text = text
@@ -59,11 +63,15 @@ def __init__(
5963
self.trial_remains_until_date = trial_remains_until_date
6064

6165
@staticmethod
62-
def _parse(transcribed_audio) -> Optional["TranscribedAudio"]:
63-
if transcribed_audio is None:
66+
def _parse(
67+
client: "pyrogram.Client",
68+
transcribed_audio: "raw.types.messages.TranscribedAudio",
69+
) -> Optional["TranscribedAudio"]:
70+
if not isinstance(transcribed_audio, raw.types.messages.TranscribedAudio):
6471
return None
6572

6673
return TranscribedAudio(
74+
client=client,
6775
transcription_id=transcribed_audio.transcription_id,
6876
text=transcribed_audio.text,
6977
pending=transcribed_audio.pending,

0 commit comments

Comments
 (0)