|
| 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 List, Optional |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import enums, raw, types, utils |
| 23 | + |
| 24 | + |
| 25 | +class ComposeMessageWithAI: |
| 26 | + async def compose_message_with_ai( |
| 27 | + self: "pyrogram.Client", |
| 28 | + text: str, |
| 29 | + proofread: Optional[bool] = None, |
| 30 | + translate_to_language_code: Optional[str] = None, |
| 31 | + change_tone: Optional[str] = None, |
| 32 | + emojify: Optional[bool] = None, |
| 33 | + parse_mode: Optional["enums.ParseMode"] = None, |
| 34 | + entities: List["types.MessageEntity"] = None, |
| 35 | + ) -> "types.ComposedMessageWithAI": |
| 36 | + """Compose, rewrite or proofread a text with Telegram AI. |
| 37 | +
|
| 38 | + .. include:: /_includes/usable-by/users.rst |
| 39 | +
|
| 40 | + Parameters: |
| 41 | + text (``str``): |
| 42 | + Input text to process. |
| 43 | +
|
| 44 | + proofread (``bool``, *optional*): |
| 45 | + Whether to proofread the text. |
| 46 | +
|
| 47 | + translate_to_language_code (``str``, *optional*): |
| 48 | + Language code of the language to which the text is translated. |
| 49 | +
|
| 50 | + change_tone (``str``, *optional*): |
| 51 | + Desired output tone. |
| 52 | +
|
| 53 | + emojify (``bool``, *optional*): |
| 54 | + Whether to add emoji to the resulting text. |
| 55 | +
|
| 56 | + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): |
| 57 | + Parse mode of the text. |
| 58 | +
|
| 59 | + entities (List of :obj:`~pyrogram.types.MessageEntity`, *optional*): |
| 60 | + List of special entities that appear in the text. |
| 61 | +
|
| 62 | + Returns: |
| 63 | + :obj:`~pyrogram.types.ComposedMessageWithAI`: On success, the AI-composed message is returned. |
| 64 | +
|
| 65 | + Example: |
| 66 | + .. code-block:: python |
| 67 | +
|
| 68 | + await app.compose_message_with_ai( |
| 69 | + "hello!! can u help me rewrite this?", |
| 70 | + proofread=True, |
| 71 | + change_tone="formal" |
| 72 | + ) |
| 73 | + """ |
| 74 | + message, entities = ( |
| 75 | + await utils.parse_text_entities(self, text, parse_mode, entities) |
| 76 | + ).values() |
| 77 | + |
| 78 | + r = await self.invoke( |
| 79 | + raw.functions.messages.ComposeMessageWithAI( |
| 80 | + text=raw.types.TextWithEntities(text=message, entities=entities or []), |
| 81 | + proofread=proofread, |
| 82 | + emojify=emojify, |
| 83 | + translate_to_lang=translate_to_language_code, |
| 84 | + change_tone=change_tone, |
| 85 | + ) |
| 86 | + ) |
| 87 | + |
| 88 | + return types.ComposedMessageWithAI._parse(self, r) |
0 commit comments