X Tutup
Skip to content

Commit d38a21c

Browse files
committed
Adding setWebhook
1 parent b90b608 commit d38a21c

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

telegram/bot.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212

1313
class Bot(object):
14+
1415
def __init__(self,
1516
token,
1617
base_url=None):
@@ -554,12 +555,33 @@ def getUpdates(self,
554555

555556
return [Update.de_json(x) for x in data]
556557

557-
def setWebhook(self):
558+
def setWebhook(self, webhook_url=""):
559+
"""Use this method to specify a url and receive incoming updates via an
560+
outgoing webhook. Whenever there is an update for the bot, we will send
561+
an HTTPS POST request to the specified url, containing a
562+
JSON-serialized Update. In case of an unsuccessful request, we will
563+
give up after a reasonable amount of attempts.
564+
565+
Args:
566+
url:
567+
HTTPS url to send updates to.
568+
Use an empty string to remove webhook integration
569+
570+
Returns:
571+
True if successful else TelegramError was raised
572+
"""
558573
url = '%s/setWebhook' % (self.base_url)
559574

560575
if not self.__auth:
561576
raise TelegramError({'message': "API must be authenticated."})
562577

578+
data = {'url': webhook_url}
579+
580+
json_data = self._requestUrl(url, 'POST', data=data)
581+
data = self._parseAndCheckTelegram(json_data.content)
582+
583+
return True
584+
563585
def _requestUrl(self,
564586
url,
565587
method,

0 commit comments

Comments
 (0)
X Tutup