diff --git a/README.md b/README.md index e5f61d3..5853544 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,11 @@ tb.polling(none_stop=False, interval=0, block=True) # getMe user = tb.get_me() +# setWebhook +tb.set_webhook(url="http://example.com", cert=open('mycert.pem')) +# unset webhook +tb.remove_webhook() + # getUpdates updates = tb.get_updates() updates = tb.get_updates(1234,100,20) #get_Updates(offset, limit, timeout): diff --git a/telebot/__init__.py b/telebot/__init__.py index 6cbf85a..fefd164 100644 --- a/telebot/__init__.py +++ b/telebot/__init__.py @@ -68,6 +68,12 @@ class TeleBot: if self.__create_threads: self.worker_pool = util.ThreadPool(num_threads) + def set_webhook(self, url=None, certificate=None): + return apihelper.set_webhook(self.token, url, certificate) + + def remove_webhook(self): + return self.set_webhook() # No params resets webhook + def get_updates(self, offset=None, limit=None, timeout=20): """ Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned. diff --git a/telebot/apihelper.py b/telebot/apihelper.py index 0e9e14b..3c8c529 100644 --- a/telebot/apihelper.py +++ b/telebot/apihelper.py @@ -105,6 +105,18 @@ def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_m return _make_request(token, method_url, params=payload, method='post') +def set_webhook(token, url=None, certificate=None): + method_url = 'setWebhook' + payload = { + 'url': url if url else "", + } + files = None + if certificate: + files = {'certificate': certificate} + + return _make_request(token, method_url, params=payload, files=files) + + def get_updates(token, offset=None, limit=None, timeout=None): method_url = r'getUpdates' payload = {}