async def send_as_file( self, chat_id: Union[int, str], text: str, filename: str = "output.txt", caption: str = '', log: Union[bool, str] = False, reply_to_message_id: Optional[int] = None ) -> 'types.bound.Message': """\nYou can send large outputs as file Example: @userge.send_as_file(chat_id=12345, text="hello") Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). text (``str``): Text of the message to be sent. filename (``str``, *optional*): file_name for output file. caption (``str``, *optional*): caption for output file. log (``bool`` | ``str``, *optional*): If ``True``, the message will be forwarded to the log channel. If ``str``, the logger name will be updated. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. Returns: On success, the sent Message is returned. """ if text and chat_id not in Config.AUTH_CHATS: text = secure_text(str(text)) text = (await Parser(self).parse(text)).get("message") async with aiofiles.open(filename, "w+", encoding="utf8") as out_file: await out_file.write(text) _LOG.debug(_LOG_STR, f"Uploading {filename} To Telegram") msg = await self.send_document(chat_id=chat_id, document=filename, caption=caption[:1024], disable_notification=True, reply_to_message_id=reply_to_message_id) os.remove(filename) module = inspect.currentframe().f_back.f_globals['__name__'] if log: await self._channel.fwd_msg( msg, module if isinstance(log, bool) else log) return types.bound.Message.parse(self, msg, module=module)
async def edit_message_text(self, # pylint: disable=arguments-differ chat_id: Union[int, str], message_id: int, text: str, del_in: int = -1, log: Union[bool, str] = False, parse_mode: Union[str, object] = object, entities: List[MessageEntity] = None, disable_web_page_preview: Optional[bool] = None, reply_markup: InlineKeyboardMarkup = None ) -> Union['types.bound.Message', bool]: """\nExample: message.edit_text("hello") Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). message_id (``int``): Message identifier in the chat specified in chat_id. text (``str``): New text of the message. del_in (``int``): Time in Seconds for delete that message. log (``bool`` | ``str``, *optional*): If ``True``, the message will be forwarded to the log channel. If ``str``, the logger name will be updated. parse_mode (``str``, *optional*): By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together. Pass "markdown" or "md" to enable Markdown-style parsing only. Pass "html" to enable HTML-style parsing only. Pass None to completely disable style parsing. entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in message text, which can be specified instead of *parse_mode*. disable_web_page_preview (``bool``, *optional*): Disables link previews for links in this message. reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): An InlineKeyboardMarkup object. Returns: On success, the edited :obj:`Message` or True is returned. Raises: RPCError: In case of a Telegram RPC error. """ if text and chat_id not in Config.AUTH_CHATS: text = secure_text(str(text)) msg = await super().edit_message_text(chat_id=chat_id, message_id=message_id, text=text, parse_mode=parse_mode, entities=entities, disable_web_page_preview=disable_web_page_preview, reply_markup=reply_markup) module = inspect.currentframe().f_back.f_globals['__name__'] if log: await self._channel.fwd_msg(msg, module if isinstance(log, bool) else log) del_in = del_in or Config.MSG_DELETE_TIMEOUT if del_in > 0: await asyncio.sleep(del_in) return bool(await msg.delete()) return types.bound.Message.parse(self, msg, module=module)
async def send_message( self, # pylint: disable=arguments-differ chat_id: Union[int, str], text: str, del_in: int = -1, log: Union[bool, str] = False, parse_mode: Union[str, object] = object, entities: List[MessageEntity] = None, disable_web_page_preview: Optional[bool] = None, disable_notification: Optional[bool] = None, reply_to_message_id: Optional[int] = None, schedule_date: Optional[int] = None, reply_markup: Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply] = None ) -> Union['types.bound.Message', bool]: """\nSend text messages. Example: @userge.send_message(chat_id=12345, text='test') Parameters: chat_id (``int`` | ``str``): Unique identifier (int) or username (str) of the target chat. For your personal cloud (Saved Messages) you can simply use "me" or "self". For a contact that exists in your Telegram address book you can use his phone number (str). text (``str``): Text of the message to be sent. del_in (``int``): Time in Seconds for delete that message. log (``bool`` | ``str``, *optional*): If ``True``, the message will be forwarded to the log channel. If ``str``, the logger name will be updated. parse_mode (``str``, *optional*): By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together. Pass "markdown" or "md" to enable Markdown-style parsing only. Pass "html" to enable HTML-style parsing only. Pass None to completely disable style parsing. entities (List of :obj:`~pyrogram.types.MessageEntity`): List of special entities that appear in message text, which can be specified instead of *parse_mode*. disable_web_page_preview (``bool``, *optional*): Disables link previews for links in this message. disable_notification (``bool``, *optional*): Sends the message silently. Users will receive a notification with no sound. reply_to_message_id (``int``, *optional*): If the message is a reply, ID of the original message. schedule_date (``int``, *optional*): Date when the message will be automatically sent. Unix time. reply_markup (:obj:`InlineKeyboardMarkup` | :obj:`ReplyKeyboardMarkup` | :obj:`ReplyKeyboardRemove` | :obj:`ForceReply`, *optional*): Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. Returns: :obj:`Message`: On success, the sent text message or True is returned. """ if text and chat_id not in Config.AUTH_CHATS: text = secure_text(str(text)) msg = await super().send_message( chat_id=chat_id, text=text, parse_mode=parse_mode, entities=entities, disable_web_page_preview=disable_web_page_preview, disable_notification=disable_notification, reply_to_message_id=reply_to_message_id, schedule_date=schedule_date, reply_markup=reply_markup) module = inspect.currentframe().f_back.f_globals['__name__'] if log: await self._channel.fwd_msg( msg, module if isinstance(log, bool) else log) del_in = del_in or Config.MSG_DELETE_TIMEOUT if del_in > 0: await asyncio.sleep(del_in) return bool(await msg.delete()) return types.bound.Message.parse(self, msg, module=module)