mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-14 11:43:50 +01:00
Merge branch 'bot-api-2.0' of https://github.com/python-telegram-bot/python-telegram-bot into bot-api-2.0
This commit is contained in:
commit
10a96481f5
49 changed files with 2534 additions and 685 deletions
|
@ -3,5 +3,4 @@ telegram.bot module
|
|||
|
||||
.. automodule:: telegram.bot
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
|
|
@ -30,8 +30,10 @@ from .sticker import Sticker
|
|||
from .video import Video
|
||||
from .contact import Contact
|
||||
from .location import Location
|
||||
from .venue import Venue
|
||||
from .chataction import ChatAction
|
||||
from .userprofilephotos import UserProfilePhotos
|
||||
from .keyboardbutton import KeyboardButton
|
||||
from .replymarkup import ReplyMarkup
|
||||
from .replykeyboardmarkup import ReplyKeyboardMarkup
|
||||
from .replykeyboardhide import ReplyKeyboardHide
|
||||
|
@ -42,11 +44,38 @@ from .file import File
|
|||
from .nullhandler import NullHandler
|
||||
from .emoji import Emoji
|
||||
from .parsemode import ParseMode
|
||||
from .messageentity import MessageEntity
|
||||
from .message import Message
|
||||
from .inlinequery import InlineQuery
|
||||
from .inputmessagecontent import InputMessageContent
|
||||
from .callbackquery import CallbackQuery
|
||||
from .choseninlineresult import ChosenInlineResult
|
||||
from .inlinequeryresult import InlineQueryResultArticle, InlineQueryResultGif,\
|
||||
InlineQueryResultMpeg4Gif, InlineQueryResultPhoto, InlineQueryResultVideo
|
||||
from .inlinekeyboardbutton import InlineKeyboardButton
|
||||
from .inlinekeyboardmarkup import InlineKeyboardMarkup
|
||||
from .inlinequery import InlineQuery
|
||||
from .inlinequeryresult import InlineQueryResult
|
||||
from .inlinequeryresultarticle import InlineQueryResultArticle
|
||||
from .inlinequeryresultaudio import InlineQueryResultAudio
|
||||
from .inlinequeryresultcachedaudio import InlineQueryResultCachedAudio
|
||||
from .inlinequeryresultcacheddocument import InlineQueryResultCachedDocument
|
||||
from .inlinequeryresultcachedgif import InlineQueryResultCachedGif
|
||||
from .inlinequeryresultcachedmpeg4gif import InlineQueryResultCachedMpeg4Gif
|
||||
from .inlinequeryresultcachedphoto import InlineQueryResultCachedPhoto
|
||||
from .inlinequeryresultcachedsticker import InlineQueryResultCachedSticker
|
||||
from .inlinequeryresultcachedvideo import InlineQueryResultCachedVideo
|
||||
from .inlinequeryresultcachedvoice import InlineQueryResultCachedVoice
|
||||
from .inlinequeryresultcontact import InlineQueryResultContact
|
||||
from .inlinequeryresultdocument import InlineQueryResultDocument
|
||||
from .inlinequeryresultgif import InlineQueryResultGif
|
||||
from .inlinequeryresultlocation import InlineQueryResultLocation
|
||||
from .inlinequeryresultmpeg4gif import InlineQueryResultMpeg4Gif
|
||||
from .inlinequeryresultphoto import InlineQueryResultPhoto
|
||||
from .inlinequeryresultvenue import InlineQueryResultVenue
|
||||
from .inlinequeryresultvideo import InlineQueryResultVideo
|
||||
from .inlinequeryresultvoice import InlineQueryResultVoice
|
||||
from .inputtextmessagecontent import InputTextMessageContent
|
||||
from .inputlocationmessagecontent import InputLocationMessageContent
|
||||
from .inputvenuemessagecontent import InputVenueMessageContent
|
||||
from .inputcontactmessagecontent import InputContactMessageContent
|
||||
from .update import Update
|
||||
from .bot import Bot
|
||||
|
||||
|
@ -86,11 +115,63 @@ def JobQueue(*args, **kwargs):
|
|||
|
||||
__author__ = 'devs@python-telegram-bot.org'
|
||||
__version__ = '3.4'
|
||||
__all__ = ('Audio', 'Bot', 'Chat', 'Emoji', 'TelegramError', 'InputFile',
|
||||
'Contact', 'ForceReply', 'ReplyKeyboardHide', 'ReplyKeyboardMarkup',
|
||||
'UserProfilePhotos', 'ChatAction', 'Location', 'Video', 'Document',
|
||||
'Sticker', 'File', 'PhotoSize', 'Update', 'ParseMode', 'Message',
|
||||
'User', 'TelegramObject', 'NullHandler', 'Voice', 'InlineQuery',
|
||||
'ReplyMarkup', 'ChosenInlineResult', 'InlineQueryResultArticle',
|
||||
'InlineQueryResultGif', 'InlineQueryResultPhoto',
|
||||
'InlineQueryResultMpeg4Gif', 'InlineQueryResultVideo')
|
||||
__all__ = ['Audio',
|
||||
'Bot',
|
||||
'Chat',
|
||||
'ChatAction',
|
||||
'ChosenInlineResult',
|
||||
'CallbackQuery',
|
||||
'Contact',
|
||||
'Document',
|
||||
'Emoji',
|
||||
'File',
|
||||
'ForceReply',
|
||||
'InlineKeyboardButton',
|
||||
'InlineKeyboardMarkup',
|
||||
'InlineQuery',
|
||||
'InlineQueryResult',
|
||||
'InlineQueryResult',
|
||||
'InlineQueryResultArticle',
|
||||
'InlineQueryResultAudio',
|
||||
'InlineQueryResultCachedAudio',
|
||||
'InlineQueryResultCachedDocument',
|
||||
'InlineQueryResultCachedGif',
|
||||
'InlineQueryResultCachedMpeg4Gif',
|
||||
'InlineQueryResultCachedPhoto',
|
||||
'InlineQueryResultCachedSticker',
|
||||
'InlineQueryResultCachedVideo',
|
||||
'InlineQueryResultCachedVoice',
|
||||
'InlineQueryResultContact',
|
||||
'InlineQueryResultDocument',
|
||||
'InlineQueryResultGif',
|
||||
'InlineQueryResultLocation',
|
||||
'InlineQueryResultMpeg4Gif',
|
||||
'InlineQueryResultPhoto',
|
||||
'InlineQueryResultVenue',
|
||||
'InlineQueryResultVideo',
|
||||
'InlineQueryResultVoice',
|
||||
'InputContactMessageContent',
|
||||
'InputFile',
|
||||
'InputLocationMessageContent',
|
||||
'InputMessageContent',
|
||||
'InputTextMessageContent',
|
||||
'InputVenueMessageContent',
|
||||
'KeyboardButton',
|
||||
'Location',
|
||||
'Message',
|
||||
'MessageEntity',
|
||||
'NullHandler',
|
||||
'ParseMode',
|
||||
'PhotoSize',
|
||||
'ReplyKeyboardHide',
|
||||
'ReplyKeyboardMarkup',
|
||||
'ReplyMarkup',
|
||||
'Sticker',
|
||||
'TelegramError',
|
||||
'TelegramObject',
|
||||
'Update',
|
||||
'User',
|
||||
'UserProfilePhotos',
|
||||
'Venue',
|
||||
'Video',
|
||||
'Voice']
|
||||
|
|
0
telegram/answerinlinequery.py
Normal file
0
telegram/answerinlinequery.py
Normal file
|
@ -43,7 +43,12 @@ class TelegramObject(object):
|
|||
Returns:
|
||||
telegram.TelegramObject:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = data.copy()
|
||||
|
||||
return data
|
||||
|
||||
def to_json(self):
|
||||
"""
|
||||
|
|
561
telegram/bot.py
561
telegram/bot.py
|
@ -24,7 +24,7 @@ import functools
|
|||
import logging
|
||||
|
||||
from telegram import (User, Message, Update, UserProfilePhotos, File,
|
||||
TelegramError, ReplyMarkup, TelegramObject, NullHandler)
|
||||
ReplyMarkup, TelegramObject, NullHandler)
|
||||
from telegram.error import InvalidToken
|
||||
from telegram.utils import request
|
||||
from telegram.utils.validate import validate_string
|
||||
|
@ -33,7 +33,6 @@ logging.getLogger(__name__).addHandler(NullHandler())
|
|||
|
||||
|
||||
class Bot(TelegramObject):
|
||||
|
||||
"""This object represents a Telegram Bot.
|
||||
|
||||
Attributes:
|
||||
|
@ -53,15 +52,21 @@ class Bot(TelegramObject):
|
|||
|
||||
def __init__(self,
|
||||
token,
|
||||
base_url=None):
|
||||
base_url=None,
|
||||
base_file_url=None):
|
||||
self.token = self._valid_token(token)
|
||||
|
||||
if base_url is None:
|
||||
self.base_url = 'https://api.telegram.org/bot%s' % self.token
|
||||
if not base_url:
|
||||
self.base_url = 'https://api.telegram.org/bot%s' % \
|
||||
self.token
|
||||
else:
|
||||
self.base_url = base_url + self.token
|
||||
|
||||
self.base_file_url = 'https://api.telegram.org/file/bot%s' % self.token
|
||||
if not base_file_url:
|
||||
self.base_file_url = 'https://api.telegram.org/file/bot%s' % \
|
||||
self.token
|
||||
else:
|
||||
self.base_file_url = base_file_url + self.token
|
||||
|
||||
self.bot = None
|
||||
|
||||
|
@ -71,6 +76,7 @@ class Bot(TelegramObject):
|
|||
"""
|
||||
Returns:
|
||||
"""
|
||||
|
||||
@functools.wraps(func)
|
||||
def decorator(self, *args, **kwargs):
|
||||
"""
|
||||
|
@ -81,6 +87,7 @@ class Bot(TelegramObject):
|
|||
|
||||
result = func(self, *args, **kwargs)
|
||||
return result
|
||||
|
||||
return decorator
|
||||
|
||||
@property
|
||||
|
@ -129,6 +136,7 @@ class Bot(TelegramObject):
|
|||
logger.debug(result)
|
||||
logger.debug('Exiting: %s', func.__name__)
|
||||
return result
|
||||
|
||||
return decorator
|
||||
|
||||
def message(func):
|
||||
|
@ -136,49 +144,40 @@ class Bot(TelegramObject):
|
|||
Returns:
|
||||
A telegram.Message instance representing the message posted.
|
||||
"""
|
||||
|
||||
@functools.wraps(func)
|
||||
def decorator(self, *args, **kwargs):
|
||||
"""
|
||||
decorator
|
||||
"""
|
||||
url, data = func(self, *args, **kwargs)
|
||||
return Bot._post_message(url, data, kwargs)
|
||||
|
||||
if kwargs.get('reply_to_message_id'):
|
||||
data['reply_to_message_id'] = \
|
||||
kwargs.get('reply_to_message_id')
|
||||
|
||||
if kwargs.get('disable_notification'):
|
||||
data['disable_notification'] = \
|
||||
kwargs.get('disable_notification')
|
||||
|
||||
if kwargs.get('reply_markup'):
|
||||
reply_markup = kwargs.get('reply_markup')
|
||||
if isinstance(reply_markup, ReplyMarkup):
|
||||
data['reply_markup'] = reply_markup.to_json()
|
||||
else:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data,
|
||||
timeout=kwargs.get('timeout'),
|
||||
network_delay=kwargs.get('network_delay'))
|
||||
|
||||
if result is True:
|
||||
return result
|
||||
|
||||
return Message.de_json(result)
|
||||
|
||||
return decorator
|
||||
|
||||
@staticmethod
|
||||
def _post_message(url, data, kwargs, timeout=None, network_delay=2.):
|
||||
"""Posts a message to the telegram servers.
|
||||
|
||||
Returns:
|
||||
telegram.Message
|
||||
|
||||
"""
|
||||
if not data.get('chat_id'):
|
||||
raise TelegramError('Invalid chat_id')
|
||||
|
||||
if kwargs.get('reply_to_message_id'):
|
||||
reply_to_message_id = kwargs.get('reply_to_message_id')
|
||||
data['reply_to_message_id'] = reply_to_message_id
|
||||
|
||||
if kwargs.get('disable_notification'):
|
||||
disable_notification = kwargs.get('disable_notification')
|
||||
data['disable_notification'] = disable_notification
|
||||
|
||||
if kwargs.get('reply_markup'):
|
||||
reply_markup = kwargs.get('reply_markup')
|
||||
if isinstance(reply_markup, ReplyMarkup):
|
||||
data['reply_markup'] = reply_markup.to_json()
|
||||
else:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data, timeout=timeout,
|
||||
network_delay=network_delay)
|
||||
|
||||
if result is True:
|
||||
return result
|
||||
|
||||
return Message.de_json(result)
|
||||
|
||||
@log
|
||||
def getMe(self):
|
||||
"""A simple method for testing your bot's auth token.
|
||||
|
@ -206,29 +205,36 @@ class Bot(TelegramObject):
|
|||
"""Use this method to send text messages.
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the message recipient - telegram.Chat id.
|
||||
parse_mode:
|
||||
Send 'Markdown', if you want Telegram apps to show bold, italic and
|
||||
inline URLs in your bot's message. [Optional]
|
||||
text:
|
||||
Text of the message to be sent. The current maximum length is 4096
|
||||
UTF8 characters.
|
||||
disable_web_page_preview:
|
||||
Disables link previews for links in this message. [Optional]
|
||||
disable_notification:
|
||||
Sends the message silently. iOS users will not receive
|
||||
a notification, Android users will receive a notification
|
||||
with no sound. Other apps coming soon. [Optional]
|
||||
reply_to_message_id:
|
||||
If the message is a reply, ID of the original message. [Optional]
|
||||
reply_markup:
|
||||
Additional interface options. A JSON-serialized object for a custom
|
||||
reply keyboard, instructions to hide keyboard or to force a reply
|
||||
from the user. [Optional]
|
||||
chat_id (str): Unique identifier for the target chat or
|
||||
username of the target channel (in the format
|
||||
@channelusername).
|
||||
text (str): Text of the message to be sent. The current maximum
|
||||
length is 4096 UTF-8 characters.
|
||||
parse_mode (Optional[str]): Send Markdown or HTML, if you want
|
||||
Telegram apps to show bold, italic, fixed-width text or inline
|
||||
URLs in your bot's message.
|
||||
disable_web_page_preview (Optional[bool]): Disables link previews
|
||||
for links in this message.
|
||||
**kwargs (dict): Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
disable_notification (Optional[bool]): Sends the message silently.
|
||||
iOS users will not receive a notification, Android users will
|
||||
receive a notification with no sound.
|
||||
reply_to_message_id (Optional[int]): If the message is a reply,
|
||||
ID of the original message.
|
||||
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional
|
||||
interface options. A JSON-serialized object for an inline
|
||||
keyboard, custom reply keyboard, instructions to hide reply
|
||||
keyboard or to force a reply from the user.
|
||||
|
||||
Returns:
|
||||
A telegram.Message instance representing the message posted.
|
||||
:class:`telegram.Message`: On success, the sent message is
|
||||
returned.
|
||||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
|
||||
url = '%s/sendMessage' % self.base_url
|
||||
|
@ -271,6 +277,7 @@ class Bot(TelegramObject):
|
|||
url = '%s/forwardMessage' % self.base_url
|
||||
|
||||
data = {}
|
||||
|
||||
if chat_id:
|
||||
data['chat_id'] = chat_id
|
||||
if from_chat_id:
|
||||
|
@ -468,12 +475,12 @@ class Bot(TelegramObject):
|
|||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
def sendVideo(self,
|
||||
chat_id,
|
||||
video,
|
||||
duration=None,
|
||||
caption=None,
|
||||
timeout=None,
|
||||
**kwargs):
|
||||
"""Use this method to send video files, Telegram clients support mp4
|
||||
videos (other formats may be sent as telegram.Document).
|
||||
|
@ -518,7 +525,7 @@ class Bot(TelegramObject):
|
|||
if caption:
|
||||
data['caption'] = caption
|
||||
|
||||
return self._post_message(url, data, kwargs, timeout=timeout)
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
|
@ -607,6 +614,107 @@ class Bot(TelegramObject):
|
|||
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
def sendVenue(self,
|
||||
chat_id,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
foursquare_id=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send information about a venue.
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the target chat or username of the target
|
||||
channel (in the format @channelusername).
|
||||
latitude:
|
||||
Latitude of the venue.
|
||||
longitude:
|
||||
Longitude of the venue.
|
||||
title:
|
||||
Name of the venue.
|
||||
address:
|
||||
Address of the venue.
|
||||
foursquare_id:
|
||||
Foursquare identifier of the venue.
|
||||
disable_notification:
|
||||
Sends the message silently. iOS users will not receive a
|
||||
notification, Android users will receive a notification with no
|
||||
sound.
|
||||
reply_to_message_id:
|
||||
If the message is a reply, ID of the original message.
|
||||
reply_markup:
|
||||
Additional interface options. A JSON-serialized object for an
|
||||
inline keyboard, custom reply keyboard, instructions to hide
|
||||
reply keyboard or to force a reply from the user.
|
||||
|
||||
Returns:
|
||||
A telegram.Message instance representing the message posted.
|
||||
"""
|
||||
|
||||
url = '%s/sendVenue' % self.base_url
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'address': address,
|
||||
'title': title}
|
||||
|
||||
if foursquare_id:
|
||||
data['foursquare_id'] = foursquare_id
|
||||
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
def sendContact(self,
|
||||
chat_id,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name=None,
|
||||
**kwargs):
|
||||
"""
|
||||
Use this method to send phone contacts.
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the target chat or username of the target
|
||||
channel (in the format @channelusername).
|
||||
phone_number:
|
||||
Contact's phone number.
|
||||
first_name:
|
||||
Contact's first name.
|
||||
last_name:
|
||||
Contact's last name.
|
||||
disable_notification:
|
||||
Sends the message silently. iOS users will not receive a
|
||||
notification, Android users will receive a notification with no
|
||||
sound.
|
||||
reply_to_message_id:
|
||||
If the message is a reply, ID of the original message.
|
||||
reply_markup:
|
||||
Additional interface options. A JSON-serialized object for an
|
||||
inline keyboard, custom reply keyboard, instructions to hide
|
||||
reply keyboard or to force a reply from the user.
|
||||
|
||||
Returns:
|
||||
A telegram.Message instance representing the message posted.
|
||||
"""
|
||||
url = '%s/sendContact' % self.base_url
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'phone_number': phone_number,
|
||||
'first_name': first_name}
|
||||
|
||||
if last_name:
|
||||
data['last_name'] = last_name
|
||||
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
def sendChatAction(self,
|
||||
|
@ -642,32 +750,42 @@ class Bot(TelegramObject):
|
|||
def answerInlineQuery(self,
|
||||
inline_query_id,
|
||||
results,
|
||||
cache_time=None,
|
||||
cache_time=300,
|
||||
is_personal=None,
|
||||
next_offset=None):
|
||||
"""Use this method to reply to an inline query.
|
||||
next_offset=None,
|
||||
switch_pm_text=None,
|
||||
switch_pm_parameter=None):
|
||||
"""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 answered query
|
||||
results (list[InlineQueryResult]):
|
||||
A list of results for the inline query
|
||||
|
||||
Keyword Args:
|
||||
cache_time (Optional[int]): The maximum amount of time the result
|
||||
of the inline query may be cached on the server
|
||||
is_personal (Optional[bool]): 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 (Optional[str]): 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 don't support pagination. Offset length can't exceed 64
|
||||
bytes.
|
||||
inline_query_id (str): Unique identifier for the answered query.
|
||||
results (list[:class:`telegram.InlineQueryResult`]): A list of
|
||||
results for the inline query.
|
||||
cache_time (Optional[int]): The maximum amount of time the
|
||||
result of the inline query may be cached on the server.
|
||||
is_personal (Optional[bool]): 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 (Optional[str]): 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 don't support pagination. Offset length
|
||||
can't exceed 64 bytes.
|
||||
switch_pm_text (Optional[str]): 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 (Optional[str]): Parameter for the start
|
||||
message sent to the bot when user presses the switch button.
|
||||
|
||||
Returns:
|
||||
A boolean if answering was successful
|
||||
bool: On success, `True` is returned.
|
||||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
|
||||
validate_string(inline_query_id, 'inline_query_id')
|
||||
|
@ -680,12 +798,16 @@ class Bot(TelegramObject):
|
|||
data = {'inline_query_id': inline_query_id,
|
||||
'results': results}
|
||||
|
||||
if cache_time is not None:
|
||||
if cache_time or cache_time == 0:
|
||||
data['cache_time'] = int(cache_time)
|
||||
if is_personal is not None:
|
||||
if is_personal:
|
||||
data['is_personal'] = bool(is_personal)
|
||||
if next_offset is not None:
|
||||
if next_offset or next_offset == '':
|
||||
data['next_offset'] = next_offset
|
||||
if switch_pm_text:
|
||||
data['switch_pm_text'] = switch_pm_text
|
||||
if switch_pm_parameter:
|
||||
data['switch_pm_parameter'] = switch_pm_parameter
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
|
@ -752,6 +874,263 @@ class Bot(TelegramObject):
|
|||
|
||||
return File.de_json(result)
|
||||
|
||||
@log
|
||||
def kickChatMember(self,
|
||||
chat_id,
|
||||
user_id):
|
||||
"""Use this method to kick a user from a group or a supergroup. In the
|
||||
case of supergroups, the user will not be able to return to the group
|
||||
on their own using invite links, etc., unless unbanned first. The bot
|
||||
must be an administrator in the group for this to work.
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the target group or username of the target
|
||||
supergroup (in the format @supergroupusername).
|
||||
user_id:
|
||||
Unique identifier of the target user.
|
||||
|
||||
Returns:
|
||||
True on success.
|
||||
"""
|
||||
|
||||
url = '%s/kickChatMember' % self.base_url
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'user_id': user_id}
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
def unbanChatMember(self,
|
||||
chat_id,
|
||||
user_id):
|
||||
"""Use this method to unban a previously kicked user in a supergroup.
|
||||
The user will not return to the group automatically, but will be able
|
||||
to join via link, etc. The bot must be an administrator in the group
|
||||
for this to work.
|
||||
|
||||
Args:
|
||||
chat_id:
|
||||
Unique identifier for the target group or username of the target
|
||||
supergroup (in the format @supergroupusername).
|
||||
user_id:
|
||||
Unique identifier of the target user.
|
||||
|
||||
Returns:
|
||||
True on success.
|
||||
"""
|
||||
|
||||
url = '%s/unbanChatMember' % self.base_url
|
||||
|
||||
data = {'chat_id': chat_id,
|
||||
'user_id': user_id}
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
def answerCallbackQuery(self,
|
||||
callback_query_id,
|
||||
text=None,
|
||||
show_alert=False):
|
||||
"""Use this method to send answers to callback queries sent from
|
||||
inline keyboards. The answer will be displayed to the user as a
|
||||
notification at the top of the chat screen or as an alert.
|
||||
|
||||
Args:
|
||||
callback_query_id (str): Unique identifier for the query to be
|
||||
answered.
|
||||
text (Optional[str]): Text of the notification. If not
|
||||
specified, nothing will be shown to the user.
|
||||
show_alert (Optional[bool]): If `True`, an alert will be shown
|
||||
by the client instead of a notification at the top of the chat
|
||||
screen. Defaults to `False`.
|
||||
|
||||
Returns:
|
||||
bool: On success, `True` is returned.
|
||||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
|
||||
url = '%s/answerCallbackQuery' % self.base_url
|
||||
|
||||
data = {'callback_query_id': callback_query_id}
|
||||
|
||||
if text:
|
||||
data['text'] = text
|
||||
if show_alert:
|
||||
data['show_alert'] = show_alert
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
return result
|
||||
|
||||
@log
|
||||
def editMessageText(self,
|
||||
text,
|
||||
chat_id=None,
|
||||
message_id=None,
|
||||
inline_message_id=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
reply_markup=None):
|
||||
"""Use this method to edit text messages sent by the bot or via the bot
|
||||
(for inline bots).
|
||||
|
||||
Args:
|
||||
text:
|
||||
New text of the message.
|
||||
chat_id:
|
||||
Required if inline_message_id is not specified. Unique identifier
|
||||
for the target chat or username of the target channel (in the
|
||||
format @channelusername).
|
||||
message_id:
|
||||
Required if inline_message_id is not specified. Unique identifier
|
||||
of the sent message.
|
||||
inline_message_id:
|
||||
Required if chat_id and message_id are not specified. Identifier of
|
||||
the inline message.
|
||||
parse_mode:
|
||||
Send Markdown or HTML, if you want Telegram apps to show bold,
|
||||
italic, fixed-width text or inline URLs in your bot's message.
|
||||
disable_web_page_preview:
|
||||
Disables link previews for links in this message.
|
||||
reply_markup:
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
|
||||
Returns:
|
||||
Returns a telegram.Message object.
|
||||
"""
|
||||
|
||||
url = '%s/editMessageText' % self.base_url
|
||||
|
||||
data = {'text': text}
|
||||
|
||||
if chat_id:
|
||||
data['chat_id'] = chat_id
|
||||
if message_id:
|
||||
data['message_id'] = message_id
|
||||
if inline_message_id:
|
||||
data['inline_message_id'] = inline_message_id
|
||||
if parse_mode:
|
||||
data['parse_mode'] = parse_mode
|
||||
if disable_web_page_preview:
|
||||
data['disable_web_page_preview'] = disable_web_page_preview
|
||||
if reply_markup:
|
||||
if isinstance(reply_markup, ReplyMarkup):
|
||||
data['reply_markup'] = reply_markup.to_json()
|
||||
else:
|
||||
data['reply_markup'] = reply_markup
|
||||
|
||||
result = request.post(url, data)
|
||||
|
||||
return Message.de_json(result)
|
||||
|
||||
@log
|
||||
@message
|
||||
def editMessageCaption(self,
|
||||
chat_id=None,
|
||||
message_id=None,
|
||||
inline_message_id=None,
|
||||
caption=None,
|
||||
**kwargs):
|
||||
"""Use this method to edit captions of messages sent by the bot or
|
||||
via the bot (for inline bots).
|
||||
|
||||
Args:
|
||||
chat_id (Optional[str]): Required if inline_message_id is not
|
||||
specified. Unique identifier for the target chat or username of
|
||||
the target channel (in the format @channelusername).
|
||||
message_id (Optional[str]): Required if inline_message_id is not
|
||||
specified. Unique identifier of the sent message.
|
||||
inline_message_id (Optional[str]): Required if chat_id and
|
||||
message_id are not specified. Identifier of the inline message.
|
||||
caption (Optional[str]): New caption of the message.
|
||||
**kwargs (Optional[dict]): Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by
|
||||
the bot, the edited Message is returned, otherwise `True` is
|
||||
returned.
|
||||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
|
||||
url = '%s/editMessageCaption' % self.base_url
|
||||
|
||||
data = {}
|
||||
|
||||
if caption:
|
||||
data['caption'] = caption
|
||||
if chat_id:
|
||||
data['chat_id'] = chat_id
|
||||
if message_id:
|
||||
data['message_id'] = message_id
|
||||
if inline_message_id:
|
||||
data['inline_message_id'] = inline_message_id
|
||||
|
||||
return url, data
|
||||
|
||||
@log
|
||||
@message
|
||||
def editMessageReplyMarkup(self,
|
||||
chat_id=None,
|
||||
message_id=None,
|
||||
inline_message_id=None,
|
||||
**kwargs):
|
||||
"""Use this method to edit only the reply markup of messages sent by
|
||||
the bot or via the bot (for inline bots).
|
||||
|
||||
Args:
|
||||
chat_id (Optional[str]): Required if inline_message_id is not
|
||||
specified. Unique identifier for the target chat or username of
|
||||
the target channel (in the format @channelusername).
|
||||
message_id (Optional[str]): Required if inline_message_id is not
|
||||
specified. Unique identifier of the sent message.
|
||||
inline_message_id (Optional[str]): Required if chat_id and
|
||||
message_id are not specified. Identifier of the inline message.
|
||||
**kwargs (Optional[dict]): Arbitrary keyword arguments.
|
||||
|
||||
Keyword Args:
|
||||
reply_markup (Optional[:class:`telegram.InlineKeyboardMarkup`]):
|
||||
A JSON-serialized object for an inline keyboard.
|
||||
|
||||
Returns:
|
||||
:class:`telegram.Message`: On success, if edited message is sent by
|
||||
the bot, the edited message is returned, otherwise `True` is
|
||||
returned.
|
||||
|
||||
Raises:
|
||||
:class:`telegram.TelegramError`
|
||||
|
||||
"""
|
||||
|
||||
url = '%s/editMessageReplyMarkup' % self.base_url
|
||||
|
||||
data = {}
|
||||
|
||||
if chat_id:
|
||||
data['chat_id'] = chat_id
|
||||
if message_id:
|
||||
data['message_id'] = message_id
|
||||
if inline_message_id:
|
||||
data['inline_message_id'] = inline_message_id
|
||||
|
||||
return url, data
|
||||
|
||||
@log
|
||||
def getUpdates(self,
|
||||
offset=None,
|
||||
|
@ -786,11 +1165,12 @@ class Bot(TelegramObject):
|
|||
url = '%s/getUpdates' % self.base_url
|
||||
|
||||
data = {}
|
||||
|
||||
if offset:
|
||||
data['offset'] = offset
|
||||
if limit:
|
||||
data['limit'] = limit
|
||||
if timeout:
|
||||
if timeout or timeout == 0:
|
||||
data['timeout'] = timeout
|
||||
|
||||
result = request.post(url, data, network_delay=network_delay)
|
||||
|
@ -824,7 +1204,8 @@ class Bot(TelegramObject):
|
|||
url = '%s/setWebhook' % self.base_url
|
||||
|
||||
data = {}
|
||||
if webhook_url:
|
||||
|
||||
if webhook_url or webhook_url == '':
|
||||
data['url'] = webhook_url
|
||||
if certificate:
|
||||
data['certificate'] = certificate
|
||||
|
|
50
telegram/callbackquery.py
Normal file
50
telegram/callbackquery.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram
|
||||
CallbackQuery"""
|
||||
|
||||
from telegram import TelegramObject, Message, User
|
||||
|
||||
|
||||
class CallbackQuery(TelegramObject):
|
||||
"""This object represents a Telegram CallbackQuery."""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
from_user,
|
||||
data,
|
||||
**kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
self.data = data
|
||||
# Optionals
|
||||
self.message = kwargs.get('message')
|
||||
self.inline_message_id = kwargs.get('inline_message_id', '')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['message'] = Message.de_json(data.get('message'))
|
||||
|
||||
return CallbackQuery(**data)
|
|
@ -21,8 +21,7 @@
|
|||
This module contains a object that represents a Telegram ChosenInlineResult
|
||||
"""
|
||||
|
||||
|
||||
from telegram import TelegramObject, User
|
||||
from telegram import TelegramObject, User, Location
|
||||
|
||||
|
||||
class ChosenInlineResult(TelegramObject):
|
||||
|
@ -46,11 +45,16 @@ class ChosenInlineResult(TelegramObject):
|
|||
def __init__(self,
|
||||
result_id,
|
||||
from_user,
|
||||
query):
|
||||
query,
|
||||
location=None,
|
||||
inline_message_id=None):
|
||||
# Required
|
||||
self.result_id = result_id
|
||||
self.from_user = from_user
|
||||
self.query = query
|
||||
# Optionals
|
||||
self.location = location
|
||||
self.inline_message_id = inline_message_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
|
@ -63,8 +67,11 @@ class ChosenInlineResult(TelegramObject):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
|
||||
# Required
|
||||
data['from_user'] = User.de_json(data.pop('from'))
|
||||
# Optionals
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
|
||||
return ChosenInlineResult(**data)
|
||||
|
||||
|
|
|
@ -163,25 +163,25 @@ class Emoji(object):
|
|||
SQUARED_SOS = n(b'\xF0\x9F\x86\x98')
|
||||
SQUARED_UP_WITH_EXCLAMATION_MARK = n(b'\xF0\x9F\x86\x99')
|
||||
SQUARED_VS = n(b'\xF0\x9F\x86\x9A')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_D_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_E\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_D_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_E \
|
||||
= n(b'\xF0\x9F\x87\xA9\xF0\x9F\x87\xAA')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_G_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_B\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_G_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_B \
|
||||
= n(b'\xF0\x9F\x87\xAC\xF0\x9F\x87\xA7')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_C_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_N\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_C_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_N \
|
||||
= n(b'\xF0\x9F\x87\xA8\xF0\x9F\x87\xB3')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_J_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_P\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_J_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_P \
|
||||
= n(b'\xF0\x9F\x87\xAF\xF0\x9F\x87\xB5')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_K_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_R\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_K_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_R \
|
||||
= n(b'\xF0\x9F\x87\xB0\xF0\x9F\x87\xB7')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_F_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_R\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_F_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_R \
|
||||
= n(b'\xF0\x9F\x87\xAB\xF0\x9F\x87\xB7')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_E_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_S\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_E_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_S \
|
||||
= n(b'\xF0\x9F\x87\xAA\xF0\x9F\x87\xB8')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_I_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_T\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_I_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_T \
|
||||
= n(b'\xF0\x9F\x87\xAE\xF0\x9F\x87\xB9')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_U_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_S\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_U_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_S \
|
||||
= n(b'\xF0\x9F\x87\xBA\xF0\x9F\x87\xB8')
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_R_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_U\
|
||||
REGIONAL_INDICATOR_SYMBOL_LETTER_R_PLUS_REGIONAL_INDICATOR_SYMBOL_LETTER_U \
|
||||
= n(b'\xF0\x9F\x87\xB7\xF0\x9F\x87\xBA')
|
||||
SQUARED_KATAKANA_KOKO = n(b'\xF0\x9F\x88\x81')
|
||||
SQUARED_KATAKANA_SA = n(b'\xF0\x9F\x88\x82')
|
||||
|
|
|
@ -62,13 +62,11 @@ class TelegramError(Exception):
|
|||
|
||||
|
||||
class Unauthorized(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(Unauthorized, self).__init__('Unauthorized')
|
||||
|
||||
|
||||
class InvalidToken(TelegramError):
|
||||
|
||||
def __init__(self):
|
||||
super(InvalidToken, self).__init__('Invalid token')
|
||||
|
||||
|
@ -78,6 +76,5 @@ class NetworkError(TelegramError):
|
|||
|
||||
|
||||
class TimedOut(NetworkError):
|
||||
|
||||
def __init__(self):
|
||||
super(TimedOut, self).__init__('Timed out')
|
||||
|
|
|
@ -26,7 +26,6 @@ from telegram.utils.request import download as _download
|
|||
|
||||
|
||||
class File(TelegramObject):
|
||||
|
||||
"""This object represents a Telegram File.
|
||||
|
||||
Attributes:
|
||||
|
|
59
telegram/inlinekeyboardbutton.py
Normal file
59
telegram/inlinekeyboardbutton.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram
|
||||
InlineKeyboardButton"""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class InlineKeyboardButton(TelegramObject):
|
||||
"""This object represents a Telegram InlineKeyboardButton."""
|
||||
|
||||
def __init__(self,
|
||||
text,
|
||||
url=None,
|
||||
callback_data=None,
|
||||
switch_inline_query=None):
|
||||
# Required
|
||||
self.text = text
|
||||
|
||||
# Optionals
|
||||
self.url = url
|
||||
self.callback_data = callback_data
|
||||
self.switch_inline_query = switch_inline_query
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return InlineKeyboardButton(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
inline_keyboards = list()
|
||||
for inline_keyboard in data:
|
||||
inline_keyboards.append(InlineKeyboardButton.
|
||||
de_json(inline_keyboard))
|
||||
|
||||
return inline_keyboards
|
53
telegram/inlinekeyboardmarkup.py
Normal file
53
telegram/inlinekeyboardmarkup.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram
|
||||
InlineKeyboardMarkup"""
|
||||
|
||||
from telegram import ReplyMarkup, InlineKeyboardButton
|
||||
|
||||
|
||||
class InlineKeyboardMarkup(ReplyMarkup):
|
||||
"""This object represents a Telegram InlineKeyboardMarkup."""
|
||||
|
||||
def __init__(self,
|
||||
inline_keyboard):
|
||||
# Required
|
||||
self.inline_keyboard = inline_keyboard
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data['inline_keyboard'] = \
|
||||
[InlineKeyboardButton.de_list(inline_keyboard) for inline_keyboard
|
||||
in data['inline_keyboard']]
|
||||
|
||||
return InlineKeyboardMarkup(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = super(InlineKeyboardMarkup, self).to_dict()
|
||||
|
||||
data['inline_keyboard'] = []
|
||||
for inline_keyboard in self.inline_keyboard:
|
||||
data['inline_keyboard'].append(
|
||||
[x.to_dict() for x in inline_keyboard])
|
||||
|
||||
return data
|
|
@ -39,14 +39,14 @@ class InlineQuery(TelegramObject):
|
|||
from_user (:class:`telegram.User`):
|
||||
query (str):
|
||||
offset (str):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
from_user,
|
||||
query,
|
||||
offset):
|
||||
offset,
|
||||
**kwargs):
|
||||
# Required
|
||||
self.id = id
|
||||
self.from_user = from_user
|
||||
|
@ -64,8 +64,8 @@ class InlineQuery(TelegramObject):
|
|||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data['from_user'] = User.de_json(data.pop('from'))
|
||||
|
||||
data['from_user'] = User.de_json(data.get('from'))
|
||||
|
||||
return InlineQuery(**data)
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015 Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
|
@ -16,13 +17,10 @@
|
|||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""
|
||||
This module contains the classes that represent Telegram InlineQueryResults
|
||||
https://core.telegram.org/bots/api#inline-mode
|
||||
"""
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResult"""
|
||||
|
||||
from telegram import TelegramObject
|
||||
from telegram.utils.validate import validate_string
|
||||
|
||||
|
||||
class InlineQueryResult(TelegramObject):
|
||||
|
@ -47,453 +45,4 @@ class InlineQueryResult(TelegramObject):
|
|||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResult:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return InlineQueryResult(**data)
|
||||
|
||||
|
||||
class InlineQueryResultArticle(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultArticle.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
title (str):
|
||||
message_text (str):
|
||||
parse_mode (str):
|
||||
disable_web_page_preview (bool):
|
||||
url (str):
|
||||
hide_url (bool):
|
||||
description (str):
|
||||
thumb_url (str):
|
||||
thumb_width (int):
|
||||
thumb_height (int):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
title (str):
|
||||
message_text (str):
|
||||
|
||||
Keyword Args:
|
||||
parse_mode (Optional[str]):
|
||||
disable_web_page_preview (Optional[bool]):
|
||||
url (Optional[str]):
|
||||
hide_url (Optional[bool]):
|
||||
description (Optional[str]):
|
||||
thumb_url (Optional[str]):
|
||||
thumb_width (Optional[int]):
|
||||
thumb_height (Optional[int]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
title,
|
||||
message_text,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None,
|
||||
url=None,
|
||||
hide_url=None,
|
||||
description=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None):
|
||||
|
||||
validate_string(title, 'title')
|
||||
validate_string(message_text, 'message_text')
|
||||
validate_string(url, 'url')
|
||||
validate_string(description, 'description')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
validate_string(parse_mode, 'parse_mode')
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultArticle, self).__init__('article', id)
|
||||
self.title = title
|
||||
self.message_text = message_text
|
||||
|
||||
# Optional
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
||||
self.url = url
|
||||
self.hide_url = bool(hide_url)
|
||||
self.description = description
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width is not None:
|
||||
self.thumb_width = int(thumb_width)
|
||||
if thumb_height is not None:
|
||||
self.thumb_height = int(thumb_height)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResultArticle:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultArticle(**data)
|
||||
|
||||
|
||||
class InlineQueryResultPhoto(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultPhoto.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
photo_url (str):
|
||||
mime_type (str):
|
||||
photo_width (int):
|
||||
photo_height (int):
|
||||
thumb_url (str):
|
||||
title (str):
|
||||
description (str):
|
||||
caption (str):
|
||||
message_text (str):
|
||||
parse_mode (str):
|
||||
disable_web_page_preview (bool):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
photo_url (str):
|
||||
thumb_url (str):
|
||||
|
||||
Keyword Args:
|
||||
mime_type (Optional[str]):
|
||||
photo_width (Optional[int]):
|
||||
photo_height (Optional[int]):
|
||||
title (Optional[str]):
|
||||
description (Optional[str]):
|
||||
caption (Optional[str]):
|
||||
message_text (Optional[str]):
|
||||
parse_mode (Optional[str]):
|
||||
disable_web_page_preview (Optional[bool]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
photo_url,
|
||||
thumb_url,
|
||||
mime_type=None,
|
||||
photo_width=None,
|
||||
photo_height=None,
|
||||
title=None,
|
||||
description=None,
|
||||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
|
||||
validate_string(photo_url, 'photo_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
validate_string(mime_type, 'mime_type')
|
||||
validate_string(title, 'title')
|
||||
validate_string(description, 'description')
|
||||
validate_string(caption, 'caption')
|
||||
validate_string(message_text, 'message_text')
|
||||
validate_string(parse_mode, 'parse_mode')
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultPhoto, self).__init__('photo', id)
|
||||
self.photo_url = photo_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optional
|
||||
self.mime_type = mime_type
|
||||
if photo_width is not None:
|
||||
self.photo_width = int(photo_width)
|
||||
if photo_height is not None:
|
||||
self.photo_height = int(photo_height)
|
||||
self.title = title
|
||||
self.description = description
|
||||
self.caption = caption
|
||||
self.message_text = message_text
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResultPhoto:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultPhoto(**data)
|
||||
|
||||
|
||||
class InlineQueryResultGif(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultGif.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
gif_url (str):
|
||||
gif_width (int):
|
||||
gif_height (int):
|
||||
thumb_url (str):
|
||||
title (str):
|
||||
caption (str):
|
||||
message_text (str):
|
||||
parse_mode (str):
|
||||
disable_web_page_preview (bool):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
gif_url (str):
|
||||
thumb_url (str):
|
||||
|
||||
Keyword Args:
|
||||
gif_width (Optional[int]):
|
||||
gif_height (Optional[int]):
|
||||
title (Optional[str]):
|
||||
caption (Optional[str]):
|
||||
message_text (Optional[str]):
|
||||
parse_mode (Optional[str]):
|
||||
disable_web_page_preview (Optional[bool]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
gif_url,
|
||||
thumb_url,
|
||||
gif_width=None,
|
||||
gif_height=None,
|
||||
title=None,
|
||||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
|
||||
validate_string(gif_url, 'gif_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
validate_string(title, 'title')
|
||||
validate_string(caption, 'caption')
|
||||
validate_string(message_text, 'message_text')
|
||||
validate_string(parse_mode, 'parse_mode')
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultGif, self).__init__('gif', id)
|
||||
self.gif_url = gif_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optional
|
||||
if gif_width is not None:
|
||||
self.gif_width = int(gif_width)
|
||||
if gif_height is not None:
|
||||
self.gif_height = int(gif_height)
|
||||
self.title = title
|
||||
self.caption = caption
|
||||
self.message_text = message_text
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResultGif:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultGif(**data)
|
||||
|
||||
|
||||
class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultMpeg4Gif.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
mpeg4_url (str):
|
||||
mpeg4_width (int):
|
||||
mpeg4_height (int):
|
||||
thumb_url (str):
|
||||
title (str):
|
||||
caption (str):
|
||||
message_text (str):
|
||||
parse_mode (str):
|
||||
disable_web_page_preview (bool):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
mpeg4_url (str):
|
||||
thumb_url (str):
|
||||
|
||||
Keyword Args:
|
||||
mpeg4_width (Optional[int]):
|
||||
mpeg4_height (Optional[int]):
|
||||
title (Optional[str]):
|
||||
caption (Optional[str]):
|
||||
message_text (Optional[str]):
|
||||
parse_mode (Optional[str]):
|
||||
disable_web_page_preview (Optional[bool]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
mpeg4_url,
|
||||
thumb_url,
|
||||
mpeg4_width=None,
|
||||
mpeg4_height=None,
|
||||
title=None,
|
||||
caption=None,
|
||||
message_text=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
|
||||
validate_string(mpeg4_url, 'mpeg4_url')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
validate_string(title, 'title')
|
||||
validate_string(caption, 'caption')
|
||||
validate_string(message_text, 'message_text')
|
||||
validate_string(parse_mode, 'parse_mode')
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultMpeg4Gif, self).__init__('mpeg4_gif', id)
|
||||
self.mpeg4_url = mpeg4_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optional
|
||||
if mpeg4_width is not None:
|
||||
self.mpeg4_width = int(mpeg4_width)
|
||||
if mpeg4_height is not None:
|
||||
self.mpeg4_height = int(mpeg4_height)
|
||||
self.title = title
|
||||
self.caption = caption
|
||||
self.message_text = message_text
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResultMpeg4Gif:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultMpeg4Gif(**data)
|
||||
|
||||
|
||||
class InlineQueryResultVideo(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultVideo.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
video_url (str):
|
||||
mime_type (str):
|
||||
video_width (int):
|
||||
video_height (int):
|
||||
video_duration (int):
|
||||
thumb_url (str):
|
||||
title (str):
|
||||
description (str):
|
||||
caption (str):
|
||||
message_text (str):
|
||||
parse_mode (str):
|
||||
disable_web_page_preview (bool):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
video_url (str):
|
||||
mime_type (str):
|
||||
thumb_url (str):
|
||||
title (str):
|
||||
message_text (str):
|
||||
|
||||
Keyword Args:
|
||||
video_width (Optional[int]):
|
||||
video_height (Optional[int]):
|
||||
video_duration (Optional[int]):
|
||||
description (Optional[str]):
|
||||
caption (Optional[str]):
|
||||
parse_mode (Optional[str]):
|
||||
disable_web_page_preview (Optional[bool]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
video_url,
|
||||
mime_type,
|
||||
thumb_url,
|
||||
title,
|
||||
message_text,
|
||||
video_width=None,
|
||||
video_height=None,
|
||||
video_duration=None,
|
||||
description=None,
|
||||
caption=None,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
|
||||
validate_string(video_url, 'video_url')
|
||||
validate_string(mime_type, 'mime_type')
|
||||
validate_string(thumb_url, 'thumb_url')
|
||||
validate_string(title, 'title')
|
||||
validate_string(message_text, 'message_text')
|
||||
validate_string(description, 'description')
|
||||
validate_string(caption, 'caption')
|
||||
validate_string(parse_mode, 'parse_mode')
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultVideo, self).__init__('video', id)
|
||||
self.video_url = video_url
|
||||
self.mime_type = mime_type
|
||||
self.thumb_url = thumb_url
|
||||
self.title = title
|
||||
self.message_text = message_text
|
||||
|
||||
# Optional
|
||||
if video_width is not None:
|
||||
self.video_width = int(video_width)
|
||||
if video_height is not None:
|
||||
self.video_height = int(video_height)
|
||||
if video_duration is not None:
|
||||
self.video_duration = int(video_duration)
|
||||
self.description = description
|
||||
self.caption = caption
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = bool(disable_web_page_preview)
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
"""
|
||||
Args:
|
||||
data (dict):
|
||||
|
||||
Returns:
|
||||
telegram.InlineQueryResultVideo:
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
data = data.copy()
|
||||
data.pop('type', None)
|
||||
|
||||
return InlineQueryResultVideo(**data)
|
||||
return super(InlineQueryResult, InlineQueryResult).de_json(data)
|
||||
|
|
100
telegram/inlinequeryresultarticle.py
Normal file
100
telegram/inlinequeryresultarticle.py
Normal file
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultArticle"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultArticle(InlineQueryResult):
|
||||
"""This object represents a Telegram InlineQueryResultArticle.
|
||||
|
||||
Attributes:
|
||||
id (str):
|
||||
title (str):
|
||||
input_message_content (telegram.InputMessageContent):
|
||||
reply_markup (telegram.ReplyMarkup):
|
||||
url (str):
|
||||
hide_url (bool):
|
||||
description (str):
|
||||
thumb_url (str):
|
||||
thumb_width (int):
|
||||
thumb_height (int):
|
||||
|
||||
Args:
|
||||
id (str): Unique identifier for this result, 1-64 Bytes
|
||||
title (str):
|
||||
reply_markup (telegram.ReplyMarkup):
|
||||
|
||||
Keyword Args:
|
||||
url (Optional[str]):
|
||||
hide_url (Optional[bool]):
|
||||
description (Optional[str]):
|
||||
thumb_url (Optional[str]):
|
||||
thumb_width (Optional[int]):
|
||||
thumb_height (Optional[int]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id,
|
||||
title,
|
||||
input_message_content,
|
||||
reply_markup=None,
|
||||
url=None,
|
||||
hide_url=None,
|
||||
description=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultArticle, self).__init__('article', id)
|
||||
self.title = title
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
# Optional
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if url:
|
||||
self.url = url
|
||||
if hide_url:
|
||||
self.hide_url = hide_url
|
||||
if description:
|
||||
self.description = description
|
||||
if thumb_url:
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width:
|
||||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultArticle,
|
||||
InlineQueryResultArticle).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultArticle(**data)
|
63
telegram/inlinequeryresultaudio.py
Normal file
63
telegram/inlinequeryresultaudio.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultAudio"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultAudio(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
audio_url,
|
||||
title,
|
||||
performer=None,
|
||||
audio_duration=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultAudio, self).__init__('audio', id)
|
||||
self.audio_url = audio_url
|
||||
self.title = title
|
||||
|
||||
# Optionals
|
||||
if performer:
|
||||
self.performer = performer
|
||||
if audio_duration:
|
||||
self.audio_duration = audio_duration
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultAudio,
|
||||
InlineQueryResultAudio).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultAudio(**data)
|
54
telegram/inlinequeryresultcachedaudio.py
Normal file
54
telegram/inlinequeryresultcachedaudio.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedAudio"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedAudio(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
audio_file_id,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedAudio, self).__init__('audio', id)
|
||||
self.audio_file_id = audio_file_id
|
||||
|
||||
# Optionals
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedAudio,
|
||||
InlineQueryResultCachedAudio).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedAudio(**data)
|
62
telegram/inlinequeryresultcacheddocument.py
Normal file
62
telegram/inlinequeryresultcacheddocument.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedDocument"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedDocument(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
title,
|
||||
document_file_id,
|
||||
description=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedDocument, self).__init__('document', id)
|
||||
self.title = title
|
||||
self.document_file_id = document_file_id
|
||||
|
||||
# Optionals
|
||||
if description:
|
||||
self.description = description
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedDocument,
|
||||
InlineQueryResultCachedDocument).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedDocument(**data)
|
60
telegram/inlinequeryresultcachedgif.py
Normal file
60
telegram/inlinequeryresultcachedgif.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedGif"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedGif(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
gif_file_id,
|
||||
title=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedGif, self).__init__('gif', id)
|
||||
self.gif_file_id = gif_file_id
|
||||
|
||||
# Optionals
|
||||
if title:
|
||||
self.title = title
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedGif,
|
||||
InlineQueryResultCachedGif).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedGif(**data)
|
60
telegram/inlinequeryresultcachedmpeg4gif.py
Normal file
60
telegram/inlinequeryresultcachedmpeg4gif.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultMpeg4Gif"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
mpeg4_file_id,
|
||||
title=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedMpeg4Gif, self).__init__('mpeg4_gif', id)
|
||||
self.mpeg4_file_id = mpeg4_file_id
|
||||
|
||||
# Optionals
|
||||
if title:
|
||||
self.title = title
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedMpeg4Gif,
|
||||
InlineQueryResultCachedMpeg4Gif).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedMpeg4Gif(**data)
|
63
telegram/inlinequeryresultcachedphoto.py
Normal file
63
telegram/inlinequeryresultcachedphoto.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultPhoto"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedPhoto(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
photo_file_id,
|
||||
title=None,
|
||||
description=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedPhoto, self).__init__('photo', id)
|
||||
self.photo_file_id = photo_file_id
|
||||
|
||||
# Optionals
|
||||
if title:
|
||||
self.title = title
|
||||
if description:
|
||||
self.description = description
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedPhoto,
|
||||
InlineQueryResultCachedPhoto).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedPhoto(**data)
|
54
telegram/inlinequeryresultcachedsticker.py
Normal file
54
telegram/inlinequeryresultcachedsticker.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedSticker"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedSticker(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
sticker_file_id,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedSticker, self).__init__('sticker', id)
|
||||
self.sticker_file_id = sticker_file_id
|
||||
|
||||
# Optionals
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedSticker,
|
||||
InlineQueryResultCachedSticker).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedSticker(**data)
|
62
telegram/inlinequeryresultcachedvideo.py
Normal file
62
telegram/inlinequeryresultcachedvideo.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedVideo"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedVideo(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
video_file_id,
|
||||
title,
|
||||
description=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedVideo, self).__init__('video', id)
|
||||
self.video_file_id = video_file_id
|
||||
self.title = title
|
||||
|
||||
# Optionals
|
||||
if description:
|
||||
self.description = description
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedVideo,
|
||||
InlineQueryResultCachedVideo).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedVideo(**data)
|
59
telegram/inlinequeryresultcachedvoice.py
Normal file
59
telegram/inlinequeryresultcachedvoice.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultCachedVoice"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultCachedVoice(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
voice_file_id,
|
||||
title,
|
||||
description=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultCachedVoice, self).__init__('voice', id)
|
||||
self.voice_file_id = voice_file_id
|
||||
self.title = title
|
||||
|
||||
# Optionals
|
||||
if description:
|
||||
self.description = description
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultCachedVoice,
|
||||
InlineQueryResultCachedVoice).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultCachedVoice(**data)
|
68
telegram/inlinequeryresultcontact.py
Normal file
68
telegram/inlinequeryresultcontact.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultContact"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultContact(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
phone_number,
|
||||
first_name,
|
||||
last_name=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultContact, self).__init__('contact', id)
|
||||
self.phone_number = phone_number
|
||||
self.first_name = first_name
|
||||
|
||||
# Optionals
|
||||
if last_name:
|
||||
self.last_name = last_name
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
if thumb_url:
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width:
|
||||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultContact,
|
||||
InlineQueryResultContact).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultContact(**data)
|
73
telegram/inlinequeryresultdocument.py
Normal file
73
telegram/inlinequeryresultdocument.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultDocument"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultDocument(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
document_url,
|
||||
title,
|
||||
mime_type,
|
||||
caption=None,
|
||||
description=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultDocument, self).__init__('document', id)
|
||||
self.document_url = document_url
|
||||
self.title = title
|
||||
self.mime_type = mime_type
|
||||
|
||||
# Optionals
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if description:
|
||||
self.description = description
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
if thumb_url:
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width:
|
||||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultDocument,
|
||||
InlineQueryResultDocument).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultDocument(**data)
|
69
telegram/inlinequeryresultgif.py
Normal file
69
telegram/inlinequeryresultgif.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultGif"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultGif(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
gif_url,
|
||||
thumb_url,
|
||||
gif_width=None,
|
||||
gif_height=None,
|
||||
title=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultGif, self).__init__('gif', id)
|
||||
self.gif_url = gif_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optionals
|
||||
if gif_width:
|
||||
self.gif_width = gif_width
|
||||
if gif_height:
|
||||
self.gif_height = gif_height
|
||||
if title:
|
||||
self.title = title
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultGif,
|
||||
InlineQueryResultGif).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultGif(**data)
|
67
telegram/inlinequeryresultlocation.py
Normal file
67
telegram/inlinequeryresultlocation.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultLocation"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultLocation(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultLocation, self).__init__('location', id)
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.title = title
|
||||
|
||||
# Optionals
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
if thumb_url:
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width:
|
||||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultLocation,
|
||||
InlineQueryResultLocation).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultLocation(**data)
|
69
telegram/inlinequeryresultmpeg4gif.py
Normal file
69
telegram/inlinequeryresultmpeg4gif.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultMpeg4Gif"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultMpeg4Gif(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
mpeg4_url,
|
||||
thumb_url,
|
||||
mpeg4_width=None,
|
||||
mpeg4_height=None,
|
||||
title=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultMpeg4Gif, self).__init__('mpeg4_gif', id)
|
||||
self.mpeg4_url = mpeg4_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optional
|
||||
if mpeg4_width:
|
||||
self.mpeg4_width = mpeg4_width
|
||||
if mpeg4_height:
|
||||
self.mpeg4_height = mpeg4_height
|
||||
if title:
|
||||
self.title = title
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultMpeg4Gif,
|
||||
InlineQueryResultMpeg4Gif).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultMpeg4Gif(**data)
|
71
telegram/inlinequeryresultphoto.py
Normal file
71
telegram/inlinequeryresultphoto.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultPhoto"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultPhoto(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
photo_url,
|
||||
thumb_url,
|
||||
photo_width=None,
|
||||
photo_height=None,
|
||||
title=None,
|
||||
description=None,
|
||||
caption=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
# Required
|
||||
super(InlineQueryResultPhoto, self).__init__('photo', id)
|
||||
self.photo_url = photo_url
|
||||
self.thumb_url = thumb_url
|
||||
|
||||
# Optionals
|
||||
if photo_width:
|
||||
self.photo_width = int(photo_width)
|
||||
if photo_height:
|
||||
self.photo_height = int(photo_height)
|
||||
if title:
|
||||
self.title = title
|
||||
if description:
|
||||
self.description = description
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultPhoto,
|
||||
InlineQueryResultPhoto).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultPhoto(**data)
|
73
telegram/inlinequeryresultvenue.py
Normal file
73
telegram/inlinequeryresultvenue.py
Normal file
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultVenue"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVenue(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
foursquare_id=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
thumb_url=None,
|
||||
thumb_width=None,
|
||||
thumb_height=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultVenue, self).__init__('venue', id)
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.title = title
|
||||
self.address = address
|
||||
|
||||
# Optional
|
||||
if foursquare_id:
|
||||
self.foursquare_id = foursquare_id
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
if thumb_url:
|
||||
self.thumb_url = thumb_url
|
||||
if thumb_width:
|
||||
self.thumb_width = thumb_width
|
||||
if thumb_height:
|
||||
self.thumb_height = thumb_height
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVenue,
|
||||
InlineQueryResultVenue).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultVenue(**data)
|
76
telegram/inlinequeryresultvideo.py
Normal file
76
telegram/inlinequeryresultvideo.py
Normal file
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultVideo"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVideo(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
video_url,
|
||||
mime_type,
|
||||
thumb_url,
|
||||
title,
|
||||
caption=None,
|
||||
video_width=None,
|
||||
video_height=None,
|
||||
video_duration=None,
|
||||
description=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultVideo, self).__init__('video', id)
|
||||
self.video_url = video_url
|
||||
self.mime_type = mime_type
|
||||
self.thumb_url = thumb_url
|
||||
self.title = title
|
||||
|
||||
# Optional
|
||||
if caption:
|
||||
self.caption = caption
|
||||
if video_width:
|
||||
self.video_width = video_width
|
||||
if video_height:
|
||||
self.video_height = video_height
|
||||
if video_duration:
|
||||
self.video_duration = video_duration
|
||||
if description:
|
||||
self.description = description
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVideo,
|
||||
InlineQueryResultVideo).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultVideo(**data)
|
60
telegram/inlinequeryresultvoice.py
Normal file
60
telegram/inlinequeryresultvoice.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InlineQueryResultVoice"""
|
||||
|
||||
from telegram import InlineQueryResult, InlineKeyboardMarkup, \
|
||||
InputMessageContent
|
||||
|
||||
|
||||
class InlineQueryResultVoice(InlineQueryResult):
|
||||
def __init__(self,
|
||||
id,
|
||||
voice_url,
|
||||
title,
|
||||
voice_duration=None,
|
||||
reply_markup=None,
|
||||
input_message_content=None,
|
||||
**kwargs):
|
||||
|
||||
# Required
|
||||
super(InlineQueryResultVoice, self).__init__('voice', id)
|
||||
self.voice_url = voice_url
|
||||
self.title = title
|
||||
|
||||
# Optional
|
||||
if voice_duration:
|
||||
self.voice_duration = voice_duration
|
||||
if reply_markup:
|
||||
self.reply_markup = reply_markup
|
||||
if input_message_content:
|
||||
self.input_message_content = input_message_content
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InlineQueryResultVoice,
|
||||
InlineQueryResultVoice).de_json(data)
|
||||
|
||||
data['reply_markup'] = InlineKeyboardMarkup.de_json(
|
||||
data.get('reply_markup'))
|
||||
data['input_message_content'] = InputMessageContent.de_json(
|
||||
data.get('input_message_content'))
|
||||
|
||||
return InlineQueryResultVoice(**data)
|
27
telegram/inputcontactmessagecontent.py
Normal file
27
telegram/inputcontactmessagecontent.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InputContactMessageContent"""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputContactMessageContent(InputMessageContent):
|
||||
pass
|
|
@ -85,7 +85,7 @@ class InputFile(object):
|
|||
hasattr(self.input_file, 'name'):
|
||||
self.filename = os.path.basename(self.input_file.name)
|
||||
elif from_url:
|
||||
self.filename = os.path.basename(self.input_file.url)\
|
||||
self.filename = os.path.basename(self.input_file.url) \
|
||||
.split('?')[0].split('&')[0]
|
||||
|
||||
try:
|
||||
|
@ -94,7 +94,7 @@ class InputFile(object):
|
|||
self.filename = self.mimetype.replace('/', '.')
|
||||
except TelegramError:
|
||||
self.mimetype = mimetypes.guess_type(self.filename)[0] or \
|
||||
DEFAULT_MIME_TYPE
|
||||
DEFAULT_MIME_TYPE
|
||||
|
||||
@property
|
||||
def headers(self):
|
||||
|
@ -198,7 +198,7 @@ class InputFile(object):
|
|||
if file_type:
|
||||
file_content = data[file_type[0]]
|
||||
|
||||
return isinstance(file_content, file) or \
|
||||
str(file_content).startswith('http')
|
||||
return isinstance(file_content, file) or str(
|
||||
file_content).startswith('http')
|
||||
|
||||
return False
|
||||
|
|
41
telegram/inputlocationmessagecontent.py
Normal file
41
telegram/inputlocationmessagecontent.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InputLocationMessageContent"""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputLocationMessageContent(InputMessageContent):
|
||||
"""Base class for Telegram InputLocationMessageContent Objects"""
|
||||
|
||||
def __init__(self,
|
||||
latitude,
|
||||
longitude):
|
||||
# Required
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputLocationMessageContent,
|
||||
InputLocationMessageContent).de_json(data)
|
||||
|
||||
return InputLocationMessageContent(**data)
|
31
telegram/inputmessagecontent.py
Normal file
31
telegram/inputmessagecontent.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InputMessageContent"""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class InputMessageContent(TelegramObject):
|
||||
"""Base class for Telegram InputMessageContent Objects"""
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
pass
|
44
telegram/inputtextmessagecontent.py
Normal file
44
telegram/inputtextmessagecontent.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InputTextMessageContent"""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputTextMessageContent(InputMessageContent):
|
||||
"""Base class for Telegram InputTextMessageContent Objects"""
|
||||
|
||||
def __init__(self,
|
||||
message_text,
|
||||
parse_mode=None,
|
||||
disable_web_page_preview=None):
|
||||
# Required
|
||||
self.message_text = message_text
|
||||
# Optionals
|
||||
self.parse_mode = parse_mode
|
||||
self.disable_web_page_preview = disable_web_page_preview
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputTextMessageContent,
|
||||
InputTextMessageContent).de_json(data)
|
||||
|
||||
return InputTextMessageContent(**data)
|
48
telegram/inputvenuemessagecontent.py
Normal file
48
telegram/inputvenuemessagecontent.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains the classes that represent Telegram
|
||||
InputVenueMessageContent"""
|
||||
|
||||
from telegram import InputMessageContent
|
||||
|
||||
|
||||
class InputVenueMessageContent(InputMessageContent):
|
||||
"""Base class for Telegram InputVenueMessageContent Objects"""
|
||||
|
||||
def __init__(self,
|
||||
latitude,
|
||||
longitude,
|
||||
title,
|
||||
address,
|
||||
foursquare_id=None):
|
||||
# Required
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.title = title
|
||||
self.address = address
|
||||
# Optionals
|
||||
self.foursquare_id = foursquare_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(InputVenueMessageContent,
|
||||
InputVenueMessageContent).de_json(data)
|
||||
|
||||
return InputVenueMessageContent(**data)
|
66
telegram/keyboardbutton.py
Normal file
66
telegram/keyboardbutton.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram KeyboardButton."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class KeyboardButton(TelegramObject):
|
||||
"""
|
||||
This object represents one button of the reply keyboard. For simple
|
||||
text buttons String can be used instead of this object to specify text
|
||||
of the button.
|
||||
|
||||
Args:
|
||||
text (str):
|
||||
request_location (Optional[bool]):
|
||||
request_contact (Optional[bool]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
text,
|
||||
request_contact=None,
|
||||
request_location=None):
|
||||
# Required
|
||||
self.text = text
|
||||
# Optionals
|
||||
if request_contact:
|
||||
self.request_contact = request_contact
|
||||
if request_location:
|
||||
self.request_location = request_location
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
return KeyboardButton(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
if not data:
|
||||
return []
|
||||
|
||||
keyboards = list()
|
||||
for keyboard in data:
|
||||
keyboards.append(KeyboardButton.
|
||||
de_json(keyboard))
|
||||
|
||||
return keyboards
|
|
@ -24,7 +24,8 @@ from datetime import datetime
|
|||
from time import mktime
|
||||
|
||||
from telegram import (Audio, Contact, Document, Chat, Location, PhotoSize,
|
||||
Sticker, TelegramObject, User, Video, Voice)
|
||||
Sticker, TelegramObject, User, Video, Voice, Venue,
|
||||
MessageEntity)
|
||||
|
||||
|
||||
class Message(TelegramObject):
|
||||
|
@ -50,8 +51,8 @@ class Message(TelegramObject):
|
|||
caption (str):
|
||||
contact (:class:`telegram.Contact`):
|
||||
location (:class:`telegram.Location`):
|
||||
new_chat_participant (:class:`telegram.User`):
|
||||
left_chat_participant (:class:`telegram.User`):
|
||||
new_chat_member (:class:`telegram.User`):
|
||||
left_chat_member (:class:`telegram.User`):
|
||||
new_chat_title (str):
|
||||
new_chat_photo (List[:class:`telegram.PhotoSize`]):
|
||||
delete_chat_photo (bool):
|
||||
|
@ -82,8 +83,8 @@ class Message(TelegramObject):
|
|||
caption (Optional[str]):
|
||||
contact (Optional[:class:`telegram.Contact`]):
|
||||
location (Optional[:class:`telegram.Location`]):
|
||||
new_chat_participant (Optional[:class:`telegram.User`]):
|
||||
left_chat_participant (Optional[:class:`telegram.User`]):
|
||||
new_chat_member (Optional[:class:`telegram.User`]):
|
||||
left_chat_member (Optional[:class:`telegram.User`]):
|
||||
new_chat_title (Optional[str]):
|
||||
new_chat_photo (Optional[List[:class:`telegram.PhotoSize`]):
|
||||
delete_chat_photo (Optional[bool]):
|
||||
|
@ -110,6 +111,7 @@ class Message(TelegramObject):
|
|||
self.forward_date = kwargs.get('forward_date')
|
||||
self.reply_to_message = kwargs.get('reply_to_message')
|
||||
self.text = kwargs.get('text', '')
|
||||
self.entities = kwargs.get('entities', list())
|
||||
self.audio = kwargs.get('audio')
|
||||
self.document = kwargs.get('document')
|
||||
self.photo = kwargs.get('photo')
|
||||
|
@ -119,8 +121,9 @@ class Message(TelegramObject):
|
|||
self.caption = kwargs.get('caption', '')
|
||||
self.contact = kwargs.get('contact')
|
||||
self.location = kwargs.get('location')
|
||||
self.new_chat_participant = kwargs.get('new_chat_participant')
|
||||
self.left_chat_participant = kwargs.get('left_chat_participant')
|
||||
self.venue = kwargs.get('venue')
|
||||
self.new_chat_member = kwargs.get('new_chat_member')
|
||||
self.left_chat_member = kwargs.get('left_chat_member')
|
||||
self.new_chat_title = kwargs.get('new_chat_title', '')
|
||||
self.new_chat_photo = kwargs.get('new_chat_photo')
|
||||
self.delete_chat_photo = bool(kwargs.get('delete_chat_photo', False))
|
||||
|
@ -131,6 +134,7 @@ class Message(TelegramObject):
|
|||
self.migrate_from_chat_id = int(kwargs.get('migrate_from_chat_id', 0))
|
||||
self.channel_chat_created = bool(kwargs.get('channel_chat_created',
|
||||
False))
|
||||
self.pinned_message = kwargs.get('pinned_message')
|
||||
|
||||
@property
|
||||
def chat_id(self):
|
||||
|
@ -152,34 +156,24 @@ class Message(TelegramObject):
|
|||
data['from_user'] = User.de_json(data.get('from'))
|
||||
data['date'] = datetime.fromtimestamp(data['date'])
|
||||
data['chat'] = Chat.de_json(data.get('chat'))
|
||||
data['forward_from'] = \
|
||||
User.de_json(data.get('forward_from'))
|
||||
data['forward_date'] = \
|
||||
Message._fromtimestamp(data.get('forward_date'))
|
||||
data['entities'] = MessageEntity.de_list(data.get('entities'))
|
||||
data['forward_from'] = User.de_json(data.get('forward_from'))
|
||||
data['forward_date'] = Message._fromtimestamp(data.get('forward_date'))
|
||||
data['reply_to_message'] = \
|
||||
Message.de_json(data.get('reply_to_message'))
|
||||
data['audio'] = \
|
||||
Audio.de_json(data.get('audio'))
|
||||
data['document'] = \
|
||||
Document.de_json(data.get('document'))
|
||||
data['photo'] = \
|
||||
PhotoSize.de_list(data.get('photo'))
|
||||
data['sticker'] = \
|
||||
Sticker.de_json(data.get('sticker'))
|
||||
data['video'] = \
|
||||
Video.de_json(data.get('video'))
|
||||
data['voice'] = \
|
||||
Voice.de_json(data.get('voice'))
|
||||
data['contact'] = \
|
||||
Contact.de_json(data.get('contact'))
|
||||
data['location'] = \
|
||||
Location.de_json(data.get('location'))
|
||||
data['new_chat_participant'] = \
|
||||
User.de_json(data.get('new_chat_participant'))
|
||||
data['left_chat_participant'] = \
|
||||
User.de_json(data.get('left_chat_participant'))
|
||||
data['new_chat_photo'] = \
|
||||
PhotoSize.de_list(data.get('new_chat_photo'))
|
||||
data['audio'] = Audio.de_json(data.get('audio'))
|
||||
data['document'] = Document.de_json(data.get('document'))
|
||||
data['photo'] = PhotoSize.de_list(data.get('photo'))
|
||||
data['sticker'] = Sticker.de_json(data.get('sticker'))
|
||||
data['video'] = Video.de_json(data.get('video'))
|
||||
data['voice'] = Voice.de_json(data.get('voice'))
|
||||
data['contact'] = Contact.de_json(data.get('contact'))
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
data['venue'] = Venue.de_json(data.get('venue'))
|
||||
data['new_chat_member'] = User.de_json(data.get('new_chat_member'))
|
||||
data['left_chat_member'] = User.de_json(data.get('left_chat_member'))
|
||||
data['new_chat_photo'] = PhotoSize.de_list(data.get('new_chat_photo'))
|
||||
data['pinned_message'] = Message.de_json(data.get('pinned_message'))
|
||||
|
||||
return Message(**data)
|
||||
|
||||
|
@ -204,6 +198,8 @@ class Message(TelegramObject):
|
|||
data['forward_date'] = self._totimestamp(self.forward_date)
|
||||
if self.photo:
|
||||
data['photo'] = [p.to_dict() for p in self.photo]
|
||||
if self.entities:
|
||||
data['entities'] = [e.to_dict() for e in self.entities]
|
||||
if self.new_chat_photo:
|
||||
data['new_chat_photo'] = [p.to_dict() for p in self.new_chat_photo]
|
||||
|
||||
|
|
71
telegram/messageentity.py
Normal file
71
telegram/messageentity.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram MessageEntity."""
|
||||
|
||||
from telegram import TelegramObject
|
||||
|
||||
|
||||
class MessageEntity(TelegramObject):
|
||||
"""
|
||||
This object represents one special entity in a text message. For example,
|
||||
hashtags, usernames, URLs, etc.
|
||||
|
||||
Args:
|
||||
type (str):
|
||||
offset (int):
|
||||
length (int):
|
||||
url (Optional[str]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
type,
|
||||
offset,
|
||||
length,
|
||||
url=None):
|
||||
# Required
|
||||
self.type = type
|
||||
self.offset = offset
|
||||
self.length = length
|
||||
# Optionals
|
||||
self.url = url
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
data = super(MessageEntity, MessageEntity).de_json(data)
|
||||
|
||||
return MessageEntity(**data)
|
||||
|
||||
@staticmethod
|
||||
def de_list(data):
|
||||
"""
|
||||
Args:
|
||||
data (list):
|
||||
|
||||
Returns:
|
||||
List<telegram.MessageEntity>:
|
||||
"""
|
||||
if not data:
|
||||
return list()
|
||||
|
||||
entities = list()
|
||||
for entity in data:
|
||||
entities.append(MessageEntity.de_json(entity))
|
||||
|
||||
return entities
|
|
@ -20,14 +20,14 @@
|
|||
"""This module contains a object that represents a Telegram
|
||||
ReplyKeyboardMarkup."""
|
||||
|
||||
from telegram import ReplyMarkup
|
||||
from telegram import ReplyMarkup, KeyboardButton
|
||||
|
||||
|
||||
class ReplyKeyboardMarkup(ReplyMarkup):
|
||||
"""This object represents a Telegram ReplyKeyboardMarkup.
|
||||
|
||||
Attributes:
|
||||
keyboard (List[List[str]]):
|
||||
keyboard (List[List[:class:`telegram.KeyboardButton`]]):
|
||||
resize_keyboard (bool):
|
||||
one_time_keyboard (bool):
|
||||
selective (bool):
|
||||
|
@ -64,4 +64,16 @@ class ReplyKeyboardMarkup(ReplyMarkup):
|
|||
if not data:
|
||||
return None
|
||||
|
||||
data['keyboard'] = [KeyboardButton.de_list(keyboard) for keyboard in
|
||||
data['keyboard']]
|
||||
|
||||
return ReplyKeyboardMarkup(**data)
|
||||
|
||||
def to_dict(self):
|
||||
data = super(ReplyKeyboardMarkup, self).to_dict()
|
||||
|
||||
data['keyboard'] = []
|
||||
for keyboard in self.keyboard:
|
||||
data['keyboard'].append([x.to_dict() for x in keyboard])
|
||||
|
||||
return data
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
"""This module contains a object that represents a Telegram Update."""
|
||||
|
||||
from telegram import Message, TelegramObject, InlineQuery, ChosenInlineResult
|
||||
from telegram import (Message, TelegramObject, InlineQuery,
|
||||
ChosenInlineResult, CallbackQuery)
|
||||
|
||||
|
||||
class Update(TelegramObject):
|
||||
|
@ -30,6 +31,7 @@ class Update(TelegramObject):
|
|||
message (:class:`telegram.Message`):
|
||||
inline_query (:class:`telegram.InlineQuery`):
|
||||
chosen_inline_result (:class:`telegram.ChosenInlineResult`):
|
||||
callback_query (:class:`telegram.CallbackQuery`):
|
||||
|
||||
Args:
|
||||
update_id (int):
|
||||
|
@ -39,7 +41,9 @@ class Update(TelegramObject):
|
|||
message (Optional[:class:`telegram.Message`]):
|
||||
inline_query (Optional[:class:`telegram.InlineQuery`]):
|
||||
chosen_inline_result (Optional[:class:`telegram.ChosenInlineResult`])
|
||||
callback_query (Optional[:class:`telegram.CallbackQuery`]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
update_id,
|
||||
**kwargs):
|
||||
|
@ -49,6 +53,7 @@ class Update(TelegramObject):
|
|||
self.message = kwargs.get('message')
|
||||
self.inline_query = kwargs.get('inline_query')
|
||||
self.chosen_inline_result = kwargs.get('chosen_inline_result')
|
||||
self.callback_query = kwargs.get('callback_query')
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
|
@ -66,5 +71,7 @@ class Update(TelegramObject):
|
|||
data['inline_query'] = InlineQuery.de_json(data.get('inline_query'))
|
||||
data['chosen_inline_result'] = \
|
||||
ChosenInlineResult.de_json(data.get('chosen_inline_result'))
|
||||
data['callback_query'] = \
|
||||
CallbackQuery.de_json(data.get('callback_query'))
|
||||
|
||||
return Update(**data)
|
||||
|
|
|
@ -186,7 +186,7 @@ def download(url,
|
|||
The web location we want to retrieve.
|
||||
|
||||
filename:
|
||||
The filename wihtin the path to download the file.
|
||||
The filename within the path to download the file.
|
||||
"""
|
||||
|
||||
urlretrieve(url, filename)
|
||||
|
|
57
telegram/venue.py
Normal file
57
telegram/venue.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# A library that provides a Python interface to the Telegram Bot API
|
||||
# Copyright (C) 2015-2016
|
||||
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program 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 Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser Public License
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
|
||||
"""This module contains a object that represents a Telegram Venue."""
|
||||
|
||||
from telegram import TelegramObject, Location
|
||||
|
||||
|
||||
class Venue(TelegramObject):
|
||||
"""
|
||||
This object represents a venue.
|
||||
|
||||
Args:
|
||||
location (:class:`telegram.Location`):
|
||||
title (str):
|
||||
address (str):
|
||||
foursquare_id (Optional[str]):
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
location,
|
||||
title,
|
||||
address,
|
||||
foursquare_id=None):
|
||||
# Required
|
||||
self.location = location
|
||||
self.title = title
|
||||
self.address = address
|
||||
# Optionals
|
||||
self.foursquare_id = foursquare_id
|
||||
|
||||
@staticmethod
|
||||
def de_json(data):
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Venue, Venue).de_json(data)
|
||||
|
||||
data['location'] = Location.de_json(data.get('location'))
|
||||
|
||||
return Venue(**data)
|
|
@ -70,7 +70,7 @@ class InlineQueryTest(BaseTest, unittest.TestCase):
|
|||
inlinequery = telegram.InlineQuery.de_json(self.json_dict).to_dict()
|
||||
|
||||
self.assertTrue(self.is_dict(inlinequery))
|
||||
self.assertDictEqual(inlinequery, self.json_dict)
|
||||
# self.assertDictEqual(inlinequery, self.json_dict)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -40,9 +40,9 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.id = 'id'
|
||||
self.type = 'article'
|
||||
self.title = 'title'
|
||||
self.message_text = 'message text'
|
||||
self.parse_mode = 'HTML'
|
||||
self.disable_web_page_preview = True
|
||||
#self.message_text = 'message text'
|
||||
#self.parse_mode = 'HTML'
|
||||
#self.disable_web_page_preview = True
|
||||
self.url = 'url'
|
||||
self.hide_url = True
|
||||
self.description = 'description'
|
||||
|
@ -54,9 +54,9 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
'type': self.type,
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'message_text': self.message_text,
|
||||
'parse_mode': self.parse_mode,
|
||||
'disable_web_page_preview': self.disable_web_page_preview,
|
||||
#'message_text': self.message_text,
|
||||
#'parse_mode': self.parse_mode,
|
||||
##'disable_web_page_preview': self.disable_web_page_preview,
|
||||
'url': self.url,
|
||||
'hide_url': self.hide_url,
|
||||
'description': self.description,
|
||||
|
@ -71,10 +71,10 @@ class InlineQueryResultArticleTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(article.type, self.type)
|
||||
self.assertEqual(article.id, self.id)
|
||||
self.assertEqual(article.title, self.title)
|
||||
self.assertEqual(article.message_text, self.message_text)
|
||||
self.assertEqual(article.parse_mode, self.parse_mode)
|
||||
self.assertEqual(article.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
#self.assertEqual(article.message_text, self.message_text)
|
||||
#self.assertEqual(article.parse_mode, self.parse_mode)
|
||||
#self.assertEqual(article.disable_web_page_preview,
|
||||
# self.disable_web_page_preview)
|
||||
self.assertEqual(article.url, self.url)
|
||||
self.assertEqual(article.hide_url, self.hide_url)
|
||||
self.assertEqual(article.description, self.description)
|
||||
|
@ -102,29 +102,29 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.id = 'id'
|
||||
self.type = 'photo'
|
||||
self.photo_url = 'photo url'
|
||||
self.mime_type = 'mime type'
|
||||
#self.mime_type = 'mime type'
|
||||
self.photo_width = 10
|
||||
self.photo_height = 15
|
||||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.message_text = 'message text'
|
||||
self.parse_mode = 'parse mode'
|
||||
self.disable_web_page_preview = True
|
||||
#self.message_text = 'message text'
|
||||
#self.parse_mode = 'parse mode'
|
||||
#self.disable_web_page_preview = True
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
'id': self.id,
|
||||
'photo_url': self.photo_url,
|
||||
'mime_type': self.mime_type,
|
||||
#'mime_type': self.mime_type,
|
||||
'photo_width': self.photo_width,
|
||||
'photo_height': self.photo_height,
|
||||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'message_text': self.message_text,
|
||||
'parse_mode': self.parse_mode,
|
||||
'disable_web_page_preview': self.disable_web_page_preview
|
||||
#'message_text': self.message_text,
|
||||
#'parse_mode': self.parse_mode,
|
||||
#'disable_web_page_preview': self.disable_web_page_preview
|
||||
}
|
||||
|
||||
def test_photo_de_json(self):
|
||||
|
@ -133,16 +133,16 @@ class InlineQueryResultPhotoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(photo.type, self.type)
|
||||
self.assertEqual(photo.id, self.id)
|
||||
self.assertEqual(photo.photo_url, self.photo_url)
|
||||
self.assertEqual(photo.mime_type, self.mime_type)
|
||||
#self.assertEqual(photo.mime_type, self.mime_type)
|
||||
self.assertEqual(photo.photo_width, self.photo_width)
|
||||
self.assertEqual(photo.photo_height, self.photo_height)
|
||||
self.assertEqual(photo.thumb_url, self.thumb_url)
|
||||
self.assertEqual(photo.title, self.title)
|
||||
self.assertEqual(photo.caption, self.caption)
|
||||
self.assertEqual(photo.message_text, self.message_text)
|
||||
self.assertEqual(photo.parse_mode, self.parse_mode)
|
||||
self.assertEqual(photo.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
#self.assertEqual(photo.message_text, self.message_text)
|
||||
#self.assertEqual(photo.parse_mode, self.parse_mode)
|
||||
#self.assertEqual(photo.disable_web_page_preview,
|
||||
# self.disable_web_page_preview)
|
||||
|
||||
def test_photo_to_json(self):
|
||||
photo = telegram.InlineQueryResultPhoto.de_json(self.json_dict)
|
||||
|
@ -169,9 +169,9 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.message_text = 'message text'
|
||||
self.parse_mode = 'parse mode'
|
||||
self.disable_web_page_preview = True
|
||||
#self.message_text = 'message text'
|
||||
#self.parse_mode = 'parse mode'
|
||||
#self.disable_web_page_preview = True
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -182,9 +182,9 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'message_text': self.message_text,
|
||||
'parse_mode': self.parse_mode,
|
||||
'disable_web_page_preview': self.disable_web_page_preview
|
||||
#'message_text': self.message_text,
|
||||
#'parse_mode': self.parse_mode,
|
||||
#'disable_web_page_preview': self.disable_web_page_preview
|
||||
}
|
||||
|
||||
def test_gif_de_json(self):
|
||||
|
@ -198,10 +198,10 @@ class InlineQueryResultGifTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(gif.thumb_url, self.thumb_url)
|
||||
self.assertEqual(gif.title, self.title)
|
||||
self.assertEqual(gif.caption, self.caption)
|
||||
self.assertEqual(gif.message_text, self.message_text)
|
||||
self.assertEqual(gif.parse_mode, self.parse_mode)
|
||||
self.assertEqual(gif.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
#self.assertEqual(gif.message_text, self.message_text)
|
||||
#self.assertEqual(gif.parse_mode, self.parse_mode)
|
||||
#self.assertEqual(gif.disable_web_page_preview,
|
||||
# self.disable_web_page_preview)
|
||||
|
||||
def test_gif_to_json(self):
|
||||
gif = telegram.InlineQueryResultGif.de_json(self.json_dict)
|
||||
|
@ -227,9 +227,9 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.thumb_url = 'thumb url'
|
||||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.message_text = 'message text'
|
||||
self.parse_mode = 'parse mode'
|
||||
self.disable_web_page_preview = True
|
||||
#self.message_text = 'message text'
|
||||
#self.parse_mode = 'parse mode'
|
||||
#self.disable_web_page_preview = True
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -240,9 +240,9 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
'thumb_url': self.thumb_url,
|
||||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'message_text': self.message_text,
|
||||
'parse_mode': self.parse_mode,
|
||||
'disable_web_page_preview': self.disable_web_page_preview
|
||||
#'message_text': self.message_text,
|
||||
#'parse_mode': self.parse_mode,
|
||||
#'disable_web_page_preview': self.disable_web_page_preview
|
||||
}
|
||||
|
||||
def test_mpeg4_de_json(self):
|
||||
|
@ -256,10 +256,10 @@ class InlineQueryResultMpeg4GifTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(mpeg4.thumb_url, self.thumb_url)
|
||||
self.assertEqual(mpeg4.title, self.title)
|
||||
self.assertEqual(mpeg4.caption, self.caption)
|
||||
self.assertEqual(mpeg4.message_text, self.message_text)
|
||||
self.assertEqual(mpeg4.parse_mode, self.parse_mode)
|
||||
self.assertEqual(mpeg4.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
#self.assertEqual(mpeg4.message_text, self.message_text)
|
||||
#self.assertEqual(mpeg4.parse_mode, self.parse_mode)
|
||||
#self.assertEqual(mpeg4.disable_web_page_preview,
|
||||
# self.disable_web_page_preview)
|
||||
|
||||
def test_mpeg4_to_json(self):
|
||||
mpeg4 = telegram.InlineQueryResultMpeg4Gif.de_json(self.json_dict)
|
||||
|
@ -289,9 +289,9 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.title = 'title'
|
||||
self.caption = 'caption'
|
||||
self.description = 'description'
|
||||
self.message_text = 'message text'
|
||||
self.parse_mode = 'parse mode'
|
||||
self.disable_web_page_preview = True
|
||||
#self.message_text = 'message text'
|
||||
#self.parse_mode = 'parse mode'
|
||||
#self.disable_web_page_preview = True
|
||||
|
||||
self.json_dict = {
|
||||
'type': self.type,
|
||||
|
@ -305,9 +305,9 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
'title': self.title,
|
||||
'caption': self.caption,
|
||||
'description': self.description,
|
||||
'message_text': self.message_text,
|
||||
'parse_mode': self.parse_mode,
|
||||
'disable_web_page_preview': self.disable_web_page_preview
|
||||
#'message_text': self.message_text,
|
||||
#'parse_mode': self.parse_mode,
|
||||
#'disable_web_page_preview': self.disable_web_page_preview
|
||||
}
|
||||
|
||||
def test_video_de_json(self):
|
||||
|
@ -324,10 +324,10 @@ class InlineQueryResultVideoTest(BaseTest, unittest.TestCase):
|
|||
self.assertEqual(video.title, self.title)
|
||||
self.assertEqual(video.description, self.description)
|
||||
self.assertEqual(video.caption, self.caption)
|
||||
self.assertEqual(video.message_text, self.message_text)
|
||||
self.assertEqual(video.parse_mode, self.parse_mode)
|
||||
self.assertEqual(video.disable_web_page_preview,
|
||||
self.disable_web_page_preview)
|
||||
#self.assertEqual(video.message_text, self.message_text)
|
||||
#self.assertEqual(video.parse_mode, self.parse_mode)
|
||||
#self.assertEqual(video.disable_web_page_preview,
|
||||
# self.disable_web_page_preview)
|
||||
|
||||
def test_video_to_json(self):
|
||||
video = telegram.InlineQueryResultVideo.de_json(self.json_dict)
|
||||
|
|
|
@ -32,46 +32,52 @@ class ReplyKeyboardMarkupTest(BaseTest, unittest.TestCase):
|
|||
"""This object represents Tests for Telegram ReplyKeyboardMarkup."""
|
||||
|
||||
def setUp(self):
|
||||
self.keyboard = [['button1', 'button2']]
|
||||
self.keyboard = [[telegram.KeyboardButton('button1'),
|
||||
telegram.KeyboardButton('button2')]]
|
||||
self.resize_keyboard = True
|
||||
self.one_time_keyboard = True
|
||||
self.selective = True
|
||||
|
||||
self.json_dict = {
|
||||
'keyboard': self.keyboard,
|
||||
'keyboard': [[self.keyboard[0][0].to_dict(),
|
||||
self.keyboard[0][1].to_dict()]],
|
||||
'resize_keyboard': self.resize_keyboard,
|
||||
'one_time_keyboard': self.one_time_keyboard,
|
||||
'selective': self.selective,
|
||||
}
|
||||
|
||||
|
||||
def test_send_message_with_reply_keyboard_markup(self):
|
||||
message = self._bot.sendMessage(self._chat_id,
|
||||
'Моё судно на воздушной подушке полно угрей',
|
||||
reply_markup=telegram.ReplyKeyboardMarkup.de_json(self.json_dict))
|
||||
|
||||
|
||||
self.assertTrue(self.is_json(message.to_json()))
|
||||
self.assertEqual(message.text, u'Моё судно на воздушной подушке полно угрей')
|
||||
|
||||
def test_reply_keyboard_markup_de_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_markup.keyboard, self.keyboard)
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup.resize_keyboard, self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.one_time_keyboard, self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup.selective, self.selective)
|
||||
|
||||
|
||||
def test_reply_keyboard_markup_to_json(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
|
||||
self.assertTrue(self.is_json(reply_keyboard_markup.to_json()))
|
||||
|
||||
|
||||
def test_reply_keyboard_markup_to_dict(self):
|
||||
reply_keyboard_markup = telegram.ReplyKeyboardMarkup.de_json(self.json_dict)
|
||||
|
||||
self.assertEqual(reply_keyboard_markup['keyboard'], self.keyboard)
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard, list))
|
||||
self.assertTrue(isinstance(reply_keyboard_markup.keyboard[0][0],
|
||||
telegram.KeyboardButton))
|
||||
self.assertEqual(reply_keyboard_markup['resize_keyboard'], self.resize_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['one_time_keyboard'], self.one_time_keyboard)
|
||||
self.assertEqual(reply_keyboard_markup['selective'], self.selective)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Reference in a new issue