X Tutup
Skip to content

Commit 868d921

Browse files
committed
Add WebhookInfo and getWebhookInfo
Still needs tests though
1 parent f7ede4b commit 868d921

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

telegram/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
MAX_FILESIZE_DOWNLOAD, MAX_FILESIZE_UPLOAD,
8484
MAX_MESSAGES_PER_SECOND_PER_CHAT, MAX_MESSAGES_PER_SECOND,
8585
MAX_MESSAGES_PER_MINUTE_PER_GROUP)
86+
from .webhookinfo import WebhookInfo
8687
from .version import __version__ # flake8: noqa
8788

8889
__author__ = 'devs@python-telegram-bot.org'
@@ -105,4 +106,4 @@
105106
'TelegramObject', 'Update', 'User', 'UserProfilePhotos', 'Venue', 'Video', 'Voice',
106107
'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
107108
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
108-
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP']
109+
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo']

telegram/bot.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import logging
2424

2525
from telegram import (User, Message, Update, Chat, ChatMember, UserProfilePhotos, File,
26-
ReplyMarkup, TelegramObject)
26+
ReplyMarkup, TelegramObject, WebhookInfo)
2727
from telegram.error import InvalidToken
2828
from telegram.utils.request import Request
2929

@@ -1440,6 +1440,15 @@ def getChatMember(self, chat_id, user_id, **kwargs):
14401440

14411441
return ChatMember.de_json(result, self)
14421442

1443+
def getWebhookInfo(self, **kwargs):
1444+
url = '{0}/getWebhookInfo'.format(self.base_url)
1445+
1446+
data = {}
1447+
1448+
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
1449+
1450+
return WebhookInfo.de_json(result, self)
1451+
14431452
@staticmethod
14441453
def de_json(data, bot):
14451454
data = super(Bot, Bot).de_json(data, bot)
@@ -1489,3 +1498,4 @@ def __reduce__(self):
14891498
get_chat_administrators = getChatAdministrators
14901499
get_chat_member = getChatMember
14911500
get_chat_members_count = getChatMembersCount
1501+
get_webhook_info = getWebhookInfo

telegram/webhookinfo.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env python
2+
#
3+
# A library that provides a Python interface to the Telegram Bot API
4+
# Copyright (C) 2015-2016
5+
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser Public License
18+
# along with this program. If not, see [http://www.gnu.org/licenses/].
19+
"""This module contains a object that represents a Telegram WebhookInfo."""
20+
21+
from telegram import TelegramObject
22+
23+
24+
class WebhookInfo(TelegramObject):
25+
"""This object represents a Telegram WebhookInfo.
26+
27+
Attributes:
28+
url (str): Webhook URL, may be empty if webhook is not set up
29+
has_custom_certificate (bool):
30+
pending_update_count (int):
31+
last_error_date (Optional[int]):
32+
last_error_message (Optional[str]):
33+
34+
Args:
35+
url (str): Webhook URL, may be empty if webhook is not set up
36+
has_custom_certificate (bool):
37+
pending_update_count (int):
38+
last_error_date (Optional[int]):
39+
last_error_message (Optional[str]):
40+
"""
41+
42+
def __init__(self, url, has_custom_certificate, pending_update_count, **kwargs):
43+
# Required
44+
self.url = url
45+
self.has_custom_certificate = has_custom_certificate
46+
self.pending_update_count = pending_update_count
47+
self.last_error_date = kwargs.get('last_error_date')
48+
self.last_error_message = kwargs.get('last_error_message')
49+
50+
@staticmethod
51+
def de_json(data, bot):
52+
"""
53+
Args:
54+
data (dict):
55+
bot (telegram.Bot):
56+
57+
Returns:
58+
telegram.WebhookInfo:
59+
"""
60+
if not data:
61+
return None
62+
63+
return WebhookInfo(**data)

0 commit comments

Comments
 (0)
X Tutup