Skip to content

Commit 0608a15

Browse files
author
Pietro Albini
committed
Add support for sending venues
A Venue is a new kind of message introduced in the Bot API 2.0 update, which can be sent only by bots. This commit adds support for sending it in chats and as a reply. Fixes: GH-58
1 parent 7833174 commit 0608a15

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

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"""
@@ -261,6 +275,11 @@ def reply_with_location(self, *args, **kwargs):
261275
"""Reply with a geographic location to the current chat"""
262276
return self.chat.send_location(*args, reply_to=self, **kwargs)
263277

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

docs/api/telegram.rst

Lines changed: 90 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
@@ -1428,6 +1488,36 @@ about its business.
14281488

14291489
Now the method returns the sent message
14301490

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+
14311521
.. py:method:: reply_with_sticker(sticker, [reply_to=None, extra=None, notify=True])
14321522
14331523
Reply with the sticker (in webp format) to the chat. *extra* is an

docs/changelog/0.3.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ New features
6363

6464
* New class :py:class:`botogram.Venue`
6565
* 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`
6669

6770
* Added new attribute :py:attr:`botogram.Message.pinned_message`
6871
* Added new attribute :py:attr:`botogram.Sticker.emoji`

0 commit comments

Comments
 (0)