From cd0b85c03cd221dfe9f199c17ec443e44932d3fc Mon Sep 17 00:00:00 2001 From: eternnoir Date: Sat, 27 Jun 2015 22:11:18 +0800 Subject: [PATCH] sendLocation method supported. --- README.md | 3 +++ telebot/__init__.py | 4 ++-- telebot/apihelper.py | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c62b631..a3ba97f 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,9 @@ tb.send_sticker(chat_id, sti) video = open('/tmp/video.mp4', 'rb') tb.send_video(chat_id, video) +# sendLocation +tb.send_location(chat_id, lat, lon) + ``` ## TODO diff --git a/telebot/__init__.py b/telebot/__init__.py index e8483c3..cb1eb7e 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -179,5 +179,5 @@ class TeleBot: """ return apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup) - - + def send_location(self, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None): + return apihelper.send_location(self.token, chat_id, latitude, longitude, reply_to_message_id, reply_markup) diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 6daef8a..1aea1c1 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -42,7 +42,7 @@ def get_updates(token): method_url = r'getUpdates' request_url = api_url + 'bot' + token + '/' + method_url req = requests.get(request_url) - return check_result(method_url,req) + return check_result(method_url, req) def forward_message(token, chat_id, from_chat_id, message_id): @@ -70,6 +70,19 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re return check_result(method_url, req) +def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None, reply_markup=None): + api_url = telebot.API_URL + method_url = r'sendLocation' + request_url = api_url + 'bot' + token + '/' + method_url + payload = {'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude} + if reply_to_message_id: + payload['reply_to_message_id'] = reply_to_message_id + if reply_markup: + payload['reply_markup'] = reply_markup + req = requests.get(request_url, params=payload) + return check_result(method_url, req) + + def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_markup=None): api_url = telebot.API_URL method_url = get_method_by_type(data_type)