Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/telegram.proximityalerttriggered.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
telegram.ProximityAlertTriggered
================================

.. autoclass:: telegram.ProximityAlertTriggered
:members:
:show-inheritance:
2 changes: 2 additions & 0 deletions telegram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .games.game import Game
from .poll import Poll, PollOption, PollAnswer
from .loginurl import LoginUrl
from .proximityalerttriggered import ProximityAlertTriggered
from .games.callbackgame import CallbackGame
from .payment.shippingaddress import ShippingAddress
from .payment.orderinfo import OrderInfo
Expand Down Expand Up @@ -189,6 +190,7 @@
'InputTextMessageContent',
'InputVenueMessageContent',
'Location',
'ProximityAlertTriggered',
'EncryptedCredentials',
'PassportFile',
'EncryptedPassportElement',
Expand Down
32 changes: 32 additions & 0 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,9 @@ def send_location(
location: Location = None,
live_period: int = None,
api_kwargs: JSONDict = None,
horizontal_accuracy: float = None,
heading: int = None,
proximity_alert_radius: int = None,
) -> Optional[Message]:
"""Use this method to send point on the map.

Expand All @@ -1333,8 +1336,15 @@ def send_location(
latitude (:obj:`float`, optional): Latitude of location.
longitude (:obj:`float`, optional): Longitude of location.
location (:class:`telegram.Location`, optional): The location to send.
horizontal_accuracy (:obj:`int`, optional): The radius of uncertainty for the location,
measured in meters; 0-1500.
live_period (:obj:`int`, optional): Period in seconds for which the location will be
updated, should be between 60 and 86400.
heading (:obj:`int`, optional): For live locations, a direction in which the user is
moving, in degrees. Must be between 1 and 360 if specified.
proximity_alert_radius (:obj:`int`, optional): For live locations, a maximum distance
for proximity alerts about approaching another chat member, in meters. Must be
between 1 and 100000 if specified.
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 Down Expand Up @@ -1373,6 +1383,12 @@ def send_location(

if live_period:
data['live_period'] = live_period
if horizontal_accuracy:
data['horizontal_accuracy'] = horizontal_accuracy
if heading:
data['heading'] = heading
if proximity_alert_radius:
data['proximity_alert_radius'] = proximity_alert_radius

return self._message( # type: ignore[return-value]
'sendLocation',
Expand All @@ -1396,6 +1412,9 @@ def edit_message_live_location(
reply_markup: ReplyMarkup = None,
timeout: float = None,
api_kwargs: JSONDict = None,
horizontal_accuracy: float = None,
heading: int = None,
proximity_alert_radius: int = None,
) -> Union[Optional[Message], bool]:
"""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
Expand All @@ -1415,6 +1434,13 @@ def edit_message_live_location(
latitude (:obj:`float`, optional): Latitude of location.
longitude (:obj:`float`, optional): Longitude of location.
location (:class:`telegram.Location`, optional): The location to send.
horizontal_accuracy (:obj:`float`, optional): The radius of uncertainty for the
location, measured in meters; 0-1500.
heading (:obj:`int`, optional): Direction in which the user is moving, in degrees. Must
be between 1 and 360 if specified.
proximity_alert_radius (:obj:`int`, optional): Maximum distance for proximity alerts
about approaching another chat member, in meters. Must be between 1 and 100000 if
specified.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): A JSON-serialized
object for a new inline keyboard.
timeout (:obj:`int` | :obj:`float`, optional): If this value is specified, use it as
Expand Down Expand Up @@ -1448,6 +1474,12 @@ def edit_message_live_location(
data['message_id'] = message_id
if inline_message_id:
data['inline_message_id'] = inline_message_id
if horizontal_accuracy:
data['horizontal_accuracy'] = horizontal_accuracy
if heading:
data['heading'] = heading
if proximity_alert_radius:
data['proximity_alert_radius'] = proximity_alert_radius

return self._message(
'editMessageLiveLocation',
Expand Down
14 changes: 14 additions & 0 deletions telegram/ext/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,15 @@ def filter(self, message: Message) -> bool:
connected_website = _ConnectedWebsite()
"""Messages that contain :attr:`telegram.Message.connected_website`."""

class _ProximityAlertTriggered(MessageFilter):
name = 'Filters.status_update.proximity_alert_triggered'

def filter(self, message: Message) -> bool:
return bool(message.proximity_alert_triggered)

proximity_alert_triggered = _ProximityAlertTriggered()
"""Messages that contain :attr:`telegram.Message.proximity_alert_triggered`."""

name = 'Filters.status_update'

def filter(self, message: Update) -> bool:
Expand All @@ -1043,6 +1052,7 @@ def filter(self, message: Update) -> bool:
or self.migrate(message)
or self.pinned_message(message)
or self.connected_website(message)
or self.proximity_alert_triggered(message)
)

status_update = _StatusUpdate()
Expand All @@ -1057,6 +1067,8 @@ def filter(self, message: Update) -> bool:
:attr:`telegram.Message.group_chat_created`,
:attr:`telegram.Message.supergroup_chat_created` or
:attr:`telegram.Message.channel_chat_created`.
connected_website: Messages that contain
:attr:`telegram.Message.connected_website`.
delete_chat_photo: Messages that contain
:attr:`telegram.Message.delete_chat_photo`.
left_chat_member: Messages that contain
Expand All @@ -1072,6 +1084,8 @@ def filter(self, message: Update) -> bool:
:attr:`telegram.Message.new_chat_title`.
pinned_message: Messages that contain
:attr:`telegram.Message.pinned_message`.
proximity_alert_triggered: Messages that contain
:attr:`telegram.Message.proximity_alert_triggered`.
"""

class _Forwarded(MessageFilter):
Expand Down
35 changes: 34 additions & 1 deletion telegram/files/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,50 @@ class Location(TelegramObject):
Attributes:
longitude (:obj:`float`): Longitude as defined by sender.
latitude (:obj:`float`): Latitude as defined by sender.
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
measured in meters.
live_period (:obj:`int`): Optional. Time relative to the message sending date, during which
the location can be updated, in seconds. For active live locations only.
heading (:obj:`int`): Optional. The direction in which user is moving, in degrees.
For active live locations only.
proximity_alert_radius (:obj:`int`): Optional. Maximum distance for proximity alerts about
approaching another chat member, in meters. For sent live locations only.

Args:
longitude (:obj:`float`): Longitude as defined by sender.
latitude (:obj:`float`): Latitude as defined by sender.
horizontal_accuracy (:obj:`float`, optional): The radius of uncertainty for the location,
measured in meters; 0-1500.
live_period (:obj:`int`, optional): Time relative to the message sending date, during which
the location can be updated, in seconds. For active live locations only.
heading (:obj:`int`, optional): The direction in which user is moving, in degrees; 1-360.
For active live locations only.
proximity_alert_radius (:obj:`int`, optional): Maximum distance for proximity alerts about
approaching another chat member, in meters. For sent live locations only.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, longitude: float, latitude: float, **_kwargs: Any):
def __init__(
self,
longitude: float,
latitude: float,
horizontal_accuracy: float = None,
live_period: int = None,
heading: int = None,
proximity_alert_radius: int = None,
**_kwargs: Any,
):
# Required
self.longitude = float(longitude)
self.latitude = float(latitude)

# Optionals
self.horizontal_accuracy = float(horizontal_accuracy) if horizontal_accuracy else None
self.live_period = int(live_period) if live_period else None
self.heading = int(heading) if heading else None
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)

self._id_attrs = (self.longitude, self.latitude)
25 changes: 23 additions & 2 deletions telegram/inline/inlinequeryresultlocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ class InlineQueryResultLocation(InlineQueryResult):
latitude (:obj:`float`): Location latitude in degrees.
longitude (:obj:`float`): Location longitude in degrees.
title (:obj:`str`): Location title.
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
measured in meters.
live_period (:obj:`int`): Optional. Period in seconds for which the location can be
updated, should be between 60 and 86400.
heading (:obj:`int`): Optional. For live locations, a direction in which the user is
moving, in degrees.
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance for
proximity alerts about approaching another chat member, in meters.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
Expand All @@ -53,8 +59,15 @@ class InlineQueryResultLocation(InlineQueryResult):
latitude (:obj:`float`): Location latitude in degrees.
longitude (:obj:`float`): Location longitude in degrees.
title (:obj:`str`): Location title.
horizontal_accuracy (:obj:`float`, optional): The radius of uncertainty for the location,
measured in meters; 0-1500.
live_period (:obj:`int`, optional): Period in seconds for which the location can be
updated, should be between 60 and 86400.
heading (:obj:`int`, optional): For live locations, a direction in which the user is
moving, in degrees. Must be between 1 and 360 if specified.
proximity_alert_radius (:obj:`int`, optional): For live locations, a maximum distance for
proximity alerts about approaching another chat member, in meters. Must be between 1
and 100000 if specified.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
Expand All @@ -78,12 +91,15 @@ def __init__(
thumb_url: str = None,
thumb_width: int = None,
thumb_height: int = None,
horizontal_accuracy: float = None,
heading: int = None,
proximity_alert_radius: int = None,
**_kwargs: Any,
):
# Required
super().__init__('location', id)
self.latitude = latitude
self.longitude = longitude
self.latitude = float(latitude)
self.longitude = float(longitude)
self.title = title

# Optionals
Expand All @@ -93,3 +109,8 @@ def __init__(
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = float(horizontal_accuracy) if horizontal_accuracy else None
self.heading = int(heading) if heading else None
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)
27 changes: 25 additions & 2 deletions telegram/inline/inputlocationmessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,44 @@ class InputLocationMessageContent(InputMessageContent):
longitude (:obj:`float`): Longitude of the location in degrees.
live_period (:obj:`int`): Optional. Period in seconds for which the location can be
updated.
heading (:obj:`int`): Optional. For live locations, a direction in which the user is
moving, in degrees.
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance for
proximity alerts about approaching another chat member, in meters.

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.
heading (:obj:`int`, optional): For live locations, a direction in which the user is
moving, in degrees. Must be between 1 and 360 if specified.
proximity_alert_radius (:obj:`int`, optional): For live locations, a maximum distance for
proximity alerts about approaching another chat member, in meters. Must be between 1
and 100000 if specified.
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""
# fmt: on

def __init__(self, latitude: float, longitude: float, live_period: int = None, **_kwargs: Any):
def __init__(
self,
latitude: float,
longitude: float,
live_period: int = None,
heading: int = None,
proximity_alert_radius: int = None,
**_kwargs: Any,
):
# Required
self.latitude = latitude
self.longitude = longitude
self.live_period = live_period

# Optionals
self.live_period = int(live_period) if live_period else None
self.heading = int(heading) if heading else None
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)

self._id_attrs = (self.latitude, self.longitude)
13 changes: 13 additions & 0 deletions telegram/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
Video,
VideoNote,
Voice,
ProximityAlertTriggered,
)
from telegram.utils.helpers import escape_markdown, from_timestamp, to_timestamp
from telegram.utils.types import JSONDict
Expand Down Expand Up @@ -145,6 +146,9 @@ class Message(TelegramObject):
information about the poll.
dice (:class:`telegram.Dice`): Optional. Message is a dice.
via_bot (:class:`telegram.User`): Optional. Bot through which the message was sent.
proximity_alert_triggered (:class:`telegram.ProximityAlertTriggered`): Optional. Service
message. A user in the chat triggered another user's proximity alert while sharing
Live Location.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
bot (:class:`telegram.Bot`): Optional. The Bot to use for instance methods.
Expand Down Expand Up @@ -257,6 +261,9 @@ class Message(TelegramObject):
information about the poll.
dice (:class:`telegram.Dice`, optional): Message is a dice with random value from 1 to 6.
via_bot (:class:`telegram.User`, optional): Message was sent through an inline bot.
proximity_alert_triggered (:class:`telegram.ProximityAlertTriggered`, optional): Service
message. A user in the chat triggered another user's proximity alert while sharing
Live Location.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message. ``login_url`` buttons are represented as ordinary url buttons.
bot (:class:`telegram.Bot`, optional): The Bot to use for instance methods.
Expand Down Expand Up @@ -298,6 +305,7 @@ class Message(TelegramObject):
'poll',
'dice',
'passport_data',
'proximity_alert_triggered',
] + ATTACHMENT_TYPES

def __init__(
Expand Down Expand Up @@ -352,6 +360,7 @@ def __init__(
bot: 'Bot' = None,
dice: Dice = None,
via_bot: User = None,
proximity_alert_triggered: ProximityAlertTriggered = None,
sender_chat: Chat = None,
**_kwargs: Any,
):
Expand Down Expand Up @@ -406,6 +415,7 @@ def __init__(
self.poll = poll
self.dice = dice
self.via_bot = via_bot
self.proximity_alert_triggered = proximity_alert_triggered
self.reply_markup = reply_markup
self.bot = bot

Expand Down Expand Up @@ -469,6 +479,9 @@ def de_json(cls, data: Optional[JSONDict], bot: 'Bot') -> 'Message':
data['poll'] = Poll.de_json(data.get('poll'), bot)
data['dice'] = Dice.de_json(data.get('dice'), bot)
data['via_bot'] = User.de_json(data.get('via_bot'), bot)
data['proximity_alert_triggered'] = ProximityAlertTriggered.de_json(
data.get('proximity_alert_triggered'), bot
)
data['reply_markup'] = InlineKeyboardMarkup.de_json(data.get('reply_markup'), bot)

return cls(bot=bot, **data)
Expand Down
Loading