Sending messages¶
Two layers, same TDLib underneath:
- Bound methods on the message —
reply_text,reply_photo, … (preferred) - Client helpers —
sendTextMessage,sendPhoto,sendAlbum,parseText
await message.reply_text("Hello", parse_mode="html")
await client.sendPhoto(
chat_id,
photo=types.InputFileLocal(path="cat.jpg"),
caption="Hi",
)
photo= (and the same on video, document, …) is an InputFile, or a str remote file id — a string is wrapped as InputFileRemote. A local file is InputFileLocal with path=. A filename string is not a local file.
Text¶
reply_text / sendTextMessage take parse_mode (html, markdown, markdownv2) or a default on the Client.
Build HTML with pytdbot.utils:
from pytdbot import utils
text = f"Hello {utils.bold(name)}"
await message.reply_text(text, parse_mode="html")
Media and albums¶
await message.reply_photo(
types.InputFileLocal(path="cat.jpg"),
caption="cat",
)
await message.reply_photo(message.remote_file_id, caption=message.caption)
await message.reply_album(
[
types.InputMessagePhoto(
photo=types.InputPhoto(photo=types.InputFileLocal(path="a.jpg")),
),
types.InputMessagePhoto(
photo=types.InputPhoto(photo=types.InputFileLocal(path="b.jpg")),
),
]
)
reply_album / sendAlbum take a list of InputMessagePhoto / InputMessageVideo / InputMessageAudio / InputMessageDocument / InputMessageAnimation — not paths.
Typing¶
action is a context manager (or await message.action("typing")).
Rich messages¶
A separate format. See Rich messages — do not mix them with ReplyMarkupInlineKeyboard unless you mean to.