Skip to content

Commit df28519

Browse files
author
Pietro Albini
committed
Add support for sending geographic locations
Added and documented the following methods: * botogram.Bot.send_location * botogram.User.send_location * botogram.Chat.send_location * botogram.Message.reply_with_location
1 parent 733be21 commit df28519

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

botogram/frozenbot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ def send_file(self, chat, path, reply_to=None, extra=None):
159159
obj = objects.Chat({"id": chat, "type": ""}, self.api)
160160
obj.send_file(path, reply_to, extra)
161161

162+
def send_location(self, chat, latitude, longitude, reply_to=None,
163+
extra=None):
164+
"""Send a generic file in a chat"""
165+
obj = objects.Chat({"id": chat, "type": ""}, self.api)
166+
obj.send_location(latitude, longitude, reply_to, extra)
167+
162168
# Let's process the messages
163169

164170
def process(self, update):

botogram/objects/mixins.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ def send_file(self, path, reply_to=None, extra=None):
9898
files = {"document": open(path, "rb")}
9999
self._api.call("sendDocument", args, files)
100100

101+
@_require_api
102+
def send_location(self, latitude, longitude, reply_to=None, extra=None):
103+
"""Send a geographic location"""
104+
args = self._get_call_args(reply_to, extra)
105+
args["latitude"] = latitude
106+
args["longitude"] = longitude
107+
108+
self._api.call("sendLocation", args)
109+
101110

102111
class MessageMixin:
103112
"""Add some methods for messages"""
@@ -141,6 +150,11 @@ def reply_with_file(self, path, extra=None):
141150
"""Reply with a generic file to the current chat"""
142151
self.chat.send_file(path, self.message_id, extra)
143152

153+
@_require_api
154+
def reply_with_location(self, latitude, longitude, extra=None):
155+
"""Reply with a geographic location to the current chat"""
156+
self.chat.send_location(latitude, longitude, self.message_id, extra)
157+
144158

145159
class FileMixin:
146160
"""Add some methods for files"""

docs/api/bot.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,26 @@ components.
399399
:param str path: The path to the file
400400
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
401401
:param object extra: An extra reply interface object to attach
402+
403+
.. py:method:: send_location(chat, latitude, longitude, [reply_to=None, extra=None])
404+
405+
This method sends a geographic location to a specific chat. The chat must
406+
be identified by its ID, and Telegram applies some restrictions on the
407+
chats allowed to receive your locations: only users who sent you a
408+
message in the past are allowed, and also the group chats your bot is
409+
currently in.
410+
411+
If the location you're sending is in reply to another message, set
412+
*reply_to* to the ID of the other :py:class:`~botogram.Message`. *extra*
413+
is an optional object which specifies additional reply interface options
414+
on the recipient's end, and can be one of the following types:
415+
416+
* :py:class:`botogram.ReplyKeyboardMarkup`
417+
* :py:class:`botogram.ReplyKeyboardHide`
418+
* :py:class:`botogram.ForceReply`
419+
420+
:param int chat: The ID of the chat which should receive the location
421+
:param float latitude: The latitude of the location
422+
:param float longitude: The longitude of the location
423+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
424+
:param object extra: An extra reply interface object to attach

docs/api/telegram.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ Available Classes
155155
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
156156
:param object extra: An extra reply interface object to attach
157157

158+
.. py:method:: send_location(latitude, longitude, [reply_to=None, extra=None])
159+
160+
Send the geographic location to the user. If the location you're sending
161+
is in reply to another message, set *reply_to* to the ID of the other
162+
:py:class:`~botogram.Message`. *extra* is an optional object which
163+
specifies additional reply interface options on the recipient's end, and
164+
can be one of the following types:
165+
166+
* :py:class:`botogram.ReplyKeyboardMarkup`
167+
* :py:class:`botogram.ReplyKeyboardHide`
168+
* :py:class:`botogram.ForceReply`
169+
170+
:param float latitude: The latitude of the location
171+
:param float longitude: The longitude of the location
172+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
173+
:param object extra: An extra reply interface object to attach
174+
158175

159176
.. py:class:: botogram.Chat
160177
@@ -288,6 +305,23 @@ Available Classes
288305
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
289306
:param object extra: An extra reply interface object to attach
290307

308+
.. py:method:: send_location(latitude, longitude, [reply_to=None, extra=None])
309+
310+
Send the geographic location to the chat. If the location you're sending
311+
is in reply to another message, set *reply_to* to the ID of the other
312+
:py:class:`~botogram.Message`. *extra* is an optional object which
313+
specifies additional reply interface options on the recipient's end, and
314+
can be one of the following types:
315+
316+
* :py:class:`botogram.ReplyKeyboardMarkup`
317+
* :py:class:`botogram.ReplyKeyboardHide`
318+
* :py:class:`botogram.ForceReply`
319+
320+
:param float latitude: The latitude of the location
321+
:param float longitude: The longitude of the location
322+
:param int reply_to: The ID of the :py:class:`~botogram.Message` this one is replying to
323+
:param object extra: An extra reply interface object to attach
324+
291325

292326
.. py:class:: botogram.Message
293327
@@ -563,6 +597,20 @@ Available Classes
563597
:param str path: The path to the file
564598
:param object extra: An extra reply interface object to attach
565599

600+
.. py:method:: reply_with_location(latitude, longitude, [extra=None])
601+
602+
Send the geographic location to the user. *extra* is an optional object
603+
which specifies additional reply interface options on the recipient's
604+
end, and can be one of the following types:
605+
606+
* :py:class:`botogram.ReplyKeyboardMarkup`
607+
* :py:class:`botogram.ReplyKeyboardHide`
608+
* :py:class:`botogram.ForceReply`
609+
610+
:param float latitude: The latitude of the location
611+
:param float longitude: The longitude of the location
612+
:param object extra: An extra reply interface object to attach
613+
566614

567615
.. py:class:: botogram.Photo
568616

0 commit comments

Comments
 (0)