mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 22:45:09 +01:00
Adding setWebhook
This commit is contained in:
parent
b90b608fb1
commit
d38a21c697
1 changed files with 23 additions and 1 deletions
|
@ -11,6 +11,7 @@ from telegram import (User, Message, Update, UserProfilePhotos, TelegramError,
|
|||
|
||||
|
||||
class Bot(object):
|
||||
|
||||
def __init__(self,
|
||||
token,
|
||||
base_url=None):
|
||||
|
@ -554,12 +555,33 @@ class Bot(object):
|
|||
|
||||
return [Update.de_json(x) for x in data]
|
||||
|
||||
def setWebhook(self):
|
||||
def setWebhook(self, webhook_url=""):
|
||||
"""Use this method to specify a url and receive incoming updates via an
|
||||
outgoing webhook. Whenever there is an update for the bot, we will send
|
||||
an HTTPS POST request to the specified url, containing a
|
||||
JSON-serialized Update. In case of an unsuccessful request, we will
|
||||
give up after a reasonable amount of attempts.
|
||||
|
||||
Args:
|
||||
url:
|
||||
HTTPS url to send updates to.
|
||||
Use an empty string to remove webhook integration
|
||||
|
||||
Returns:
|
||||
True if successful else TelegramError was raised
|
||||
"""
|
||||
url = '%s/setWebhook' % (self.base_url)
|
||||
|
||||
if not self.__auth:
|
||||
raise TelegramError({'message': "API must be authenticated."})
|
||||
|
||||
data = {'url': webhook_url}
|
||||
|
||||
json_data = self._requestUrl(url, 'POST', data=data)
|
||||
data = self._parseAndCheckTelegram(json_data.content)
|
||||
|
||||
return True
|
||||
|
||||
def _requestUrl(self,
|
||||
url,
|
||||
method,
|
||||
|
|
Loading…
Reference in a new issue