Skip to content
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ make the development of bots easy and straightforward. These classes are contain
Telegram API support
====================

As of **23. July 2017**, all types and methods of the Telegram Bot API 3.2 are supported.
All types and methods of the Telegram Bot API 3.4 are supported.

==========
Installing
Expand Down
178 changes: 177 additions & 1 deletion telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ def send_location(self,
reply_markup=None,
timeout=None,
location=None,
live_period=None,
**kwargs):
"""Use this method to send point on the map.

Expand All @@ -783,6 +784,8 @@ def send_location(self,
latitude (:obj:`float`, optional): Latitude of location.
longitude (:obj:`float`, optional): Longitude of location.
location (:class:`telegram.Location`, optional): The location to send.
live_period (:obj:`int`, optional): Period in seconds for which the location will be
updated, should be between 60 and 86400.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
reply_to_message_id (:obj:`int`, optional): If the message is a reply, ID of the
Expand All @@ -806,14 +809,126 @@ def send_location(self,

if not (all([latitude, longitude]) or location):
raise ValueError("Either location or latitude and longitude must be passed as"
"argument")
"argument.")

if not ((latitude is not None or longitude is not None) ^ bool(location)):
raise ValueError("Either location or latitude and longitude must be passed as"
"argument. Not both.")

if isinstance(location, Location):
latitude = location.latitude
longitude = location.longitude

data = {'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude}

if live_period:
data['live_period'] = live_period

return url, data

@log
@message
def edit_message_live_location(self,
chat_id=None,
message_id=None,
inline_message_id=None,
latitude=None,
longitude=None,
location=None,
reply_markup=None,
**kwargs):
"""Use this method to edit live location messages sent by the bot or via the bot
(for inline bots). A location can be edited until its :attr:`live_period` expires or
editing is explicitly disabled by a call to :attr:`stop_message_live_location`.

Note:
You can either supply a :obj:`latitude` and :obj:`longitude` or a :obj:`location`.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
message_id (:obj:`int`, optional): Required if inline_message_id is not specified.
Identifier of the sent message.
inline_message_id (:obj:`str`, optional): Required if chat_id and message_id are not
specified. Identifier of the inline message.
latitude (:obj:`float`, optional): Latitude of location.
longitude (:obj:`float`, optional): Longitude of location.
location (:class:`telegram.Location`, optional): The location to send.
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to remove reply keyboard or to force a reply from the user.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).

Returns:
:class:`telegram.Message`: On success the edited message.
"""

url = '{0}/editMessageLiveLocation'.format(self.base_url)

if not (all([latitude, longitude]) or location):
raise ValueError("Either location or latitude and longitude must be passed as"
"argument.")
if not ((latitude is not None or longitude is not None) ^ bool(location)):
raise ValueError("Either location or latitude and longitude must be passed as"
"argument. Not both.")

if isinstance(location, Location):
latitude = location.latitude
longitude = location.longitude

data = {'latitude': latitude, 'longitude': longitude}

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 stop_message_live_location(self,
chat_id=None,
message_id=None,
inline_message_id=None,
reply_markup=None,
**kwargs):
"""Use this method to stop updating a live location message sent by the bot or via the bot
(for inline bots) before live_period expires.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target channel (in the format @channelusername).
message_id (:obj:`int`, optional): Required if inline_message_id is not specified.
Identifier of the sent message.
inline_message_id (:obj:`str`, optional): Required if chat_id and message_id are not
specified. Identifier of the inline message.
reply_markup (:class:`telegram.ReplyMarkup`, optional): Additional interface options. A
JSON-serialized object for an inline keyboard, custom reply keyboard, instructions
to remove reply keyboard or to force a reply from the user.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).

Returns:
:class:`telegram.Message`: On success the edited message.
"""

url = '{0}/stopMessageLiveLocation'.format(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
Expand Down Expand Up @@ -1828,6 +1943,63 @@ def get_chat_member(self, chat_id, user_id, timeout=None, **kwargs):

return ChatMember.de_json(result, self)

@log
def set_chat_sticker_set(self, chat_id, sticker_set_name, timeout=None, **kwargs):
"""Use this method to set a new group sticker set for a supergroup.
The bot must be an administrator in the chat for this to work and must have the appropriate
admin rights. Use the field :attr:`telegram.Chat.can_set_sticker_set` optionally returned
in :attr:`get_chat` requests to check if the bot can use this method.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target supergroup (in the format @supergroupusername).
sticker_set_name (:obj:`str`): Name of the sticker set to be set as the group
sticker set.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.


Returns:
:obj:`bool`: True on success.
"""

url = '{0}/setChatStickerSet'.format(self.base_url)

data = {'chat_id': chat_id, 'sticker_set_name': sticker_set_name}

result = self._request.post(url, data, timeout=timeout)

return result

@log
def delete_chat_sticker_set(self, chat_id, timeout=None, **kwargs):
"""Use this method to delete a group sticker set from a supergroup. The bot must be an
administrator in the chat for this to work and must have the appropriate admin rights.
Use the field :attr:`telegram.Chat.can_set_sticker_set` optionally returned in
:attr:`get_chat` requests to check if the bot can use this method.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
of the target supergroup (in the format @supergroupusername).
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
the read timeout from the server (instead of the one specified during creation of
the connection pool).
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

Returns:
:obj:`bool`: True on success.
"""

url = '{0}/deleteChatStickerSet'.format(self.base_url)

data = {'chat_id': chat_id}

result = self._request.post(url, data, timeout=timeout)

return result

def get_webhook_info(self, timeout=None, **kwargs):
"""Use this method to get current webhook status. Requires no parameters.

Expand Down Expand Up @@ -2797,6 +2969,8 @@ def __reduce__(self):
sendVoice = send_voice
sendVideoNote = send_video_note
sendLocation = send_location
editMessageLiveLocation = edit_message_live_location
stopMessageLiveLocation = stop_message_live_location
sendVenue = send_venue
sendContact = send_contact
sendGame = send_game
Expand All @@ -2817,6 +2991,8 @@ def __reduce__(self):
getChat = get_chat
getChatAdministrators = get_chat_administrators
getChatMember = get_chat_member
setChatStickerSet = set_chat_sticker_set
deleteChatStickerSet = delete_chat_sticker_set
getChatMembersCount = get_chat_members_count
getWebhookInfo = get_webhook_info
setGameScore = set_game_score
Expand Down
11 changes: 11 additions & 0 deletions telegram/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class Chat(TelegramObject):
invite_link (:obj:`str`): Optional. Chat invite link, for supergroups and channel chats.
pinned_message (:class:`telegram.Message`): Optional. Pinned message, for supergroups.
Returned only in get_chat.
sticker_set_name (:obj:`str`): Optional. For supergroups, name of Group sticker set.
can_set_sticker_set (:obj:`bool`): Optional. ``True``, if the bot can change group the
sticker set.

Args:
id (:obj:`int`): Unique identifier for this chat. This number may be greater than 32 bits
Expand All @@ -61,6 +64,10 @@ class Chat(TelegramObject):
pinned_message (:class:`telegram.Message`, optional): Pinned message, for supergroups.
Returned only in get_chat.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
sticker_set_name (:obj:`str`, optional): For supergroups, name of Group sticker set.
Returned only in get_chat.
can_set_sticker_set (:obj:`bool`, optional): ``True``, if the bot can change group the
sticker set. Returned only in get_chat.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""
Expand All @@ -87,6 +94,8 @@ def __init__(self,
description=None,
invite_link=None,
pinned_message=None,
sticker_set_name=None,
can_set_sticker_set=None,
**kwargs):
# Required
self.id = int(id)
Expand All @@ -101,6 +110,8 @@ def __init__(self,
self.description = description
self.invite_link = invite_link
self.pinned_message = pinned_message
self.sticker_set_name = sticker_set_name
self.can_set_sticker_set = can_set_sticker_set

self.bot = bot
self._id_attrs = (self.id,)
Expand Down
7 changes: 7 additions & 0 deletions telegram/inline/inlinequeryresultlocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class InlineQueryResultLocation(InlineQueryResult):
latitude (:obj:`float`): Location latitude in degrees.
longitude (:obj:`float`): Location longitude in degrees.
title (:obj:`str`): Location title.
live_period (:obj:`int`): Optional. Period in seconds for which the location can be
updated, should be between 60 and 86400.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
Expand All @@ -46,6 +48,8 @@ class InlineQueryResultLocation(InlineQueryResult):
latitude (:obj:`float`): Location latitude in degrees.
longitude (:obj:`float`): Location longitude in degrees.
title (:obj:`str`): Location title.
live_period (:obj:`int`, optional): Period in seconds for which the location can be
updated, should be between 60 and 86400.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
Expand All @@ -62,6 +66,7 @@ def __init__(self,
latitude,
longitude,
title,
live_period=None,
reply_markup=None,
input_message_content=None,
thumb_url=None,
Expand All @@ -75,6 +80,8 @@ def __init__(self,
self.title = title

# Optionals
if live_period:
self.live_period = live_period
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:
Expand Down
5 changes: 4 additions & 1 deletion telegram/inline/inputlocationmessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ class InputLocationMessageContent(InputMessageContent):
Args:
latitude (:obj:`float`): Latitude of the location in degrees.
longitude (:obj:`float`): Longitude of the location in degrees.
live_period (:obj:`int`, optional): Period in seconds for which the location can be
updated, should be between 60 and 86400.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, latitude, longitude, **kwargs):
def __init__(self, latitude, longitude, live_period=None, **kwargs):
# Required
self.latitude = latitude
self.longitude = longitude
self.live_period = live_period
Loading