Skip to content
12 changes: 10 additions & 2 deletions telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,12 +1025,14 @@ def send_venue(self,
reply_markup=None,
timeout=None,
venue=None,
foursquare_type=None,
**kwargs):
"""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`.
:obj:`title` and :obj:`address` and optionally :obj:`foursquare_id` and optionally
:obj:`foursquare_type`.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand All @@ -1040,6 +1042,9 @@ def send_venue(self,
title (:obj:`str`, optional): Name of the venue.
address (:obj:`str`, optional): Address of the venue.
foursquare_id (:obj:`str`, optional): Foursquare identifier of the venue.
foursquare_type (:obj:`str`, optional): Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
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 @@ -1072,6 +1077,7 @@ def send_venue(self,
address = venue.address
title = venue.title
foursquare_id = venue.foursquare_id
foursquare_type = venue.foursquare_type

data = {
'chat_id': chat_id,
Expand All @@ -1083,6 +1089,8 @@ def send_venue(self,

if foursquare_id:
data['foursquare_id'] = foursquare_id
if foursquare_type:
data['foursquare_type'] = foursquare_type

return url, data

Expand All @@ -1103,7 +1111,7 @@ def send_contact(self,

Note:
You can either supply :obj:`contact` or :obj:`phone_number` and :obj:`first_name`
with optionally :obj:`last_name`.
with optionally :obj:`last_name` and optionally :obj:`vcard`.

Args:
chat_id (:obj:`int` | :obj:`str`): Unique identifier for the target chat or username
Expand Down
8 changes: 7 additions & 1 deletion telegram/files/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,29 @@ class Venue(TelegramObject):
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".)

Args:
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".)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, location, title, address, foursquare_id=None, **kwargs):
def __init__(self, location, title, address, foursquare_id=None, foursquare_type=None,
**kwargs):
# Required
self.location = location
self.title = title
self.address = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type

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

Expand Down
9 changes: 9 additions & 0 deletions telegram/inline/inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class InlineQueryResultVenue(InlineQueryResult):
title (:obj:`str`): Title 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".)
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
Expand All @@ -50,6 +53,9 @@ class InlineQueryResultVenue(InlineQueryResult):
title (:obj:`str`): Title 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".)
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
Expand All @@ -68,6 +74,7 @@ def __init__(self,
title,
address,
foursquare_id=None,
foursquare_type=None,
reply_markup=None,
input_message_content=None,
thumb_url=None,
Expand All @@ -85,6 +92,8 @@ def __init__(self,
# Optional
if foursquare_id:
self.foursquare_id = foursquare_id
if foursquare_type:
self.foursquare_type = foursquare_type
if reply_markup:
self.reply_markup = reply_markup
if input_message_content:
Expand Down
10 changes: 9 additions & 1 deletion telegram/inline/inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ class InputVenueMessageContent(InputMessageContent):
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".)

Args:
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".)
**kwargs (:obj:`dict`): Arbitrary keyword arguments.

"""

def __init__(self, latitude, longitude, title, address, foursquare_id=None, **kwargs):
def __init__(self, latitude, longitude, title, address, foursquare_id=None,
foursquare_type=None, **kwargs):
# Required
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
# Optionals
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
7 changes: 6 additions & 1 deletion tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,19 @@ def test_send_venue(self, bot, chat_id):
latitude = -23.691288
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
message = bot.send_venue(chat_id=chat_id, title=title, address=address, latitude=latitude,
longitude=longitude)
longitude=longitude, foursquare_id=foursquare_id,
foursquare_type=foursquare_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.foursquare_id == foursquare_id
assert message.venue.foursquare_type == foursquare_type

@flaky(3, 1)
@pytest.mark.timeout(10)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_inlinequeryresultvenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def inline_query_result_venue():
TestInlineQueryResultVenue.title,
TestInlineQueryResultVenue.address,
foursquare_id=TestInlineQueryResultVenue.foursquare_id,
foursquare_type=TestInlineQueryResultVenue.foursquare_type,
thumb_url=TestInlineQueryResultVenue.thumb_url,
thumb_width=TestInlineQueryResultVenue.thumb_width,
thumb_height=TestInlineQueryResultVenue.thumb_height,
Expand All @@ -47,6 +48,7 @@ class TestInlineQueryResultVenue(object):
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'
thumb_url = 'thumb url'
thumb_width = 10
thumb_height = 15
Expand All @@ -61,6 +63,7 @@ def test_expected_values(self, inline_query_result_venue):
assert inline_query_result_venue.title == self.title
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.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 All @@ -80,6 +83,8 @@ def test_to_dict(self, inline_query_result_venue):
assert inline_query_result_venue_dict['address'] == inline_query_result_venue.address
assert (inline_query_result_venue_dict['foursquare_id'] ==
inline_query_result_venue.foursquare_id)
assert (inline_query_result_venue_dict['foursquare_type'] ==
inline_query_result_venue.foursquare_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
7 changes: 6 additions & 1 deletion tests/test_inputvenuemessagecontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def input_venue_message_content():
TestInputVenueMessageContent.longitude,
TestInputVenueMessageContent.title,
TestInputVenueMessageContent.address,
foursquare_id=TestInputVenueMessageContent.foursquare_id)
foursquare_id=TestInputVenueMessageContent.foursquare_id,
foursquare_type=TestInputVenueMessageContent.foursquare_type)


class TestInputVenueMessageContent(object):
Expand All @@ -37,13 +38,15 @@ class TestInputVenueMessageContent(object):
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'

def test_expected_values(self, input_venue_message_content):
assert input_venue_message_content.longitude == self.longitude
assert input_venue_message_content.latitude == self.latitude
assert input_venue_message_content.title == self.title
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

def test_to_dict(self, input_venue_message_content):
input_venue_message_content_dict = input_venue_message_content.to_dict()
Expand All @@ -57,3 +60,5 @@ def test_to_dict(self, input_venue_message_content):
assert input_venue_message_content_dict['address'] == input_venue_message_content.address
assert (input_venue_message_content_dict['foursquare_id'] ==
input_venue_message_content.foursquare_id)
assert (input_venue_message_content_dict['foursquare_type'] ==
input_venue_message_content.foursquare_type)
12 changes: 9 additions & 3 deletions tests/test_venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,41 @@ def venue():
return Venue(TestVenue.location,
TestVenue.title,
TestVenue.address,
foursquare_id=TestVenue.foursquare_id)
foursquare_id=TestVenue.foursquare_id,
foursquare_type=TestVenue.foursquare_type)


class TestVenue(object):
location = Location(longitude=-46.788279, latitude=-23.691288)
title = 'title'
address = 'address'
foursquare_id = 'foursquare id'
foursquare_type = 'foursquare type'

def test_de_json(self, bot):
json_dict = {
'location': TestVenue.location.to_dict(),
'title': TestVenue.title,
'address': TestVenue.address,
'foursquare_id': TestVenue.foursquare_id
'foursquare_id': TestVenue.foursquare_id,
'foursquare_type': TestVenue.foursquare_type
}
venue = Venue.de_json(json_dict, bot)

assert venue.location == self.location
assert venue.title == self.title
assert venue.address == self.address
assert venue.foursquare_id == self.foursquare_id
assert venue.foursquare_type == self.foursquare_type

def test_send_with_venue(self, monkeypatch, bot, chat_id, venue):
def test(_, url, data, **kwargs):
return (data['longitude'] == self.location.longitude
and data['latitude'] == self.location.latitude
and data['title'] == self.title
and data['address'] == self.address
and data['foursquare_id'] == self.foursquare_id)
and data['foursquare_id'] == self.foursquare_id
and data['foursquare_type'] == self.foursquare_type)

monkeypatch.setattr('telegram.utils.request.Request.post', test)
message = bot.send_venue(chat_id, venue=venue)
Expand All @@ -74,6 +79,7 @@ def test_to_dict(self, venue):
assert venue_dict['title'] == venue.title
assert venue_dict['address'] == venue.address
assert venue_dict['foursquare_id'] == venue.foursquare_id
assert venue_dict['foursquare_type'] == venue.foursquare_type

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