mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 13:14:31 +03:00
Add parse_mode parameter to TelegramClient.send_message()
This commit is contained in:
parent
82cac4836c
commit
7e204632e2
|
@ -50,6 +50,8 @@ from .tl.types import (
|
||||||
UpdateNewChannelMessage, UpdateNewMessage, UpdateShortSentMessage,
|
UpdateNewChannelMessage, UpdateNewMessage, UpdateShortSentMessage,
|
||||||
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel)
|
PeerUser, InputPeerUser, InputPeerChat, InputPeerChannel)
|
||||||
from .tl.types.messages import DialogsSlice
|
from .tl.types.messages import DialogsSlice
|
||||||
|
from .extensions import markdown
|
||||||
|
|
||||||
|
|
||||||
class TelegramClient(TelegramBareClient):
|
class TelegramClient(TelegramBareClient):
|
||||||
"""Full featured TelegramClient meant to extend the basic functionality -
|
"""Full featured TelegramClient meant to extend the basic functionality -
|
||||||
|
@ -347,21 +349,39 @@ class TelegramClient(TelegramBareClient):
|
||||||
entity,
|
entity,
|
||||||
message,
|
message,
|
||||||
reply_to=None,
|
reply_to=None,
|
||||||
|
parse_mode=None,
|
||||||
link_preview=True):
|
link_preview=True):
|
||||||
"""
|
"""
|
||||||
Sends the given message to the specified entity (user/chat/channel).
|
Sends the given message to the specified entity (user/chat/channel).
|
||||||
|
|
||||||
:param str | int | User | Chat | Channel entity: To who will it be sent.
|
:param str | int | User | Chat | Channel entity:
|
||||||
:param str message: The message to be sent.
|
To who will it be sent.
|
||||||
:param int | Message reply_to: Whether to reply to a message or not.
|
:param str message:
|
||||||
:param link_preview: Should the link preview be shown?
|
The message to be sent.
|
||||||
|
:param int | Message reply_to:
|
||||||
|
Whether to reply to a message or not.
|
||||||
|
:param str parse_mode:
|
||||||
|
Can be 'md' or 'markdown' for markdown-like parsing, in a similar
|
||||||
|
fashion how official clients work.
|
||||||
|
:param link_preview:
|
||||||
|
Should the link preview be shown?
|
||||||
|
|
||||||
:return Message: the sent message
|
:return Message: the sent message
|
||||||
"""
|
"""
|
||||||
entity = self.get_input_entity(entity)
|
entity = self.get_input_entity(entity)
|
||||||
|
if parse_mode:
|
||||||
|
parse_mode = parse_mode.lower()
|
||||||
|
if parse_mode in {'md', 'markdown'}:
|
||||||
|
message, msg_entities = markdown.parse_tg(message)
|
||||||
|
else:
|
||||||
|
raise ValueError('Unknown parsing mode', parse_mode)
|
||||||
|
else:
|
||||||
|
msg_entities = []
|
||||||
|
|
||||||
request = SendMessageRequest(
|
request = SendMessageRequest(
|
||||||
peer=entity,
|
peer=entity,
|
||||||
message=message,
|
message=message,
|
||||||
entities=[],
|
entities=msg_entities,
|
||||||
no_webpage=not link_preview,
|
no_webpage=not link_preview,
|
||||||
reply_to_msg_id=self._get_reply_to(reply_to)
|
reply_to_msg_id=self._get_reply_to(reply_to)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user