From c1247249c7e7480a16e7c7c490b3f4b123bbc91b Mon Sep 17 00:00:00 2001 From: eternnoir Date: Thu, 14 Apr 2016 13:55:28 +0800 Subject: [PATCH] Add send venu method. --- telebot/__init__.py | 7 +++++++ telebot/apihelper.py | 15 +++++++++++++++ tests/test_telebot.py | 16 ++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/telebot/__init__.py b/telebot/__init__.py index 0fa6926..cda256e 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -413,6 +413,13 @@ class TeleBot: apihelper.send_location(self.token, chat_id, latitude, longitude, reply_to_message_id, reply_markup, disable_notification)) + def send_venue(self, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None, + reply_to_message_id=None, reply_markup=None): + return types.Message.de_json( + apihelper.send_venue(self.token, chat_id, latitude, longitude, title, address, foursquare_id, + disable_notification, reply_to_message_id, reply_markup) + ) + def send_chat_action(self, chat_id, action): """ Use this method when you need to tell the user that something is happening on the bot's side. diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 3053b59..332718f 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -182,6 +182,21 @@ def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None, return _make_request(token, method_url, params=payload) +def send_venue(token, chat_id, latitude, longitude, title, address, foursquare_id=None, disable_notification=None, + reply_to_message_id=None, reply_markup=None): + method_url = r'sendVenue' + payload = {'chat_id': chat_id, 'latitude': latitude, 'longitude': longitude, 'title': title, 'address': address} + if foursquare_id: + payload['foursquare_id'] = foursquare_id + if disable_notification: + payload['disable_notification'] = disable_notification + if reply_to_message_id: + payload['reply_to_message_id'] = reply_to_message_id + if reply_markup: + payload['reply_markup'] = _convert_markup(reply_markup) + return _make_request(token, method_url, params=payload) + + def send_chat_action(token, chat_id, action): method_url = r'sendChatAction' payload = {'chat_id': chat_id, 'action': action} diff --git a/tests/test_telebot.py b/tests/test_telebot.py index f5602d4..dc40993 100644 --- a/tests/test_telebot.py +++ b/tests/test_telebot.py @@ -304,6 +304,20 @@ class TestTeleBot: assert int(ret_msg.location.longitude) == int(lon) assert int(ret_msg.location.latitude) == int(lat) + def test_send_venue(self): + tb = telebot.TeleBot(TOKEN) + lat = 26.3875591 + lon = -161.2901042 + ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address") + assert ret_msg.venue.title == "Test Venue" + + def test_send_venue_dis_noti(self): + tb = telebot.TeleBot(TOKEN) + lat = 26.3875591 + lon = -161.2901042 + ret_msg = tb.send_venue(CHAT_ID, lat, lon, "Test Venue", "1123 Test Venue address",disable_notification=True) + assert ret_msg.venue.title == "Test Venue" + def test_Chat(self): tb = telebot.TeleBot(TOKEN) me = tb.get_me() @@ -327,5 +341,3 @@ class TestTeleBot: def test_not_string(self): i1 = 10 assert not util.is_string(i1) - -