Merge pull request #141 from pyrogram/inline-mode

Add support for inline mode (bots)
This commit is contained in:
Dan 2019-03-22 12:15:00 +01:00 committed by GitHub
commit 149130831b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 2234 additions and 79 deletions

View File

@ -93,4 +93,6 @@ CALL_ALREADY_ACCEPTED The call is already accepted
CALL_ALREADY_DECLINED The call is already declined
PHOTO_EXT_INVALID The photo extension is invalid
EXTERNAL_URL_INVALID The external media URL is invalid
CHAT_NOT_MODIFIED The chat settings were not modified
CHAT_NOT_MODIFIED The chat settings were not modified
RESULTS_TOO_MUCH The result contains too many items
RESULT_ID_DUPLICATE The result contains items with duplicated identifiers
1 id message
93 CALL_ALREADY_DECLINED The call is already declined
94 PHOTO_EXT_INVALID The photo extension is invalid
95 EXTERNAL_URL_INVALID The external media URL is invalid
96 CHAT_NOT_MODIFIED The chat settings were not modified
97 RESULTS_TOO_MUCH The result contains too many items
98 RESULT_ID_DUPLICATE The result contains items with duplicated identifiers

View File

@ -143,6 +143,7 @@ Bots
send_game
set_game_score
get_game_high_scores
answer_inline_query
.. autoclass:: pyrogram.Client

View File

@ -66,6 +66,7 @@ Input Media
.. autosummary::
:nosignatures:
InputMedia
InputMediaPhoto
InputMediaVideo
InputMediaAudio
@ -73,6 +74,25 @@ Input Media
InputMediaDocument
InputPhoneContact
Inline Mode
------------
.. autosummary::
:nosignatures:
InlineQuery
InlineQueryResult
InlineQueryResultArticle
InputMessageContent
-------------------
.. autosummary::
:nosignatures:
InputMessageContent
InputTextMessageContent
.. User & Chats
------------
@ -196,6 +216,9 @@ Input Media
.. Input Media
-----------
.. autoclass:: InputMedia
:members:
.. autoclass:: InputMediaPhoto
:members:
@ -213,3 +236,25 @@ Input Media
.. autoclass:: InputPhoneContact
:members:
.. Inline Mode
-----------
.. autoclass:: InlineQuery
:members:
.. autoclass:: InlineQueryResult
:members:
.. autoclass:: InlineQueryResultArticle
:members:
.. InputMessageContent
-------------------
.. autoclass:: InputMessageContent
:members:
.. autoclass:: InputTextMessageContent
:members:

View File

@ -33,16 +33,19 @@ __version__ = "0.12.0.develop"
from .api.errors import Error
from .client.types import (
Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMediaPhoto,
Audio, Chat, ChatMember, ChatMembers, ChatPhoto, Contact, Document, InputMedia, InputMediaPhoto,
InputMediaVideo, InputMediaDocument, InputMediaAudio, InputMediaAnimation, InputPhoneContact,
Location, Message, MessageEntity, Dialog, Dialogs, Photo, PhotoSize, Sticker, User, UserStatus,
UserProfilePhotos, Venue, Animation, Video, VideoNote, Voice, CallbackQuery, Messages, ForceReply,
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove,
Poll, PollOption, ChatPreview, StopPropagation, ContinuePropagation, Game, CallbackGame, GameHighScore,
GameHighScores, ChatPermissions
InlineQuery, InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputTextMessageContent,
InlineKeyboardButton, InlineKeyboardMarkup, KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, Poll,
PollOption, ChatPreview, StopPropagation, ContinuePropagation, Game, CallbackGame, GameHighScore, GameHighScores,
ChatPermissions
)
from .client import (
Client, ChatAction, ParseMode, Emoji,
MessageHandler, DeletedMessagesHandler, CallbackQueryHandler,
RawUpdateHandler, DisconnectHandler, UserStatusHandler, Filters
RawUpdateHandler, DisconnectHandler, UserStatusHandler, Filters,
InlineQueryHandler
)

View File

@ -22,5 +22,6 @@ from .filters import Filters
from .handlers import (
MessageHandler, DeletedMessagesHandler,
CallbackQueryHandler, RawUpdateHandler,
DisconnectHandler, UserStatusHandler
DisconnectHandler, UserStatusHandler,
InlineQueryHandler
)

View File

@ -24,7 +24,11 @@ from threading import Thread
import pyrogram
from pyrogram.api import types
from ..handlers import CallbackQueryHandler, MessageHandler, RawUpdateHandler, UserStatusHandler, DeletedMessagesHandler
from ..ext import utils
from ..handlers import (
CallbackQueryHandler, MessageHandler, DeletedMessagesHandler,
UserStatusHandler, RawUpdateHandler, InlineQueryHandler
)
log = logging.getLogger(__name__)
@ -73,7 +77,10 @@ class Dispatcher:
(types.UpdateUserStatus,):
lambda upd, usr, cht: (
pyrogram.UserStatus._parse(self.client, upd.status, upd.user_id), UserStatusHandler
)
),
(types.UpdateBotInlineQuery,):
lambda upd, usr, cht: (pyrogram.InlineQuery._parse(self.client, upd, usr), InlineQueryHandler)
}
self.update_parsers = {key: value for key_tuple, value in self.update_parsers.items() for key in key_tuple}

View File

@ -129,3 +129,6 @@ class BaseClient:
def get_chat_members_count(self, *args, **kwargs):
pass
def answer_inline_query(self, *args, **kwargs):
pass

View File

@ -19,6 +19,7 @@
from .callback_query_handler import CallbackQueryHandler
from .deleted_messages_handler import DeletedMessagesHandler
from .disconnect_handler import DisconnectHandler
from .inline_query_handler import InlineQueryHandler
from .message_handler import MessageHandler
from .raw_update_handler import RawUpdateHandler
from .user_status_handler import UserStatusHandler

View File

@ -0,0 +1,54 @@
# 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 .handler import Handler
class InlineQueryHandler(Handler):
"""The InlineQuery handler class. Used to handle inline queries.
It is intended to be used with :meth:`add_handler() <pyrogram.Client.add_handler>`
For a nicer way to register this handler, have a look at the
:meth:`on_inline_query() <pyrogram.Client.on_inline_query>` decorator.
Args:
callback (``callable``):
Pass a function that will be called when a new InlineQuery arrives. It takes *(client, inline_query)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters <pyrogram.Filters>`):
Pass one or more filters to allow only a subset of inline queries to be passed
in your callback function.
Other parameters:
client (:obj:`Client <pyrogram.Client>`):
The Client itself, useful when you want to call other API methods inside the inline query handler.
inline_query (:obj:`InlineQuery <pyrogram.InlineQuery>`):
The received inline query.
"""
def __init__(self, callback: callable, filters=None):
super().__init__(callback, filters)
def check(self, callback_query):
return (
self.filters(callback_query)
if callable(self.filters)
else True
)

View File

@ -17,6 +17,7 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .answer_callback_query import AnswerCallbackQuery
from .answer_inline_query import AnswerInlineQuery
from .get_game_high_scores import GetGameHighScores
from .get_inline_bot_results import GetInlineBotResults
from .request_callback_answer import RequestCallbackAnswer
@ -27,6 +28,7 @@ from .set_game_score import SetGameScore
class Bots(
AnswerCallbackQuery,
AnswerInlineQuery,
GetInlineBotResults,
RequestCallbackAnswer,
SendInlineBotResult,

View File

@ -0,0 +1,91 @@
# 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 typing import List
from pyrogram.api import functions, types
from pyrogram.client.ext import BaseClient
from ...types.inline_mode import InlineQueryResult
class AnswerInlineQuery(BaseClient):
def answer_inline_query(
self,
inline_query_id: str,
results: List[InlineQueryResult],
cache_time: int = 300,
is_personal: bool = None,
next_offset: str = "",
switch_pm_text: str = "",
switch_pm_parameter: str = ""
):
"""Use this method to send answers to an inline query.
No more than 50 results per query are allowed.
Args:
inline_query_id (``str``):
Unique identifier for the answered query.
results (List of :obj:`InlineQueryResult <pyrogram.InlineQueryResult>`):
A list of results for the inline query.
cache_time (``int``, *optional*):
The maximum amount of time in seconds that the result of the inline query may be cached on the server.
Defaults to 300.
is_personal (``bool``, *optional*):
Pass True, if results may be cached on the server side only for the user that sent the query.
By default, results may be returned to any user who sends the same query.
next_offset (``str``, *optional*):
Pass the offset that a client should send in the next query with the same text to receive more results.
Pass an empty string if there are no more results or if you dont support pagination.
Offset length cant exceed 64 bytes.
switch_pm_text (``str``, *optional*):
If passed, clients will display a button with specified text that switches the user to a private chat
with the bot and sends the bot a start message with the parameter switch_pm_parameter
switch_pm_parameter (``str``, *optional*):
`Deep-linking <https://core.telegram.org/bots#deep-linking>`_ parameter for the /start message sent to
the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube
account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account"
button above the results, or even before showing any. The user presses the button, switches to a private
chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth
link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat
where they wanted to use the bot's inline capabilities.
Returns:
On success, True is returned.
"""
return self.send(
functions.messages.SetInlineBotResults(
query_id=int(inline_query_id),
results=[r.write() for r in results],
cache_time=cache_time,
gallery=None,
private=is_personal or None,
next_offset=next_offset or None,
switch_pm=types.InlineBotSwitchPM(
text=switch_pm_text,
start_param=switch_pm_parameter
) if switch_pm_text else None
)
)

View File

@ -29,8 +29,8 @@ class RequestCallbackAnswer(BaseClient):
message_id: int,
callback_data: bytes
):
"""Use this method to request a callback answer from bots. This is the equivalent of clicking an
inline button containing callback data.
"""Use this method to request a callback answer from bots.
This is the equivalent of clicking an inline button containing callback data.
Args:
chat_id (``int`` | ``str``):

View File

@ -28,8 +28,9 @@ class GetChat(BaseClient):
self,
chat_id: Union[int, str]
) -> "pyrogram.Chat":
"""Use this method to get up to date information about the chat (current name of the user for
one-on-one conversations, current username of a user, group or channel, etc.)
"""Use this method to get up to date information about the chat.
Information include current name of the user for one-on-one conversations, current username of a user, group or
channel, etc.
Args:
chat_id (``int`` | ``str``):

View File

@ -34,7 +34,7 @@ class GetDialogs(BaseClient):
limit: int = 100,
pinned_only: bool = False
) -> "pyrogram.Dialogs":
"""Use this method to get a chunk of the user's dialogs
"""Use this method to get a chunk of the user's dialogs.
You can get up to 100 dialogs at once.
For a more convenient way of getting a user's dialogs see :meth:`iter_dialogs`.

View File

@ -38,9 +38,10 @@ class RestrictChatMember(BaseClient):
can_invite_users: bool = False,
can_pin_messages: bool = False
) -> Chat:
"""Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for
this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift
restrictions from a user.
"""Use this method to restrict a user in a supergroup.
The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
Pass True for all boolean parameters to lift restrictions from a user.
Args:
chat_id (``int`` | ``str``):

View File

@ -28,7 +28,7 @@ class DeleteContacts(BaseClient):
self,
ids: List[int]
):
"""Use this method to delete contacts from your Telegram address book
"""Use this method to delete contacts from your Telegram address book.
Args:
ids (List of ``int``):

View File

@ -19,6 +19,7 @@
from .on_callback_query import OnCallbackQuery
from .on_deleted_messages import OnDeletedMessages
from .on_disconnect import OnDisconnect
from .on_inline_query import OnInlineQuery
from .on_message import OnMessage
from .on_raw_update import OnRawUpdate
from .on_user_status import OnUserStatus
@ -30,6 +31,7 @@ class Decorators(
OnCallbackQuery,
OnRawUpdate,
OnDisconnect,
OnUserStatus
OnUserStatus,
OnInlineQuery
):
pass

View File

@ -30,9 +30,8 @@ class OnCallbackQuery(BaseClient):
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling
callback queries. This does the same thing as :meth:`add_handler` using the
:class:`CallbackQueryHandler`.
"""Use this decorator to automatically register a function for handling callback queries.
This does the same thing as :meth:`add_handler` using the :class:`CallbackQueryHandler`.
.. note::
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.

View File

@ -30,9 +30,8 @@ class OnDeletedMessages(BaseClient):
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling
deleted messages. This does the same thing as :meth:`add_handler` using the
:class:`DeletedMessagesHandler`.
"""Use this decorator to automatically register a function for handling deleted messages.
This does the same thing as :meth:`add_handler` using the :class:`DeletedMessagesHandler`.
.. note::
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.

View File

@ -23,9 +23,8 @@ from ...ext import BaseClient
class OnDisconnect(BaseClient):
def on_disconnect(self=None) -> callable:
"""Use this decorator to automatically register a function for handling
disconnections. This does the same thing as :meth:`add_handler` using the
:class:`DisconnectHandler`.
"""Use this decorator to automatically register a function for handling disconnections.
This does the same thing as :meth:`add_handler` using the :class:`DisconnectHandler`.
"""
def decorator(func: callable) -> Handler:

View File

@ -0,0 +1,59 @@
# 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 typing import Tuple
import pyrogram
from pyrogram.client.filters.filter import Filter
from pyrogram.client.handlers.handler import Handler
from ...ext import BaseClient
class OnInlineQuery(BaseClient):
def on_inline_query(
self=None,
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling inline queries.
This does the same thing as :meth:`add_handler` using the :class:`InlineQueryHandler`.
Args:
filters (:obj:`Filters <pyrogram.Filters>`):
Pass one or more filters to allow only a subset of inline queries to be passed
in your function.
group (``int``, *optional*):
The group identifier, defaults to 0.
"""
def decorator(func: callable) -> Tuple[Handler, int]:
if isinstance(func, tuple):
func = func[0].callback
handler = pyrogram.InlineQueryHandler(func, filters)
if isinstance(self, Filter):
return pyrogram.InlineQueryHandler(func, self), group if filters is None else filters
if self is not None:
self.add_handler(handler, group)
return handler, group
return decorator

View File

@ -30,9 +30,8 @@ class OnMessage(BaseClient):
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling
messages. This does the same thing as :meth:`add_handler` using the
:class:`MessageHandler`.
"""Use this decorator to automatically register a function for handling messages.
This does the same thing as :meth:`add_handler` using the :class:`MessageHandler`.
.. note::
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.

View File

@ -28,9 +28,8 @@ class OnRawUpdate(BaseClient):
self=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling
raw updates. This does the same thing as :meth:`add_handler` using the
:class:`RawUpdateHandler`.
"""Use this decorator to automatically register a function for handling raw updates.
This does the same thing as :meth:`add_handler` using the :class:`RawUpdateHandler`.
.. note::
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.

View File

@ -30,9 +30,8 @@ class OnUserStatus(BaseClient):
filters=None,
group: int = 0
) -> callable:
"""Use this decorator to automatically register a function for handling
user status updates. This does the same thing as :meth:`add_handler` using the
:class:`UserStatusHandler`.
"""Use this decorator to automatically register a function for handling user status updates.
This does the same thing as :meth:`add_handler` using the :class:`UserStatusHandler`.
.. note::
This decorator will wrap your defined function in a tuple consisting of *(Handler, group)*.

View File

@ -29,7 +29,9 @@ class DeleteMessages(BaseClient):
message_ids: Iterable[int],
revoke: bool = True
) -> bool:
"""Use this method to delete messages, including service messages, with the following limitations:
"""Use this method to delete messages, including service messages.
Deleting messages have the following limitations:
- A message can only be deleted if it was sent less than 48 hours ago.
- Users can delete outgoing messages in groups and supergroups.

View File

@ -32,7 +32,7 @@ class DownloadMedia(BaseClient):
progress: callable = None,
progress_args: tuple = ()
) -> Union[str, None]:
"""Use this method to download the media from a Message.
"""Use this method to download the media from a message.
Args:
message (:obj:`Message <pyrogram.Message>` | ``str``):

View File

@ -56,7 +56,7 @@ class EditMessageMedia(BaseClient):
message_id (``int``):
Message identifier in the chat specified in chat_id.
media (:obj:`InputMediaAnimation` | :obj:`InputMediaAudio` | :obj:`InputMediaDocument` | :obj:`InputMediaPhoto` | :obj:`InputMediaVideo`)
media (:obj:`InputMedia`)
One of the InputMedia objects describing an animation, audio, document, photo or video.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):

View File

@ -49,10 +49,8 @@ class SendMediaGroup(BaseClient):
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).
media (``list``):
A list containing either :obj:`InputMediaPhoto <pyrogram.InputMediaPhoto>` or
:obj:`InputMediaVideo <pyrogram.InputMediaVideo>` objects
describing photos and videos to be sent, must include 210 items.
media (List of :obj:`InputMediaPhoto` and :obj:`InputMediaVideo`):
A list describing photos and videos to be sent, must include 210 items.
disable_notification (``bool``, *optional*):
Sends the message silently.

View File

@ -29,7 +29,7 @@ class DeleteUserProfilePhotos(BaseClient):
self,
id: Union[str, List[str]]
) -> bool:
"""Use this method to delete your own profile photos
"""Use this method to delete your own profile photos.
Args:
id (``str`` | ``list``):

View File

@ -35,8 +35,8 @@ class HTML:
HTML_RE = re.compile(r"<(\w+)(?: href=([\"'])([^<]+)\2)?>([^>]+)</\1>")
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
def __init__(self, peers_by_id):
self.peers_by_id = peers_by_id
def __init__(self, peers_by_id: dict = None):
self.peers_by_id = peers_by_id or {}
def parse(self, message: str):
entities = []

View File

@ -52,8 +52,8 @@ class Markdown:
))
MENTION_RE = re.compile(r"tg://user\?id=(\d+)")
def __init__(self, peers_by_id: dict):
self.peers_by_id = peers_by_id
def __init__(self, peers_by_id: dict = None):
self.peers_by_id = peers_by_id or {}
def parse(self, message: str):
message = utils.add_surrogates(str(message or "")).strip()

View File

@ -17,14 +17,20 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from .bots import (
CallbackQuery, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
ForceReply, InlineKeyboardButton, InlineKeyboardMarkup,
KeyboardButton, ReplyKeyboardMarkup, ReplyKeyboardRemove, CallbackGame,
GameHighScore, GameHighScores
GameHighScore, GameHighScores, CallbackQuery
)
from .inline_mode import (
InlineQuery, InlineQueryResult, InlineQueryResultArticle
)
from .input_media import (
InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto,
InputMedia, InputMediaAudio, InputPhoneContact, InputMediaVideo, InputMediaPhoto,
InputMediaDocument, InputMediaAnimation
)
from .input_message_content import (
InputMessageContent, InputTextMessageContent
)
from .messages_and_media import (
Audio, Contact, Document, Animation, Location, Photo, PhotoSize,
Sticker, Venue, Video, VideoNote, Voice, UserProfilePhotos,

View File

@ -21,8 +21,9 @@ from ..pyrogram_type import PyrogramType
class ForceReply(PyrogramType):
"""Upon receiving a message with this object, Telegram clients will display a reply interface to the user
(act as if the user has selected the bot's message and tapped 'Reply').
"""Upon receiving a message with this object, Telegram clients will display a reply interface to the user.
This acts as if the user has selected the bot's message and tapped "Reply".
This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to
sacrifice privacy mode.

View File

@ -110,21 +110,21 @@ class InlineKeyboardButton(PyrogramType):
)
def write(self):
if self.callback_data:
if self.callback_data is not None:
return KeyboardButtonCallback(text=self.text, data=self.callback_data)
if self.url:
if self.url is not None:
return KeyboardButtonUrl(text=self.text, url=self.url)
if self.switch_inline_query:
if self.switch_inline_query is not None:
return KeyboardButtonSwitchInline(text=self.text, query=self.switch_inline_query)
if self.switch_inline_query_current_chat:
if self.switch_inline_query_current_chat is not None:
return KeyboardButtonSwitchInline(
text=self.text,
query=self.switch_inline_query_current_chat,
same_peer=True
)
if self.callback_game:
if self.callback_game is not None:
return KeyboardButtonGame(text=self.text)

View File

@ -21,10 +21,9 @@ from ..pyrogram_type import PyrogramType
class ReplyKeyboardRemove(PyrogramType):
"""Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and
display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent
by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a
button (see ReplyKeyboardMarkup).
"""Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard.
By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time
keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
Args:
selective (``bool``, *optional*):

View File

@ -0,0 +1,21 @@
# 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 .inline_query import InlineQuery
from .inline_query_result import InlineQueryResult
from .inline_query_result_article import InlineQueryResultArticle

View File

@ -0,0 +1,152 @@
# 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 typing import List
import pyrogram
from pyrogram.api import types
from .inline_query_result import InlineQueryResult
from ..messages_and_media import Location
from ..pyrogram_type import PyrogramType
from ..update import Update
from ..user_and_chats import User
class InlineQuery(PyrogramType, Update):
"""This object represents an incoming inline query.
When the user sends an empty query, your bot could return some default or trending results.
Args:
id (``str``):
Unique identifier for this query.
from_user (:obj:`User <pyrogram.User>`):
Sender.
query (``str``):
Text of the query (up to 512 characters).
offset (``str``):
Offset of the results to be returned, can be controlled by the bot.
location (:obj:`Location <pyrogram.Location>`. *optional*):
Sender location, only for bots that request user location.
"""
__slots__ = ["id", "from_user", "query", "offset", "location"]
def __init__(
self,
*,
client: "pyrogram.client.ext.BaseClient",
id: str,
from_user: User,
query: str,
offset: str,
location: Location = None
):
super().__init__(client)
self._client = client
self.id = id
self.from_user = from_user
self.query = query
self.offset = offset
self.location = location
@staticmethod
def _parse(client, inline_query: types.UpdateBotInlineQuery, users: dict) -> "InlineQuery":
return InlineQuery(
id=str(inline_query.query_id),
from_user=User._parse(client, users[inline_query.user_id]),
query=inline_query.query,
offset=inline_query.offset,
location=Location(
longitude=inline_query.geo.long,
latitude=inline_query.geo.lat,
client=client
) if inline_query.geo else None,
client=client
)
def answer(
self,
results: List[InlineQueryResult],
cache_time: int = 300,
is_personal: bool = None,
next_offset: str = "",
switch_pm_text: str = "",
switch_pm_parameter: str = ""
):
"""Bound method *answer* of :obj:`InlineQuery <pyrogram.InlineQuery>`.
Use this method as a shortcut for:
.. code-block:: python
client.answer_inline_query(
inline_query.id,
results=[...]
)
Example:
.. code-block:: python
inline_query.answer([...])
Args:
results (List of :obj:`InlineQueryResult <pyrogram.InlineQueryResult>`):
A list of results for the inline query.
cache_time (``int``, *optional*):
The maximum amount of time in seconds that the result of the inline query may be cached on the server.
Defaults to 300.
is_personal (``bool``, *optional*):
Pass True, if results may be cached on the server side only for the user that sent the query.
By default, results may be returned to any user who sends the same query.
next_offset (``str``, *optional*):
Pass the offset that a client should send in the next query with the same text to receive more results.
Pass an empty string if there are no more results or if you dont support pagination.
Offset length cant exceed 64 bytes.
switch_pm_text (``str``, *optional*):
If passed, clients will display a button with specified text that switches the user to a private chat
with the bot and sends the bot a start message with the parameter switch_pm_parameter
switch_pm_parameter (``str``, *optional*):
`Deep-linking <https://core.telegram.org/bots#deep-linking>`_ parameter for the /start message sent to
the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
Example: An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube
account to adapt search results accordingly. To do this, it displays a "Connect your YouTube account"
button above the results, or even before showing any. The user presses the button, switches to a private
chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth
link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat
where they wanted to use the bot's inline capabilities.
"""
return self._client.answer_inline_query(
inline_query_id=self.id,
results=results,
cache_time=cache_time,
is_personal=is_personal,
next_offset=next_offset,
switch_pm_text=switch_pm_text,
switch_pm_parameter=switch_pm_parameter
)

View File

@ -0,0 +1,59 @@
# 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_type import PyrogramType
"""- :obj:`InlineQueryResultCachedAudio`
- :obj:`InlineQueryResultCachedDocument`
- :obj:`InlineQueryResultCachedGif`
- :obj:`InlineQueryResultCachedMpeg4Gif`
- :obj:`InlineQueryResultCachedPhoto`
- :obj:`InlineQueryResultCachedSticker`
- :obj:`InlineQueryResultCachedVideo`
- :obj:`InlineQueryResultCachedVoice`
- :obj:`InlineQueryResultAudio`
- :obj:`InlineQueryResultContact`
- :obj:`InlineQueryResultGame`
- :obj:`InlineQueryResultDocument`
- :obj:`InlineQueryResultGif`
- :obj:`InlineQueryResultLocation`
- :obj:`InlineQueryResultMpeg4Gif`
- :obj:`InlineQueryResultPhoto`
- :obj:`InlineQueryResultVenue`
- :obj:`InlineQueryResultVideo`
- :obj:`InlineQueryResultVoice`"""
class InlineQueryResult(PyrogramType):
"""This object represents one result of an inline query.
Pyrogram currently supports results of the following 20 types:
- :obj:`InlineQueryResultArticle`
"""
__slots__ = ["type", "id"]
def __init__(self, type: str, id: str):
super().__init__(None)
self.type = type
self.id = id
def write(self):
pass

View File

@ -0,0 +1,104 @@
# 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 .inline_query_result import InlineQueryResult
class InlineQueryResultArticle(InlineQueryResult):
"""Represents a link to an article or web page.
TODO: Hide url?
Args:
id (``str``):
Unique identifier for this result, 1-64 bytes.
title (``str``):
Title for the result.
input_message_content (:obj:`InputMessageContent <pyrogram.InputMessageContent>`):
Content of the message to be sent.
reply_markup (:obj:`InlineKeyboardMarkup <pyrogram.InlineKeyboardMarkup>`, *optional*):
Inline keyboard attached to the message.
url (``str``, *optional*):
URL of the result.
description (``str``, *optional*):
Short description of the result.
thumb_url (``str``, *optional*):
Url of the thumbnail for the result.
thumb_width (``int``, *optional*):
Thumbnail width.
thumb_height (``int``, *optional*):
Thumbnail height.
"""
__slots__ = [
"title", "input_message_content", "reply_markup", "url", "description", "thumb_url", "thumb_width",
"thumb_height"
]
def __init__(
self,
id: str,
title: str,
input_message_content,
reply_markup=None,
url: str = None,
description: str = None,
thumb_url: str = None,
thumb_width: int = 0,
thumb_height: int = 0
):
super().__init__("article", id)
self.title = title
self.input_message_content = input_message_content
self.reply_markup = reply_markup
self.url = url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
def write(self):
return types.InputBotInlineResult(
id=self.id,
type=self.type,
send_message=self.input_message_content.write(self.reply_markup),
title=self.title,
description=self.description,
url=self.url,
thumb=types.InputWebDocument(
url=self.thumb_url,
size=0,
mime_type="image/jpeg",
attributes=[
types.DocumentAttributeImageSize(
w=self.thumb_width,
h=self.thumb_height
)
]
) if self.thumb_url else None
)

View File

@ -0,0 +1,71 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultAudio(PyrogramType):
"""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``
Args:
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 <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, 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

@ -0,0 +1,103 @@
# 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.api.errors import FileIdInvalid
from pyrogram.client.ext import utils, BaseClient
from pyrogram.client.style import HTML, Markdown
from pyrogram.client.types.pyrogram_type import PyrogramType
class InlineQueryResultCachedAudio(PyrogramType):
"""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.
Args:
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

@ -0,0 +1,68 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedDocument(PyrogramType):
"""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``
Args:
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 <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 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

@ -0,0 +1,64 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedGif(PyrogramType):
"""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``
Args:
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 <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 = 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

@ -0,0 +1,64 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedMpeg4Gif(PyrogramType):
"""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``
Args:
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 <pyrogram.types.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

@ -0,0 +1,68 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedPhoto(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,52 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedSticker(PyrogramType):
"""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``
Args:
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 <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 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

@ -0,0 +1,68 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedVideo(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,64 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultCachedVoice(PyrogramType):
"""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``
Args:
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 <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 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

@ -0,0 +1,76 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultContact(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,84 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultDocument(PyrogramType):
"""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``
Args:
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 <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 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

@ -0,0 +1,48 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultGame(PyrogramType):
"""Represents a Game.
Attributes:
ID: ``0xb0700010``
Args:
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 <pyrogram.types.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

@ -0,0 +1,80 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultGif(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,76 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultLocation(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,80 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultMpeg4Gif(PyrogramType):
"""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``
Args:
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

@ -0,0 +1,126 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultPhoto(PyrogramType):
"""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.
Args:
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 <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.
"""
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

@ -0,0 +1,84 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultVenue(PyrogramType):
"""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``
Args:
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 <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 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

@ -0,0 +1,88 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultVideo(PyrogramType):
"""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``
Args:
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 <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. 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

@ -0,0 +1,68 @@
# 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.pyrogram_type import PyrogramType
class InlineQueryResultVoice(PyrogramType):
"""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``
Args:
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 <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 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

@ -16,16 +16,23 @@
# 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_type import PyrogramType
class InputMedia:
class InputMedia(PyrogramType):
"""This object represents the content of a media message to be sent. It should be one of:
- :obj:`InputMediaAnimation <pyrogram.InputMediaAnimation>`
- :obj:`InputMediaDocument <pyrogram.InputMediaDocument>`
- :obj:`InputMediaAudio <pyrogram.InputMediaAudio>`
- :obj:`InputMediaPhoto <pyrogram.InputMediaPhoto>`
- :obj:`InputMediaVideo <pyrogram.InputMediaVideo>`
"""
__slots__ = ["media", "caption", "parse_mode"]
def __init__(
self,
media: str,
caption: str,
parse_mode: str
):
def __init__(self, media: str, caption: str, parse_mode: str):
super().__init__(None)
self.media = media
self.caption = caption
self.parse_mode = parse_mode

View File

@ -18,9 +18,10 @@
from pyrogram.api.types import InputPhoneContact as RawInputPhoneContact
from pyrogram.session.internals import MsgId
from ..pyrogram_type import PyrogramType
class InputPhoneContact:
class InputPhoneContact(PyrogramType):
"""This object represents a Phone Contact to be added in your Telegram address book.
It is intended to be used with :meth:`add_contacts() <pyrogram.Client.add_contacts>`
@ -37,13 +38,8 @@ class InputPhoneContact:
__slots__ = []
def __init__(
self,
phone: str,
first_name: str,
last_name: str = ""
):
pass
def __init__(self, phone: str, first_name: str, last_name: str = ""):
super().__init__(None)
def __new__(cls,
phone: str,

View File

@ -0,0 +1,20 @@
# 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 .input_message_content import InputMessageContent
from .input_text_message_content import InputTextMessageContent

View File

@ -0,0 +1,37 @@
# 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_type import PyrogramType
"""- :obj:`InputLocationMessageContent`
- :obj:`InputVenueMessageContent`
- :obj:`InputContactMessageContent`"""
class InputMessageContent(PyrogramType):
"""This object represents the content of a message to be sent as a result of an inline query.
Pyrogram currently supports the following 4 types:
- :obj:`InputTextMessageContent`
"""
__slots__ = []
def __init__(self):
super().__init__(None)

View File

@ -0,0 +1,54 @@
# 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 .input_message_content import InputMessageContent
from ...style import HTML, Markdown
class InputTextMessageContent(InputMessageContent):
"""This object represents the content of a text message to be sent as the result of an inline query.
Args:
message_text (``str``):
Text of the message to be sent, 1-4096 characters.
parse_mode (``str``, *optional*):
Use :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or :obj:`HTML <pyrogram.ParseMode.HTML>`
if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your message.
Defaults to Markdown.
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
"""
__slots__ = ["message_text", "parse_mode", "disable_web_page_preview"]
def __init__(self, message_text: str, parse_mode: str = "", disable_web_page_preview: bool = None):
super().__init__()
self.message_text = message_text
self.parse_mode = parse_mode
self.disable_web_page_preview = disable_web_page_preview
def write(self, reply_markup):
return types.InputBotInlineMessageText(
no_webpage=self.disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None,
**(HTML() if self.parse_mode.lower() == "html" else Markdown()).parse(self.message_text)
)

View File

@ -26,7 +26,7 @@ from ...ext.utils import encode
class VideoNote(PyrogramType):
"""This object represents a video message (available in Telegram apps as of v.4.0).
"""This object represents a video note.
Args:
file_id (``str``):

View File

@ -26,7 +26,7 @@ from ..pyrogram_type import PyrogramType
class Dialogs(PyrogramType):
"""This object represents a user's dialogs chunk
"""This object represents a user's dialogs chunk.
Args:
total_count (``int``):