Skip to content

Commit 7833174

Browse files
author
Pietro Albini
committed
Add support for processing 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 receiving and processing it. Issue: GH-58
1 parent 1009c1c commit 7833174

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-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,

docs/api/telegram.rst

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,13 @@ about its business.
10831083

10841084
*This attribute can be None if it's not provided by Telegram.*
10851085

1086+
.. py:attribute:: venue
1087+
1088+
If the user sent a :py:class:`~botogram.Venue` with this message, the
1089+
attribute contains its representation.
1090+
1091+
*This attribute can be None if the message isn't a venue.*
1092+
10861093
.. py:attribute:: new_chat_member
10871094
10881095
A :py:class:`~botogram.User` object representing a new member of a group
@@ -1820,6 +1827,36 @@ about its business.
18201827
The float latitude as defined by the sender.
18211828

18221829

1830+
.. py:class:: botogram.Venue
1831+
1832+
This object represents a venue (a location with attached a title and an
1833+
address). A venue may also have a Foursquare ID attached.
1834+
1835+
.. py:attribute:: location
1836+
1837+
The :py:class:`~botogram.Location` of the venue. You can use this to get
1838+
the exact geographic coordinates of the venue.
1839+
1840+
.. py:attribute:: title
1841+
1842+
The name of the venue. The value might not match the venue sometimes,
1843+
because it's supplied by the user/bot who sent the venue.
1844+
1845+
.. py:attribute:: address
1846+
1847+
The address of the venue. The value might not match the venue sometimes,
1848+
because it's supplied by the user/bot who sent the venue.
1849+
1850+
.. py:attribute:: foursquare
1851+
1852+
The ID of the venue on Foursquare. You can use this to get more
1853+
information about the venue from the Foursquare API. The ID might not
1854+
match the venue sometimes because it's supplied by the user/bot who sent
1855+
the venue.
1856+
1857+
*This value can be None if the venue doesn't have a Foursquare ID.*
1858+
1859+
18231860
.. py:class:: botogram.Update
18241861
18251862
This class represents an update received by the bot. You should not need to

docs/changelog/0.3.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ 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+
6267
* Added new attribute :py:attr:`botogram.Message.pinned_message`
6368
* Added new attribute :py:attr:`botogram.Sticker.emoji`
6469
* Added new attribute :py:attr:`botogram.Chat.admins`

0 commit comments

Comments
 (0)