Skip to content

Commit e725e6d

Browse files
committed
Merge pull request python-telegram-bot#1 from macrojames/master
Adding setWebhook
2 parents b90b608 + d38a21c commit e725e6d

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy