2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Merge branch 'develop' into asyncio

# Conflicts:
#	pyrogram/client/methods/messages/edit_message_text.py
#	pyrogram/client/methods/messages/send_animation.py
#	pyrogram/client/methods/messages/send_audio.py
#	pyrogram/client/methods/messages/send_cached_media.py
#	pyrogram/client/methods/messages/send_document.py
#	pyrogram/client/methods/messages/send_message.py
#	pyrogram/client/methods/messages/send_photo.py
#	pyrogram/client/methods/messages/send_video.py
#	pyrogram/client/methods/messages/send_voice.py
#	pyrogram/client/parser/html.py
#	pyrogram/client/parser/markdown.py
#	pyrogram/client/types/input_message_content/input_text_message_content.py
This commit is contained in:
Dan 2019-06-26 19:34:49 +02:00
commit 8ef97f2177
45 changed files with 291 additions and 1608 deletions

View File

@ -24,7 +24,7 @@ import sys
from pathlib import Path
from pyrogram import __version__
from ..style import Markdown, HTML
from ..parser import Parser
from ...session.internals import MsgId
@ -91,8 +91,7 @@ class BaseClient:
self.rnd_id = MsgId
self.markdown = Markdown(self)
self.html = HTML(self)
self.parser = Parser(self)
self.session = None
self.media_sessions = {}

View File

@ -38,8 +38,11 @@ class EditInlineCaption(BaseClient):
New caption of the media message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.

View File

@ -16,6 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
import pyrogram
from pyrogram.api import functions
from pyrogram.client.ext import BaseClient, utils
@ -26,7 +28,7 @@ class EditInlineText(BaseClient):
self,
inline_message_id: str,
text: str,
parse_mode: str = "",
parse_mode: Union[str, None] = "",
disable_web_page_preview: bool = None,
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> bool:
@ -40,8 +42,11 @@ class EditInlineText(BaseClient):
New text of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -55,13 +60,12 @@ class EditInlineText(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
style = self.html if parse_mode.lower() == "html" else self.markdown
return await self.send(
functions.messages.EditInlineBotMessage(
id=utils.unpack_inline_message_id(inline_message_id),
no_webpage=disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None,
**style.parse(text)
**self.parser.parse(text, parse_mode)
)
)

View File

@ -46,8 +46,11 @@ class EditMessageCaption(BaseClient):
New caption of the media message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.

View File

@ -29,7 +29,7 @@ class EditMessageText(BaseClient):
chat_id: Union[int, str],
message_id: int,
text: str,
parse_mode: str = "",
parse_mode: Union[str, None] = "",
disable_web_page_preview: bool = None,
reply_markup: "pyrogram.InlineKeyboardMarkup" = None
) -> "pyrogram.Message":
@ -48,8 +48,11 @@ class EditMessageText(BaseClient):
New text of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -63,7 +66,6 @@ class EditMessageText(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
style = self.html if parse_mode.lower() == "html" else self.markdown
r = await self.send(
functions.messages.EditMessage(
@ -71,7 +73,7 @@ class EditMessageText(BaseClient):
id=message_id,
no_webpage=disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(text)
**await self.parser.parse(text, parse_mode)
)
)

View File

@ -32,7 +32,7 @@ class SendAnimation(BaseClient):
animation: str,
caption: str = "",
unsave: bool = False,
parse_mode: str = "",
parse_mode: Union[str, None] = "",
duration: int = 0,
width: int = 0,
height: int = 0,
@ -70,8 +70,11 @@ class SendAnimation(BaseClient):
Pass True to automatically unsave the sent animation. Defaults to False.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of sent animation in seconds.
@ -130,7 +133,6 @@ class SendAnimation(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(animation):
@ -168,7 +170,7 @@ class SendAnimation(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -31,7 +31,7 @@ class SendAudio(BaseClient):
chat_id: Union[int, str],
audio: str,
caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
duration: int = 0,
performer: str = None,
title: str = None,
@ -66,8 +66,11 @@ class SendAudio(BaseClient):
Audio caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of the audio in seconds.
@ -126,7 +129,6 @@ class SendAudio(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(audio):
@ -162,7 +164,7 @@ class SendAudio(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -29,7 +29,7 @@ class SendCachedMedia(BaseClient):
chat_id: Union[int, str],
file_id: str,
caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup: Union[
@ -59,8 +59,11 @@ class SendCachedMedia(BaseClient):
Media caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -79,7 +82,6 @@ class SendCachedMedia(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
style = self.html if parse_mode.lower() == "html" else self.markdown
r = await self.send(
functions.messages.SendMedia(
@ -89,7 +91,7 @@ class SendCachedMedia(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)

View File

@ -31,7 +31,7 @@ class SendDocument(BaseClient):
chat_id: Union[int, str],
document: str,
thumb: str = None, caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
disable_notification: bool = None,
reply_to_message_id: int = None,
reply_markup: Union[
@ -67,8 +67,11 @@ class SendDocument(BaseClient):
Document caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -112,7 +115,6 @@ class SendDocument(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(document):
@ -143,7 +145,7 @@ class SendDocument(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -28,7 +28,7 @@ class SendMessage(BaseClient):
self,
chat_id: Union[int, str],
text: str,
parse_mode: str = "",
parse_mode: Union[str, None] = "",
disable_web_page_preview: bool = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
@ -51,8 +51,11 @@ class SendMessage(BaseClient):
Text of the message to be sent.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -74,8 +77,7 @@ class SendMessage(BaseClient):
Raises:
RPCError: In case of a Telegram RPC error.
"""
style = self.html if parse_mode.lower() == "html" else self.markdown
message, entities = (await style.parse(text)).values()
message, entities = (await self.parser.parse(text, parse_mode)).values()
r = await self.send(
functions.messages.SendMessage(

View File

@ -31,7 +31,7 @@ class SendPhoto(BaseClient):
chat_id: Union[int, str],
photo: str,
caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
ttl_seconds: int = None,
disable_notification: bool = None,
reply_to_message_id: int = None,
@ -62,8 +62,11 @@ class SendPhoto(BaseClient):
Photo caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
ttl_seconds (``int``, *optional*):
Self-Destruct Timer.
@ -112,7 +115,6 @@ class SendPhoto(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(photo):
@ -139,7 +141,7 @@ class SendPhoto(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -31,7 +31,7 @@ class SendVideo(BaseClient):
chat_id: Union[int, str],
video: str,
caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
duration: int = 0,
width: int = 0,
height: int = 0,
@ -66,8 +66,11 @@ class SendVideo(BaseClient):
Video caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of sent video in seconds.
@ -129,7 +132,6 @@ class SendVideo(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(video):
@ -166,7 +168,7 @@ class SendVideo(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -31,7 +31,7 @@ class SendVoice(BaseClient):
chat_id: Union[int, str],
voice: str,
caption: str = "",
parse_mode: str = "",
parse_mode: Union[str, None] = "",
duration: int = 0,
disable_notification: bool = None,
reply_to_message_id: int = None,
@ -62,8 +62,11 @@ class SendVoice(BaseClient):
Voice message caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of the voice message in seconds.
@ -110,7 +113,6 @@ class SendVoice(BaseClient):
RPCError: In case of a Telegram RPC error.
"""
file = None
style = self.html if parse_mode.lower() == "html" else self.markdown
try:
if os.path.exists(voice):
@ -142,7 +144,7 @@ class SendVoice(BaseClient):
reply_to_msg_id=reply_to_message_id,
random_id=self.rnd_id(),
reply_markup=reply_markup.write() if reply_markup else None,
**await style.parse(caption)
**await self.parser.parse(caption, parse_mode)
)
)
except FilePartMissing as e:

View File

@ -16,5 +16,4 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .html import HTML
from .markdown import Markdown
from .parser import Parser

View File

@ -20,6 +20,7 @@ import html
import re
from collections import OrderedDict
from html.parser import HTMLParser
from typing import Union
import pyrogram
from pyrogram.api import types
@ -103,7 +104,7 @@ class Parser(HTMLParser):
class HTML:
def __init__(self, client: "pyrogram.BaseClient" = None):
def __init__(self, client: Union["pyrogram.BaseClient", None]):
self.client = client
async def parse(self, text: str):
@ -126,7 +127,8 @@ class HTML:
for entity in parser.entities:
if isinstance(entity, types.InputMessageEntityMentionName):
try:
entity.user_id = await self.client.resolve_peer(entity.user_id)
if self.client is not None:
entity.user_id = await self.client.resolve_peer(entity.user_id)
except PeerIdInvalid:
continue
@ -135,7 +137,7 @@ class HTML:
# TODO: OrderedDict to be removed in Python 3.6
return OrderedDict([
("message", utils.remove_surrogates(parser.text)),
("entities", entities)
("entities", sorted(entities, key=lambda e: e.offset))
])
@staticmethod

View File

@ -18,6 +18,7 @@
import html
import re
from typing import Union
import pyrogram
from . import utils
@ -30,42 +31,52 @@ STRIKE_DELIM = "~~"
CODE_DELIM = "`"
PRE_DELIM = "```"
MARKDOWN_RE = re.compile(r"({d})|\[(.+?)\]\((.+?)\)".format(
d="|".join(
["".join(i) for i in [
[r"\{}".format(j) for j in i]
for i in [
PRE_DELIM,
CODE_DELIM,
STRIKE_DELIM,
UNDERLINE_DELIM,
ITALIC_DELIM,
BOLD_DELIM
]
]]
)))
OPENING_TAG = "<{}>"
CLOSING_TAG = "</{}>"
URL_MARKUP = '<a href="{}">{}</a>'
FIXED_WIDTH_DELIMS = [CODE_DELIM, PRE_DELIM]
class Markdown:
MARKDOWN_RE = re.compile(r"({d})".format(
d="|".join(
["".join(i) for i in [
[r"\{}".format(j) for j in i]
for i in [
PRE_DELIM,
CODE_DELIM,
STRIKE_DELIM,
UNDERLINE_DELIM,
ITALIC_DELIM,
BOLD_DELIM
]
]]
)))
URL_RE = re.compile(r"\[([^[]+)]\(([^(]+)\)")
OPENING_TAG = "<{}>"
CLOSING_TAG = "</{}>"
URL_MARKUP = '<a href="{}">{}</a>'
FIXED_WIDTH_DELIMS = [CODE_DELIM, PRE_DELIM]
def __init__(self, client: "pyrogram.BaseClient"):
def __init__(self, client: Union["pyrogram.BaseClient", None]):
self.html = HTML(client)
async def parse(self, text: str):
text = html.escape(text)
async def parse(self, text: str, strict: bool = False):
if strict:
text = html.escape(text)
offset = 0
delims = set()
is_fixed_width = False
for i, match in enumerate(re.finditer(Markdown.MARKDOWN_RE, text)):
start, stop = match.span()
delim = match.group(1)
for i, match in enumerate(re.finditer(MARKDOWN_RE, text)):
start, _ = match.span()
delim, text_url, url = match.groups()
full = match.group(0)
if delim in FIXED_WIDTH_DELIMS:
is_fixed_width = not is_fixed_width
if is_fixed_width and delim not in FIXED_WIDTH_DELIMS:
continue
if text_url:
text = utils.replace_once(text, full, URL_MARKUP.format(url, text_url), start)
continue
if delim == BOLD_DELIM:
tag = "b"
@ -82,32 +93,14 @@ class Markdown:
else:
continue
if delim not in Markdown.FIXED_WIDTH_DELIMS and any(x in delims for x in Markdown.FIXED_WIDTH_DELIMS):
continue
if delim not in delims:
delims.add(delim)
tag = Markdown.OPENING_TAG.format(tag)
tag = OPENING_TAG.format(tag)
else:
delims.remove(delim)
tag = Markdown.CLOSING_TAG.format(tag)
tag = CLOSING_TAG.format(tag)
text = text[:start + offset] + tag + text[stop + offset:]
offset += len(tag) - len(delim)
offset = 0
for match in re.finditer(Markdown.URL_RE, text):
start, stop = match.span()
full = match.group(0)
body, url = match.groups()
replace = Markdown.URL_MARKUP.format(url, body)
text = text[:start + offset] + replace + text[stop + offset:]
offset += len(replace) - len(full)
text = utils.replace_once(text, delim, tag, start)
return await self.html.parse(text)

View File

@ -0,0 +1,56 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from collections import OrderedDict
from typing import Union
import pyrogram
from .html import HTML
from .markdown import Markdown
class Parser:
def __init__(self, client: Union["pyrogram.BaseClient", None]):
self.html = HTML(client)
self.markdown = Markdown(client)
def parse(self, text: str, mode: str = ""):
if mode is None:
return OrderedDict([
("message", text),
("entities", [])
])
mode = mode.lower()
if mode == "":
return self.markdown.parse(text)
if mode in "markdown":
return self.markdown.parse(text, True)
if mode == "html":
return self.html.parse(text)
@staticmethod
def unparse(text: str, entities: list, is_html: bool):
if is_html:
return HTML.unparse(text, entities)
else:
return Markdown.unparse(text, entities)

View File

@ -35,3 +35,7 @@ def add_surrogates(text):
def remove_surrogates(text):
# Replace each surrogate pair with a SMP code point
return text.encode("utf-16", "surrogatepass").decode("utf-16")
def replace_once(source: str, old: str, new: str, start: int):
return source[:start] + source[start:].replace(old, new, 1)

View File

@ -189,8 +189,11 @@ class CallbackQuery(Object, Update):
New text of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -238,8 +241,11 @@ class CallbackQuery(Object, Update):
New caption of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.

View File

@ -1,72 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultAudio(Object):
"""Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
Attributes:
ID: ``0xb0700004``
Parameters:
type (``str``):
Type of the result, must be audio.
id (``str``):
Unique identifier for this result, 1-64 bytes.
audio_url (``str``):
A valid URL for the audio file.
title (``str``):
Title.
caption (``str``, optional):
Caption, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
performer (``str``, optional):
Performer.
audio_duration (``int`` ``32-bit``, optional):
Audio duration in seconds.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the audio.
"""
def __init__(self, type: str, id: str, audio_url: str, title: str, caption: str = None, parse_mode: str = None,
performer: str = None, audio_duration: int = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.audio_url = audio_url # string
self.title = title # string
self.caption = caption # flags.0?string
self.parse_mode = parse_mode # flags.1?string
self.performer = performer # flags.2?string
self.audio_duration = audio_duration # flags.3?int
self.reply_markup = reply_markup # flags.4?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.5?InputMessageContent

View File

@ -1,103 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import binascii
import struct
from pyrogram.api import types
from pyrogram.client.ext import utils, BaseClient
from pyrogram.client.style import HTML, Markdown
from pyrogram.client.types.object import Object
from pyrogram.errors import FileIdInvalid
class InlineQueryResultCachedAudio(Object):
"""Represents a link to an audio file stored on the Telegram servers.
By default, this audio file will be sent by the user. Alternatively, you can use *input_message_content* to send a
message with the specified content instead of the audio.
Parameters:
id (``str``):
Unique identifier for this result, 1-64 bytes.
audio_file_id (``str``):
A valid file identifier for the audio file.
caption (``str``, *optional*):
Caption, 0-200 characters.
parse_mode (``str``, *optional*):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in
the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, *optional*):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, *optional*):
Content of the message to be sent instead of the audio.
"""
def __init__(
self,
id: str,
audio_file_id: str,
caption: str = "",
parse_mode: str = "",
reply_markup=None,
input_message_content=None
):
self.id = id
self.audio_file_id = audio_file_id
self.caption = caption
self.parse_mode = parse_mode
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.style = HTML() if parse_mode.lower() == "html" else Markdown()
def write(self):
try:
decoded = utils.decode(self.audio_file_id)
fmt = "<iiqqqqi" if len(decoded) > 24 else "<iiqq"
unpacked = struct.unpack(fmt, decoded)
except (AssertionError, binascii.Error, struct.error):
raise FileIdInvalid from None
else:
if unpacked[0] != 9:
media_type = BaseClient.MEDIA_TYPE_ID.get(unpacked[0], None)
if media_type:
raise FileIdInvalid("The file_id belongs to a {}".format(media_type))
else:
raise FileIdInvalid("Unknown media type: {}".format(unpacked[0]))
audio = types.InputDocument(
id=unpacked[2],
access_hash=unpacked[3]
)
return types.InputBotInlineResultDocument(
id=self.id,
type="audio",
document=audio,
send_message=types.InputBotInlineMessageMediaAuto(
reply_markup=self.reply_markup.write() if self.reply_markup else None,
**self.style.parse(self.caption)
)
)

View File

@ -1,69 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedDocument(Object):
"""Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file.
Attributes:
ID: ``0xb0700015``
Parameters:
type (``str``):
Type of the result, must be document.
id (``str``):
Unique identifier for this result, 1-64 bytes.
title (``str``):
Title for the result.
document_file_id (``str``):
A valid file identifier for the file.
description (``str``, optional):
Short description of the result.
caption (``str``, optional):
Caption of the document to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the file.
"""
ID = 0xb0700015
def __init__(self, type: str, id: str, title: str, document_file_id: str, description: str = None,
caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.title = title # string
self.document_file_id = document_file_id # string
self.description = description # flags.0?string
self.caption = caption # flags.1?string
self.parse_mode = parse_mode # flags.2?string
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent

View File

@ -1,65 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedGif(Object):
"""Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation.
Attributes:
ID: ``0xb0700012``
Parameters:
type (``str``):
Type of the result, must be gif.
id (``str``):
Unique identifier for this result, 1-64 bytes.
gif_file_id (``str``):
A valid file identifier for the GIF file.
title (``str``, optional):
Title for the result.
caption (``str``, optional):
Caption of the GIF file to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the GIF animation.
"""
ID = 0xb0700012
def __init__(self, type: str, id: str, gif_file_id: str, title: str = None, caption: str = None,
parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.gif_file_id = gif_file_id # string
self.title = title # flags.0?string
self.caption = caption # flags.1?string
self.parse_mode = parse_mode # flags.2?string
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent

View File

@ -1,65 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedMpeg4Gif(Object):
"""Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
Attributes:
ID: ``0xb0700013``
Parameters:
type (``str``):
Type of the result, must be mpeg4_gif.
id (``str``):
Unique identifier for this result, 1-64 bytes.
mpeg4_file_id (``str``):
A valid file identifier for the MP4 file.
title (``str``, optional):
Title for the result.
caption (``str``, optional):
Caption of the MPEG-4 file to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the video animation.
"""
ID = 0xb0700013
def __init__(self, type: str, id: str, mpeg4_file_id: str, title: str = None, caption: str = None,
parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.mpeg4_file_id = mpeg4_file_id # string
self.title = title # flags.0?string
self.caption = caption # flags.1?string
self.parse_mode = parse_mode # flags.2?string
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent

View File

@ -1,69 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedPhoto(Object):
"""Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.
Attributes:
ID: ``0xb0700011``
Parameters:
type (``str``):
Type of the result, must be photo.
id (``str``):
Unique identifier for this result, 1-64 bytes.
photo_file_id (``str``):
A valid file identifier of the photo.
title (``str``, optional):
Title for the result.
description (``str``, optional):
Short description of the result.
caption (``str``, optional):
Caption of the photo to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the photo.
"""
ID = 0xb0700011
def __init__(self, type: str, id: str, photo_file_id: str, title: str = None, description: str = None,
caption: str = None, parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.photo_file_id = photo_file_id # string
self.title = title # flags.0?string
self.description = description # flags.1?string
self.caption = caption # flags.2?string
self.parse_mode = parse_mode # flags.3?string
self.reply_markup = reply_markup # flags.4?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.5?InputMessageContent

View File

@ -1,52 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedSticker(Object):
"""Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker.
Attributes:
ID: ``0xb0700014``
Parameters:
type (``str``):
Type of the result, must be sticker.
id (``str``):
Unique identifier for this result, 1-64 bytes.
sticker_file_id (``str``):
A valid file identifier of the sticker.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the sticker.
"""
ID = 0xb0700014
def __init__(self, type: str, id: str, sticker_file_id: str, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.sticker_file_id = sticker_file_id # string
self.reply_markup = reply_markup # flags.0?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.1?InputMessageContent

View File

@ -1,69 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedVideo(Object):
"""Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.
Attributes:
ID: ``0xb0700016``
Parameters:
type (``str``):
Type of the result, must be video.
id (``str``):
Unique identifier for this result, 1-64 bytes.
video_file_id (``str``):
A valid file identifier for the video file.
title (``str``):
Title for the result.
description (``str``, optional):
Short description of the result.
caption (``str``, optional):
Caption of the video to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the video.
"""
ID = 0xb0700016
def __init__(self, type: str, id: str, video_file_id: str, title: str, description: str = None, caption: str = None,
parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.video_file_id = video_file_id # string
self.title = title # string
self.description = description # flags.0?string
self.caption = caption # flags.1?string
self.parse_mode = parse_mode # flags.2?string
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent

View File

@ -1,65 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultCachedVoice(Object):
"""Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message.
Attributes:
ID: ``0xb0700017``
Parameters:
type (``str``):
Type of the result, must be voice.
id (``str``):
Unique identifier for this result, 1-64 bytes.
voice_file_id (``str``):
A valid file identifier for the voice message.
title (``str``):
Voice message title.
caption (``str``, optional):
Caption, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the voice message.
"""
ID = 0xb0700017
def __init__(self, type: str, id: str, voice_file_id: str, title: str, caption: str = None, parse_mode: str = None,
reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.voice_file_id = voice_file_id # string
self.title = title # string
self.caption = caption # flags.0?string
self.parse_mode = parse_mode # flags.1?string
self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.3?InputMessageContent

View File

@ -1,78 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultContact(Object):
"""Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact.
Attributes:
ID: ``0xb0700009``
Parameters:
type (``str``):
Type of the result, must be contact.
id (``str``):
Unique identifier for this result, 1-64 Bytes.
phone_number (``str``):
Contact's phone number.
first_name (``str``):
Contact's first name.
last_name (``str``, optional):
Contact's last name.
vcard (``str``, optional):
Additional data about the contact in the form of a vCard, 0-2048 bytes.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the contact.
thumb_url (``str``, optional):
Url of the thumbnail for the result.
thumb_width (``int`` ``32-bit``, optional):
Thumbnail width.
thumb_height (``int`` ``32-bit``, optional):
Thumbnail height.
"""
ID = 0xb0700009
def __init__(self, type: str, id: str, phone_number: str, first_name: str, last_name: str = None, vcard: str = None,
reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None,
thumb_height: int = None):
self.type = type # string
self.id = id # string
self.phone_number = phone_number # string
self.first_name = first_name # string
self.last_name = last_name # flags.0?string
self.vcard = vcard # flags.1?string
self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.3?InputMessageContent
self.thumb_url = thumb_url # flags.4?string
self.thumb_width = thumb_width # flags.5?int
self.thumb_height = thumb_height # flags.6?int

View File

@ -1,86 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultDocument(Object):
"""Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.
Attributes:
ID: ``0xb0700006``
Parameters:
type (``str``):
Type of the result, must be document.
id (``str``):
Unique identifier for this result, 1-64 bytes.
title (``str``):
Title for the result.
document_url (``str``, optional):
Caption of the document to be sent, 0-200 characters.
mime_type (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
caption (``str``):
A valid URL for the file.
parse_mode (``str``):
Mime type of the content of the file, either "application/pdf" or "application/zip".
description (``str``, optional):
Short description of the result.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the file.
thumb_url (``str``, optional):
URL of the thumbnail (jpeg only) for the file.
thumb_width (``int`` ``32-bit``, optional):
Thumbnail width.
thumb_height (``int`` ``32-bit``, optional):
Thumbnail height.
"""
ID = 0xb0700006
def __init__(self, type: str, id: str, title: str, document_url: str, mime_type: str, caption: str = None,
parse_mode: str = None, description: str = None, reply_markup=None, input_message_content=None,
thumb_url: str = None, thumb_width: int = None, thumb_height: int = None):
self.type = type # string
self.id = id # string
self.title = title # string
self.caption = caption # flags.0?string
self.parse_mode = parse_mode # flags.1?string
self.document_url = document_url # string
self.mime_type = mime_type # string
self.description = description # flags.2?string
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent
self.thumb_url = thumb_url # flags.5?string
self.thumb_width = thumb_width # flags.6?int
self.thumb_height = thumb_height # flags.7?int

View File

@ -1,48 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultGame(Object):
"""Represents a Game.
Attributes:
ID: ``0xb0700010``
Parameters:
type (``str``):
Type of the result, must be game.
id (``str``):
Unique identifier for this result, 1-64 bytes.
game_short_name (``str``):
Short name of the game.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
"""
ID = 0xb0700010
def __init__(self, type: str, id: str, game_short_name: str, reply_markup=None):
self.type = type # string
self.id = id # string
self.game_short_name = game_short_name # string
self.reply_markup = reply_markup # flags.0?InlineKeyboardMarkup

View File

@ -1,82 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultGif(Object):
"""Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
Attributes:
ID: ``0xb0700001``
Parameters:
type (``str``):
Type of the result, must be gif.
id (``str``):
Unique identifier for this result, 1-64 bytes.
gif_url (``str``):
A valid URL for the GIF file. File size must not exceed 1MB.
thumb_url (``str``, optional):
Width of the GIF.
gif_width (``int`` ``32-bit``, optional):
Height of the GIF.
gif_height (``int`` ``32-bit``, optional):
Duration of the GIF.
gif_duration (``int`` ``32-bit``):
URL of the static thumbnail for the result (jpeg or gif).
title (``str``, optional):
Title for the result.
caption (``str``, optional):
Caption of the GIF file to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the GIF animation.
"""
ID = 0xb0700001
def __init__(self, type: str, id: str, gif_url: str, thumb_url: str, gif_width: int = None, gif_height: int = None,
gif_duration: int = None, title: str = None, caption: str = None, parse_mode: str = None,
reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.gif_url = gif_url # string
self.gif_width = gif_width # flags.0?int
self.gif_height = gif_height # flags.1?int
self.gif_duration = gif_duration # flags.2?int
self.thumb_url = thumb_url # string
self.title = title # flags.3?string
self.caption = caption # flags.4?string
self.parse_mode = parse_mode # flags.5?string
self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.7?InputMessageContent

View File

@ -1,78 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultLocation(Object):
"""Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location.
Attributes:
ID: ``0xb0700007``
Parameters:
type (``str``):
Type of the result, must be location.
id (``str``):
Unique identifier for this result, 1-64 Bytes.
latitude (``float`` ``64-bit``):
Location latitude in degrees.
longitude (``float`` ``64-bit``):
Location longitude in degrees.
title (``str``):
Location title.
live_period (``int`` ``32-bit``, optional):
Period in seconds for which the location can be updated, should be between 60 and 86400.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the location.
thumb_url (``str``, optional):
Url of the thumbnail for the result.
thumb_width (``int`` ``32-bit``, optional):
Thumbnail width.
thumb_height (``int`` ``32-bit``, optional):
Thumbnail height.
"""
ID = 0xb0700007
def __init__(self, type: str, id: str, latitude: float, longitude: float, title: str, live_period: int = None,
reply_markup=None, input_message_content=None, thumb_url: str = None, thumb_width: int = None,
thumb_height: int = None):
self.type = type # string
self.id = id # string
self.latitude = latitude # double
self.longitude = longitude # double
self.title = title # string
self.live_period = live_period # flags.0?int
self.reply_markup = reply_markup # flags.1?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.2?InputMessageContent
self.thumb_url = thumb_url # flags.3?string
self.thumb_width = thumb_width # flags.4?int
self.thumb_height = thumb_height # flags.5?int

View File

@ -1,82 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultMpeg4Gif(Object):
"""Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
Attributes:
ID: ``0xb0700002``
Parameters:
type (``str``):
Type of the result, must be mpeg4_gif.
id (``str``):
Unique identifier for this result, 1-64 bytes.
mpeg4_url (``str``):
A valid URL for the MP4 file. File size must not exceed 1MB.
thumb_url (``str``, optional):
Video width.
mpeg4_width (``int`` ``32-bit``, optional):
Video height.
mpeg4_height (``int`` ``32-bit``, optional):
Video duration.
mpeg4_duration (``int`` ``32-bit``):
URL of the static thumbnail (jpeg or gif) for the result.
title (``str``, optional):
Title for the result.
caption (``str``, optional):
Caption of the MPEG-4 file to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.types.InlineKeyboardMarkup>`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent <pyrogram.types.InputMessageContent>`, optional):
Content of the message to be sent instead of the video animation.
"""
ID = 0xb0700002
def __init__(self, type: str, id: str, mpeg4_url: str, thumb_url: str, mpeg4_width: int = None,
mpeg4_height: int = None, mpeg4_duration: int = None, title: str = None, caption: str = None,
parse_mode: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.mpeg4_url = mpeg4_url # string
self.mpeg4_width = mpeg4_width # flags.0?int
self.mpeg4_height = mpeg4_height # flags.1?int
self.mpeg4_duration = mpeg4_duration # flags.2?int
self.thumb_url = thumb_url # string
self.title = title # flags.3?string
self.caption = caption # flags.4?string
self.parse_mode = parse_mode # flags.5?string
self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.7?InputMessageContent

View File

@ -1,126 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.api import types
from pyrogram.client.style import HTML, Markdown
from pyrogram.client.types.object import Object
class InlineQueryResultPhoto(Object):
"""Represents a link to a photo. By default, this photo will be sent by the user with optional caption.
Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.
Parameters:
id (``str``):
Unique identifier for this result, 1-64 bytes.
photo_url (``str``):
A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.
thumb_url (``str``):
URL of the thumbnail for the photo.
photo_width (``int``, *optional*):
Width of the photo.
photo_height (``int``, *optional*):
Height of the photo.
title (``str``, *optional*):
Title for the result.
description (``str``, *optional*):
Short description of the result.
caption (``str``, *optional*):
Caption of the photo to be sent, 0-200 characters.
parse_mode (``str``, *optional*):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in
the media caption.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, *optional*):
Content of the message to be sent instead of the photo.
"""
def __init__(
self,
id: str,
photo_url: str,
thumb_url: str,
photo_width: int = 0,
photo_height: int = 0,
title: str = None,
description: str = None,
caption: str = "",
parse_mode: str = "",
reply_markup=None,
input_message_content=None
):
self.id = id # string
self.photo_url = photo_url # string
self.thumb_url = thumb_url # string
self.photo_width = photo_width # flags.0?int
self.photo_height = photo_height # flags.1?int
self.title = title # flags.2?string
self.description = description # flags.3?string
self.caption = caption # flags.4?string
self.parse_mode = parse_mode # flags.5?string
self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.7?InputMessageContent
self.style = HTML() if parse_mode.lower() == "html" else Markdown()
def write(self):
return types.InputBotInlineResult(
id=self.id,
type="photo",
send_message=types.InputBotInlineMessageMediaAuto(
reply_markup=self.reply_markup.write() if self.reply_markup else None,
**self.style.parse(self.caption)
),
title=self.title,
description=self.description,
url=self.photo_url,
thumb=types.InputWebDocument(
url=self.thumb_url,
size=0,
mime_type="image/jpeg",
attributes=[
types.DocumentAttributeImageSize(
w=0,
h=0
)
]
),
content=types.InputWebDocument(
url=self.thumb_url,
size=0,
mime_type="image/jpeg",
attributes=[
types.DocumentAttributeImageSize(
w=self.photo_width,
h=self.photo_height
)
]
)
)

View File

@ -1,86 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultVenue(Object):
"""Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue.
Attributes:
ID: ``0xb0700008``
Parameters:
type (``str``):
Type of the result, must be venue.
id (``str``):
Unique identifier for this result, 1-64 Bytes.
latitude (``float`` ``64-bit``):
Latitude of the venue location in degrees.
longitude (``float`` ``64-bit``):
Longitude of the venue location in degrees.
title (``str``):
Title of the venue.
address (``str``):
Address of the venue.
foursquare_id (``str``, optional):
Foursquare identifier of the venue if known.
foursquare_type (``str``, optional):
Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".).
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the venue.
thumb_url (``str``, optional):
Url of the thumbnail for the result.
thumb_width (``int`` ``32-bit``, optional):
Thumbnail width.
thumb_height (``int`` ``32-bit``, optional):
Thumbnail height.
"""
ID = 0xb0700008
def __init__(self, type: str, id: str, latitude: float, longitude: float, title: str, address: str,
foursquare_id: str = None, foursquare_type: str = None, reply_markup=None, input_message_content=None,
thumb_url: str = None, thumb_width: int = None, thumb_height: int = None):
self.type = type # string
self.id = id # string
self.latitude = latitude # double
self.longitude = longitude # double
self.title = title # string
self.address = address # string
self.foursquare_id = foursquare_id # flags.0?string
self.foursquare_type = foursquare_type # flags.1?string
self.reply_markup = reply_markup # flags.2?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.3?InputMessageContent
self.thumb_url = thumb_url # flags.4?string
self.thumb_width = thumb_width # flags.5?int
self.thumb_height = thumb_height # flags.6?int

View File

@ -1,90 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultVideo(Object):
"""Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.
Attributes:
ID: ``0xb0700003``
Parameters:
type (``str``):
Type of the result, must be video.
id (``str``):
Unique identifier for this result, 1-64 bytes.
video_url (``str``):
A valid URL for the embedded video player or video file.
mime_type (``str``):
Mime type of the content of video url, "text/html" or "video/mp4".
thumb_url (``str``):
URL of the thumbnail (jpeg only) for the video.
title (``str``):
Title for the result.
caption (``str``, optional):
Caption of the video to be sent, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
video_width (``int`` ``32-bit``, optional):
Video width.
video_height (``int`` ``32-bit``, optional):
Video height.
video_duration (``int`` ``32-bit``, optional):
Video duration in seconds.
description (``str``, optional):
Short description of the result.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).
"""
ID = 0xb0700003
def __init__(self, type: str, id: str, video_url: str, mime_type: str, thumb_url: str, title: str,
caption: str = None, parse_mode: str = None, video_width: int = None, video_height: int = None,
video_duration: int = None, description: str = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.video_url = video_url # string
self.mime_type = mime_type # string
self.thumb_url = thumb_url # string
self.title = title # string
self.caption = caption # flags.0?string
self.parse_mode = parse_mode # flags.1?string
self.video_width = video_width # flags.2?int
self.video_height = video_height # flags.3?int
self.video_duration = video_duration # flags.4?int
self.description = description # flags.5?string
self.reply_markup = reply_markup # flags.6?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.7?InputMessageContent

View File

@ -1,69 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from pyrogram.client.types.object import Object
class InlineQueryResultVoice(Object):
"""Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message.
Attributes:
ID: ``0xb0700005``
Parameters:
type (``str``):
Type of the result, must be voice.
id (``str``):
Unique identifier for this result, 1-64 bytes.
voice_url (``str``):
A valid URL for the voice recording.
title (``str``):
Recording title.
caption (``str``, optional):
Caption, 0-200 characters.
parse_mode (``str``, optional):
Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
voice_duration (``int`` ``32-bit``, optional):
Recording duration in seconds.
reply_markup (:obj:`InlineKeyboardMarkup`, optional):
Inline keyboard attached to the message.
input_message_content (:obj:`InputMessageContent`, optional):
Content of the message to be sent instead of the voice recording.
"""
ID = 0xb0700005
def __init__(self, type: str, id: str, voice_url: str, title: str, caption: str = None, parse_mode: str = None,
voice_duration: int = None, reply_markup=None, input_message_content=None):
self.type = type # string
self.id = id # string
self.voice_url = voice_url # string
self.title = title # string
self.caption = caption # flags.0?string
self.parse_mode = parse_mode # flags.1?string
self.voice_duration = voice_duration # flags.2?int
self.reply_markup = reply_markup # flags.3?InlineKeyboardMarkup
self.input_message_content = input_message_content # flags.4?InputMessageContent

View File

@ -38,8 +38,11 @@ class InputMediaAnimation(InputMedia):
Caption of the animation to be sent, 0-1024 characters
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
width (``int``, *optional*):
Animation width.

View File

@ -40,8 +40,11 @@ class InputMediaAudio(InputMedia):
Caption of the audio to be sent, 0-1024 characters
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of the audio in seconds

View File

@ -38,8 +38,11 @@ class InputMediaDocument(InputMedia):
Caption of the document to be sent, 0-1024 characters
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
"""
__slots__ = ["thumb"]

View File

@ -34,8 +34,11 @@ class InputMediaPhoto(InputMedia):
Caption of the photo to be sent, 0-1024 characters
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
"""
__slots__ = []

View File

@ -40,8 +40,11 @@ class InputMediaVideo(InputMedia):
Caption of the video to be sent, 0-1024 characters
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
width (``int``, *optional*):
Video width.

View File

@ -16,9 +16,11 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Union
from pyrogram.api import types
from .input_message_content import InputMessageContent
from ...style import HTML, Markdown
from ...parser import Parser
class InputTextMessageContent(InputMessageContent):
@ -29,8 +31,11 @@ class InputTextMessageContent(InputMessageContent):
Text of the message to be sent, 1-4096 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline URLs
in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -38,7 +43,7 @@ class InputTextMessageContent(InputMessageContent):
__slots__ = ["message_text", "parse_mode", "disable_web_page_preview"]
def __init__(self, message_text: str, parse_mode: str = "", disable_web_page_preview: bool = None):
def __init__(self, message_text: str, parse_mode: Union[str, None] = "", disable_web_page_preview: bool = None):
super().__init__()
self.message_text = message_text
@ -49,5 +54,5 @@ class InputTextMessageContent(InputMessageContent):
return types.InputBotInlineMessageText(
no_webpage=self.disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None,
**await(HTML() if self.parse_mode.lower() == "html" else Markdown()).parse(self.message_text)
**await(Parser(None)).parse(self.message_text, self.parse_mode)
)

View File

@ -31,7 +31,7 @@ from ..object import Object
from ..update import Update
from ..user_and_chats.chat import Chat
from ..user_and_chats.user import User
from ...style import utils, Markdown, HTML
from ...parser import utils, Parser
class Str(str):
@ -47,11 +47,11 @@ class Str(str):
@property
def markdown(self):
return Markdown.unparse(self, self.entities)
return Parser.unparse(self, self.entities, False)
@property
def html(self):
return HTML.unparse(self, self.entities)
return Parser.unparse(self, self.entities, True)
def __getitem__(self, item):
return utils.remove_surrogates(utils.add_surrogates(self)[item])
@ -686,8 +686,11 @@ class Message(Object, Update):
Defaults to ``True`` in group chats and ``False`` in private chats.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -780,8 +783,11 @@ class Message(Object, Update):
Animation caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of sent animation in seconds.
@ -914,8 +920,11 @@ class Message(Object, Update):
Audio caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of the audio in seconds.
@ -1040,8 +1049,11 @@ class Message(Object, Update):
Media caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -1255,8 +1267,11 @@ class Message(Object, Update):
Document caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_notification (``bool``, *optional*):
Sends the message silently.
@ -1642,8 +1657,11 @@ class Message(Object, Update):
Photo caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
ttl_seconds (``int``, *optional*):
Self-Destruct Timer.
@ -2037,8 +2055,11 @@ class Message(Object, Update):
Video caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of sent video in seconds.
@ -2290,8 +2311,11 @@ class Message(Object, Update):
Voice message caption, 0-1024 characters.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your caption. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
duration (``int``, *optional*):
Duration of the voice message in seconds.
@ -2385,8 +2409,11 @@ class Message(Object, Update):
New text of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
@ -2439,8 +2466,11 @@ class Message(Object, Update):
New caption of the message.
parse_mode (``str``, *optional*):
Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline
URLs in your message. Defaults to "markdown".
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
Pass "markdown" to enable Markdown-style parsing only.
Pass "html" to enable HTML-style parsing only.
Pass None to completely disable style parsing.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.