Skip to content

Commit 1a8da49

Browse files
author
Pietro Albini
committed
Merge branch 'feature/venues'
2 parents 016ebe0 + 0608a15 commit 1a8da49

File tree

6 files changed

+178
-2
lines changed

6 files changed

+178
-2
lines changed

botogram/objects/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from .chats import User, Chat, UserProfilePhotos
1212
from .media import PhotoSize, Photo, Audio, Voice, Document, Sticker, \
13-
Video, Contact, Location
13+
Video, Contact, Location, Venue
1414
from .messages import Message
1515
from .markup import ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply
1616
from .updates import Update, Updates
@@ -32,6 +32,7 @@
3232
"Video",
3333
"Contact",
3434
"Location",
35+
"Venue",
3536

3637
# Messages-related objects
3738
"Message",

botogram/objects/media.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,23 @@ def __eq__(self, other):
207207
return isinstance(other, Location) and \
208208
self.longitude == other.longitude and \
209209
self.latitude == other.latitude
210+
211+
212+
class Venue(BaseObject):
213+
"""Telegram API representation of a venue
214+
215+
https://core.telegram.orgf/bots/api#venue
216+
"""
217+
218+
required = {
219+
"location": Location,
220+
"title": str,
221+
"address": str,
222+
}
223+
optional = {
224+
"foursquare_id": str,
225+
}
226+
replace_keys = {
227+
"foursquare_id": "foursquare",
228+
}
229+
_check_equality_ = "location"

botogram/objects/messages.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .chats import User, Chat
1616
from .media import Audio, Voice, Document, Photo, Sticker, Video, Contact, \
17-
Location
17+
Location, Venue
1818

1919

2020
_url_protocol_re = re.compile(r"^https?:\/\/|s?ftp:\/\/|mailto:", re.I)
@@ -334,6 +334,7 @@ def from_(self):
334334
"caption": str,
335335
"contact": Contact,
336336
"location": Location,
337+
"venue": Venue,
337338
"new_chat_member": User,
338339
"left_chat_member": User,
339340
"new_chat_title": str,

botogram/objects/mixins.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ def send_location(self, latitude, longitude, reply_to=None, extra=None,
155155
return self._api.call("sendLocation", args,
156156
expect=_objects().Message)
157157

158+
@_require_api
159+
def send_venue(self, latitude, longitude, title, address, foursquare=None,
160+
reply_to=None, extra=None, notify=True):
161+
"""Send a venue"""
162+
args = self._get_call_args(reply_to, extra, notify)
163+
args["latitude"] = latitude
164+
args["longitude"] = longitude
165+
args["title"] = title
166+
args["address"] = address
167+
if foursquare is not None:
168+
args["foursquare_id"] = foursquare
169+
170+
self._api.call("sendVenue", args, expect=_objects().Message)
171+
158172
@_require_api
159173
def send_sticker(self, sticker, reply_to=None, extra=None, notify=True):
160174
"""Send a sticker"""
@@ -262,6 +276,11 @@ def reply_with_location(self, *args, **kwargs):
262276
"""Reply with a geographic location to the current chat"""
263277
return self.chat.send_location(*args, reply_to=self, **kwargs)
264278

279+
@_require_api
280+
def reply_with_venue(self, *args, **kwargs):
281+
"""Reply with a venue to the current message"""
282+
return self.chat.send_venue(*args, reply_to=self, **kwargs)
283+
265284
@_require_api
266285
def reply_with_sticker(self, *args, **kwargs):
267286
"""Reply with a sticker to the current message"""

docs/api/telegram.rst

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,36 @@ about its business.
290290

291291
Now the method returns the sent message
292292

293+
.. py:method:: send_venue(latitude, longitude, title, address, [foursquare=None, reply_to=None, extra=None, notify=True])
294+
295+
Send a venue to the user. A venue is made of its geographic coordinates
296+
(latitude and longitude), its title and address, and optionally the
297+
venue's Foursquare ID, if you want to integrate with that. Users will
298+
then see the venue in the map, along with the information you provided.
299+
300+
You can use this, for example, if you want to recommend to your bot's
301+
users a place to go to dinner tonight:
302+
303+
.. code-block:: python
304+
305+
@bot.command("whereshouldigo")
306+
def whereshouldigo_command(chat, message, args):
307+
message.sender.send("Here there is an unique place to go to dinner tonight!")
308+
message.sender.send_venue(35, -45, "The Abyss", "Atlantic Ocean")
309+
310+
:param float latitude: The latitude of the venue
311+
:param float longitude: The longitude of the venue
312+
:param str title: The name of the venue
313+
:param str address: The address of the venue
314+
:param str foursquare: The Foursquare ID of the venue
315+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
316+
:param object extra: An extra reply interface object to attach
317+
:param bool notify: If you want to trigger a notification on the client
318+
:returns: The message you sent
319+
:rtype: ~botogram.Message
320+
321+
.. versionadded:: 0.3
322+
293323
.. py:method:: send_sticker(sticker, [reply_to=None, extra=None, notify=True])
294324
295325
Send the sticker to the user (in webp format). If the sticker you're
@@ -791,6 +821,36 @@ about its business.
791821

792822
Now the method returns the sent message
793823

824+
.. py:method:: send_venue(latitude, longitude, title, address, [foursquare=None, reply_to=None, extra=None, notify=True])
825+
826+
Send a venue to the chat. A venue is made of its geographic coordinates
827+
(latitude and longitude), its title and address, and optionally the
828+
venue's Foursquare ID, if you want to integrate with that. Users will
829+
then see the venue in the map, along with the information you provided.
830+
831+
You can use this, for example, if you want to recommend to your bot's
832+
users a place to go to dinner tonight:
833+
834+
.. code-block:: python
835+
836+
@bot.command("whereshouldigo")
837+
def whereshouldigo_command(chat, message, args):
838+
chat.send("Here there is an unique place to go to dinner tonight!")
839+
chat.send_venue(35, -45, "The Abyss", "Atlantic Ocean")
840+
841+
:param float latitude: The latitude of the venue
842+
:param float longitude: The longitude of the venue
843+
:param str title: The name of the venue
844+
:param str address: The address of the venue
845+
:param str foursquare: The Foursquare ID of the venue
846+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
847+
:param object extra: An extra reply interface object to attach
848+
:param bool notify: If you want to trigger a notification on the client
849+
:returns: The message you sent
850+
:rtype: ~botogram.Message
851+
852+
.. versionadded:: 0.3
853+
794854
.. py:method:: send_sticker(sticker, [reply_to=None, extra=None, notify=True])
795855
796856
Send the sticker to the chat (in webp format). If the sticker you're
@@ -1083,6 +1143,13 @@ about its business.
10831143

10841144
*This attribute can be None if it's not provided by Telegram.*
10851145

1146+
.. py:attribute:: venue
1147+
1148+
If the user sent a :py:class:`~botogram.Venue` with this message, the
1149+
attribute contains its representation.
1150+
1151+
*This attribute can be None if the message isn't a venue.*
1152+
10861153
.. py:attribute:: new_chat_member
10871154
10881155
A :py:class:`~botogram.User` object representing a new member of a group
@@ -1421,6 +1488,36 @@ about its business.
14211488

14221489
Now the method returns the sent message
14231490

1491+
.. py:method:: reply_with_venue(latitude, longitude, title, address, [foursquare=None, extra=None, notify=True])
1492+
1493+
Reply to this message with a venue. A venue is made of its geographic
1494+
coordinates (latitude and longitude), its title and address, and
1495+
optionally the venue's Foursquare ID, if you want to integrate with that.
1496+
Users will then see the venue in the map, along with the information you
1497+
provided.
1498+
1499+
You can use this, for example, if you want to recommend to your bot's
1500+
users a place to go to dinner tonight:
1501+
1502+
.. code-block:: python
1503+
1504+
@bot.command("whereshouldigo")
1505+
def whereshouldigo_command(chat, message, args):
1506+
message.reply("Here there is an unique place to go to dinner tonight!")
1507+
message.reply_with_venue(35, -45, "The Abyss", "Atlantic Ocean")
1508+
1509+
:param float latitude: The latitude of the venue
1510+
:param float longitude: The longitude of the venue
1511+
:param str title: The name of the venue
1512+
:param str address: The address of the venue
1513+
:param str foursquare: The Foursquare ID of the venue
1514+
:param object extra: An extra reply interface object to attach
1515+
:param bool notify: If you want to trigger a notification on the client
1516+
:returns: The message you sent
1517+
:rtype: ~botogram.Message
1518+
1519+
.. versionadded:: 0.3
1520+
14241521
.. py:method:: reply_with_sticker(sticker, [reply_to=None, extra=None, notify=True])
14251522
14261523
Reply with the sticker (in webp format) to the chat. *extra* is an
@@ -1820,6 +1917,36 @@ about its business.
18201917
The float latitude as defined by the sender.
18211918

18221919

1920+
.. py:class:: botogram.Venue
1921+
1922+
This object represents a venue (a location with attached a title and an
1923+
address). A venue may also have a Foursquare ID attached.
1924+
1925+
.. py:attribute:: location
1926+
1927+
The :py:class:`~botogram.Location` of the venue. You can use this to get
1928+
the exact geographic coordinates of the venue.
1929+
1930+
.. py:attribute:: title
1931+
1932+
The name of the venue. The value might not match the venue sometimes,
1933+
because it's supplied by the user/bot who sent the venue.
1934+
1935+
.. py:attribute:: address
1936+
1937+
The address of the venue. The value might not match the venue sometimes,
1938+
because it's supplied by the user/bot who sent the venue.
1939+
1940+
.. py:attribute:: foursquare
1941+
1942+
The ID of the venue on Foursquare. You can use this to get more
1943+
information about the venue from the Foursquare API. The ID might not
1944+
match the venue sometimes because it's supplied by the user/bot who sent
1945+
the venue.
1946+
1947+
*This value can be None if the venue doesn't have a Foursquare ID.*
1948+
1949+
18231950
.. py:class:: botogram.Update
18241951
18251952
This class represents an update received by the bot. You should not need to

docs/changelog/0.3.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ New features
5959
* New method :py:meth:`botogram.Chat.send_contact`
6060
* New method :py:meth:`botogram.Message.reply_with_contact`
6161

62+
* Added support for venues:
63+
64+
* New class :py:class:`botogram.Venue`
65+
* New attrinute :py:attr:`botogram.Message.venue`
66+
* New method :py:meth:`botogram.User.send_venue`
67+
* New method :py:meth:`botogram.Chat.send_venue`
68+
* New method :py:meth:`botogram.Message.reply_with_venue`
69+
6270
* Added new attribute :py:attr:`botogram.Message.pinned_message`
6371
* Added new attribute :py:attr:`botogram.Sticker.emoji`
6472
* Added new attribute :py:attr:`botogram.Chat.admins`

0 commit comments

Comments
 (0)