diff --git a/telegram/bot.py b/telegram/bot.py index 46a77b39791..20c55cec574 100644 --- a/telegram/bot.py +++ b/telegram/bot.py @@ -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 @@ -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 \ + `_.) 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. @@ -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, @@ -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', diff --git a/telegram/files/venue.py b/telegram/files/venue.py index ca0523286cc..fa27950cb7b 100644 --- a/telegram/files/venue.py +++ b/telegram/files/venue.py @@ -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. @@ -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 `_.) **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ @@ -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 @@ -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) diff --git a/telegram/inline/inlinequeryresultvenue.py b/telegram/inline/inlinequeryresultvenue.py index e7533946cf9..6cbee78e1d8 100644 --- a/telegram/inline/inlinequeryresultvenue.py +++ b/telegram/inline/inlinequeryresultvenue.py @@ -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. @@ -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".) + 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 @@ -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 `_.) reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached to the message. input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the @@ -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, ): @@ -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 diff --git a/telegram/inline/inputvenuemessagecontent.py b/telegram/inline/inputvenuemessagecontent.py index 8e96bb2fe74..4541c254b55 100644 --- a/telegram/inline/inputvenuemessagecontent.py +++ b/telegram/inline/inputvenuemessagecontent.py @@ -30,6 +30,10 @@ 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. @@ -37,8 +41,8 @@ class InputVenueMessageContent(InputMessageContent): 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. @@ -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 `_.) **kwargs (:obj:`dict`): Arbitrary keyword arguments. """ @@ -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 @@ -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, diff --git a/tests/test_bot.py b/tests/test_bot.py index b87f479d96d..a2df690b0eb 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -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, @@ -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) diff --git a/tests/test_inlinequeryresultvenue.py b/tests/test_inlinequeryresultvenue.py index 1c8f3856a7a..3cd4b608404 100644 --- a/tests/test_inlinequeryresultvenue.py +++ b/tests/test_inlinequeryresultvenue.py @@ -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, ) @@ -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 @@ -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 @@ -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 diff --git a/tests/test_inputvenuemessagecontent.py b/tests/test_inputvenuemessagecontent.py index fef242a8784..403fe321cdf 100644 --- a/tests/test_inputvenuemessagecontent.py +++ b/tests/test_inputvenuemessagecontent.py @@ -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, ) @@ -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 @@ -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() @@ -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') diff --git a/tests/test_venue.py b/tests/test_venue.py index cbf6f7b3b8e..d7ff8b704b4 100644 --- a/tests/test_venue.py +++ b/tests/test_venue.py @@ -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, ) @@ -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 = { @@ -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) @@ -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): @@ -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) @@ -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)