1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Added webhooks support with set_webhook and remove_webhook in the TeleBot class

This commit is contained in:
pieter 2015-09-18 20:12:53 +02:00
parent 7a08102fad
commit 941b8ac5d0
3 changed files with 23 additions and 0 deletions

View File

@ -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):

View File

@ -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.

View File

@ -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 = {}