Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion telegram/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


class Bot(object):

def __init__(self,
token,
base_url=None):
Expand Down Expand Up @@ -554,12 +555,33 @@ def getUpdates(self,

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,
Expand Down