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
21 changes: 18 additions & 3 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1606,14 +1606,19 @@ def send_venue(
venue: Venue = None,
foursquare_type: str = None,
api_kwargs: JSONDict = None,
google_place_id: str = None,
google_place_type: str = None,
allow_sending_without_reply: bool = None,
) -> Optional[Message]:
"""Use this method to send information about a venue.

Note:
You can either supply :obj:`venue`, or :obj:`latitude`, :obj:`longitude`,
:obj:`title` and :obj:`address` and optionally :obj:`foursquare_id` and optionally
:obj:`foursquare_type`.
* You can either supply :obj:`venue`, or :obj:`latitude`, :obj:`longitude`,
:obj:`title` and :obj:`address` and optionally :obj:`foursquare_id` and
:obj:`foursquare_type` or optionally :obj:`google_place_id` and
:obj:`google_place_type`.
* Foursquare details and Google Pace details are mutually exclusive. However, this
behaviour is undocumented and might be changed by Telegram.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand All @@ -1626,6 +1631,10 @@ def send_venue(
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
`supported types \
<https://developers.google.com/places/web-service/supported_types>`_.)
venue (:class:`telegram.Venue`, optional): The venue to send.
disable_notification (:obj:`bool`, optional): Sends the message silently. Users will
receive a notification with no sound.
Expand Down Expand Up @@ -1662,6 +1671,8 @@ def send_venue(
title = venue.title
foursquare_id = venue.foursquare_id
foursquare_type = venue.foursquare_type
google_place_id = venue.google_place_id
google_place_type = venue.google_place_type

data: JSONDict = {
'chat_id': chat_id,
Expand All @@ -1675,6 +1686,10 @@ def send_venue(
data['foursquare_id'] = foursquare_id
if foursquare_type:
data['foursquare_type'] = foursquare_type
if google_place_id:
data['google_place_id'] = google_place_id
if google_place_type:
data['google_place_type'] = google_place_type

return self._message( # type: ignore[return-value]
'sendVenue',
Expand Down
16 changes: 14 additions & 2 deletions telegram/files/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ class Venue(TelegramObject):
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`location` and :attr:`title` are equal.

Note:
Foursquare details and Google Pace details are mutually exclusive. However, this
behaviour is undocumented and might be changed by Telegram.

Attributes:
location (:class:`telegram.Location`): Venue location.
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue. (For example,
"arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue.
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue.

Args:
location (:class:`telegram.Location`): Venue location.
Expand All @@ -48,6 +53,9 @@ class Venue(TelegramObject):
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue.
foursquare_type (:obj:`str`, optional): Foursquare type of the venue. (For example,
"arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
`supported types <https://developers.google.com/places/web-service/supported_types>`_.)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""
Expand All @@ -59,6 +67,8 @@ def __init__(
address: str,
foursquare_id: str = None,
foursquare_type: str = None,
google_place_id: str = None,
google_place_type: str = None,
**_kwargs: Any,
):
# Required
Expand All @@ -68,6 +78,8 @@ def __init__(
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type

self._id_attrs = (self.location, self.title)

Expand Down
15 changes: 13 additions & 2 deletions telegram/inline/inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class InlineQueryResultVenue(InlineQueryResult):
use :attr:`input_message_content` to send a message with the specified content instead of the
venue.

Note:
Foursquare details and Google Pace details are mutually exclusive. However, this
behaviour is undocumented and might be changed by Telegram.

Attributes:
type (:obj:`str`): 'venue'.
id (:obj:`str`): Unique identifier for this result, 1-64 Bytes.
Expand All @@ -41,8 +45,8 @@ class InlineQueryResultVenue(InlineQueryResult):
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue if known.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
Comment on lines -44 to -45
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I like this actually. Why did you remove it, maintaining?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because as a rule of thumb, attribute docstrings should be shorter than the corresponding argument docstring. at least that's what I did up to now …

google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
Expand All @@ -61,6 +65,9 @@ class InlineQueryResultVenue(InlineQueryResult):
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
`supported types <https://developers.google.com/places/web-service/supported_types>`_.)
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
Expand All @@ -86,6 +93,8 @@ def __init__(
thumb_url: str = None,
thumb_width: int = None,
thumb_height: int = None,
google_place_id: str = None,
google_place_type: str = None,
**_kwargs: Any,
):

Expand All @@ -99,6 +108,8 @@ def __init__(
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
Expand Down
15 changes: 13 additions & 2 deletions telegram/inline/inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,19 @@ class InputVenueMessageContent(InputMessageContent):
considered equal, if their :attr:`latitude`, :attr:`longitude` and :attr:`title`
are equal.

Note:
Foursquare details and Google Pace details are mutually exclusive. However, this
behaviour is undocumented and might be changed by Telegram.

Attributes:
latitude (:obj:`float`): Latitude of the location in degrees.
longitude (:obj:`float`): Longitude of the location in degrees.
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue, if known.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue.

Args:
latitude (:obj:`float`): Latitude of the location in degrees.
Expand All @@ -49,6 +53,9 @@ class InputVenueMessageContent(InputMessageContent):
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
google_place_id (:obj:`str`, optional): Google Places identifier of the venue.
google_place_type (:obj:`str`, optional): Google Places type of the venue. (See
`supported types <https://developers.google.com/places/web-service/supported_types>`_.)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""
Expand All @@ -61,6 +68,8 @@ def __init__(
address: str,
foursquare_id: str = None,
foursquare_type: str = None,
google_place_id: str = None,
google_place_type: str = None,
**_kwargs: Any,
):
# Required
Expand All @@ -71,6 +80,8 @@ def __init__(
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type

self._id_attrs = (
self.latitude,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def test_send_venue(self, bot, chat_id):
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
google_place_id = 'google_place id'
google_place_type = 'google_place type'

message = bot.send_venue(
chat_id=chat_id,
title=title,
Expand All @@ -210,6 +213,28 @@ def test_send_venue(self, bot, chat_id):
assert message.venue.location.longitude == longitude
assert message.venue.foursquare_id == foursquare_id
assert message.venue.foursquare_type == foursquare_type
assert message.venue.google_place_id is None
assert message.venue.google_place_type is None

message = bot.send_venue(
chat_id=chat_id,
title=title,
address=address,
latitude=latitude,
longitude=longitude,
google_place_id=google_place_id,
google_place_type=google_place_type,
)

assert message.venue
assert message.venue.title == title
assert message.venue.address == address
assert message.venue.location.latitude == latitude
assert message.venue.location.longitude == longitude
assert message.venue.google_place_id == google_place_id
assert message.venue.google_place_type == google_place_type
assert message.venue.foursquare_id is None
assert message.venue.foursquare_type is None

@flaky(3, 1)
@pytest.mark.timeout(10)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def inline_query_result_venue():
thumb_height=TestInlineQueryResultVenue.thumb_height,
input_message_content=TestInlineQueryResultVenue.input_message_content,
reply_markup=TestInlineQueryResultVenue.reply_markup,
google_place_id=TestInlineQueryResultVenue.google_place_id,
google_place_type=TestInlineQueryResultVenue.google_place_type,
)


Expand All @@ -55,6 +57,8 @@ class TestInlineQueryResultVenue:
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
google_place_id = 'google place id'
google_place_type = 'google place type'
thumb_url = 'thumb url'
thumb_width = 10
thumb_height = 15
Expand All @@ -70,6 +74,8 @@ def test_expected_values(self, inline_query_result_venue):
assert inline_query_result_venue.address == self.address
assert inline_query_result_venue.foursquare_id == self.foursquare_id
assert inline_query_result_venue.foursquare_type == self.foursquare_type
assert inline_query_result_venue.google_place_id == self.google_place_id
assert inline_query_result_venue.google_place_type == self.google_place_type
assert inline_query_result_venue.thumb_url == self.thumb_url
assert inline_query_result_venue.thumb_width == self.thumb_width
assert inline_query_result_venue.thumb_height == self.thumb_height
Expand Down Expand Up @@ -97,6 +103,14 @@ def test_to_dict(self, inline_query_result_venue):
inline_query_result_venue_dict['foursquare_type']
== inline_query_result_venue.foursquare_type
)
assert (
inline_query_result_venue_dict['google_place_id']
== inline_query_result_venue.google_place_id
)
assert (
inline_query_result_venue_dict['google_place_type']
== inline_query_result_venue.google_place_type
)
assert inline_query_result_venue_dict['thumb_url'] == inline_query_result_venue.thumb_url
assert (
inline_query_result_venue_dict['thumb_width'] == inline_query_result_venue.thumb_width
Expand Down
14 changes: 14 additions & 0 deletions tests/test_inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def input_venue_message_content():
TestInputVenueMessageContent.address,
foursquare_id=TestInputVenueMessageContent.foursquare_id,
foursquare_type=TestInputVenueMessageContent.foursquare_type,
google_place_id=TestInputVenueMessageContent.google_place_id,
google_place_type=TestInputVenueMessageContent.google_place_type,
)


Expand All @@ -41,6 +43,8 @@ class TestInputVenueMessageContent:
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
google_place_id = 'google place id'
google_place_type = 'google place type'

def test_expected_values(self, input_venue_message_content):
assert input_venue_message_content.longitude == self.longitude
Expand All @@ -49,6 +53,8 @@ def test_expected_values(self, input_venue_message_content):
assert input_venue_message_content.address == self.address
assert input_venue_message_content.foursquare_id == self.foursquare_id
assert input_venue_message_content.foursquare_type == self.foursquare_type
assert input_venue_message_content.google_place_id == self.google_place_id
assert input_venue_message_content.google_place_type == self.google_place_type

def test_to_dict(self, input_venue_message_content):
input_venue_message_content_dict = input_venue_message_content.to_dict()
Expand All @@ -68,6 +74,14 @@ def test_to_dict(self, input_venue_message_content):
input_venue_message_content_dict['foursquare_type']
== input_venue_message_content.foursquare_type
)
assert (
input_venue_message_content_dict['google_place_id']
== input_venue_message_content.google_place_id
)
assert (
input_venue_message_content_dict['google_place_type']
== input_venue_message_content.google_place_type
)

def test_equality(self):
a = InputVenueMessageContent(123, 456, 'title', 'address')
Expand Down
12 changes: 12 additions & 0 deletions tests/test_venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def venue():
TestVenue.address,
foursquare_id=TestVenue.foursquare_id,
foursquare_type=TestVenue.foursquare_type,
google_place_id=TestVenue.google_place_id,
google_place_type=TestVenue.google_place_type,
)


Expand All @@ -41,6 +43,8 @@ class TestVenue:
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
google_place_id = 'google place id'
google_place_type = 'google place type'

def test_de_json(self, bot):
json_dict = {
Expand All @@ -49,6 +53,8 @@ def test_de_json(self, bot):
'address': TestVenue.address,
'foursquare_id': TestVenue.foursquare_id,
'foursquare_type': TestVenue.foursquare_type,
'google_place_id': TestVenue.google_place_id,
'google_place_type': TestVenue.google_place_type,
}
venue = Venue.de_json(json_dict, bot)

Expand All @@ -57,6 +63,8 @@ def test_de_json(self, bot):
assert venue.address == self.address
assert venue.foursquare_id == self.foursquare_id
assert venue.foursquare_type == self.foursquare_type
assert venue.google_place_id == self.google_place_id
assert venue.google_place_type == self.google_place_type

def test_send_with_venue(self, monkeypatch, bot, chat_id, venue):
def test(url, data, **kwargs):
Expand All @@ -67,6 +75,8 @@ def test(url, data, **kwargs):
and data['address'] == self.address
and data['foursquare_id'] == self.foursquare_id
and data['foursquare_type'] == self.foursquare_type
and data['google_place_id'] == self.google_place_id
and data['google_place_type'] == self.google_place_type
)

monkeypatch.setattr(bot.request, 'post', test)
Expand Down Expand Up @@ -121,6 +131,8 @@ def test_to_dict(self, venue):
assert venue_dict['address'] == venue.address
assert venue_dict['foursquare_id'] == venue.foursquare_id
assert venue_dict['foursquare_type'] == venue.foursquare_type
assert venue_dict['google_place_id'] == venue.google_place_id
assert venue_dict['google_place_type'] == venue.google_place_type

def test_equality(self):
a = Venue(Location(0, 0), self.title, self.address)
Expand Down