X Tutup
Skip to content

Commit 1142953

Browse files
committed
add checks for answer* methods
1 parent 1e250f2 commit 1142953

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

telegram/bot.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1953,11 +1953,22 @@ def answer_shipping_query(self,
19531953
:class:`telegram.TelegramError`
19541954
19551955
"""
1956+
1957+
if ok is True and (shipping_options is None or error_message is not None):
1958+
raise TelegramError(
1959+
'answerShippingQuery: If ok is True, shipping_options '
1960+
'should not be empty and there should not be error_message')
1961+
1962+
if ok is False and (shipping_options is not None or error_message is None):
1963+
raise TelegramError(
1964+
'answerShippingQuery: If ok is False, error_message '
1965+
'should not be empty and there should not be shipping_options')
1966+
19561967
url = '{0}/answerShippingQuery'.format(self.base_url)
19571968

19581969
data = {'shipping_query_id': shipping_query_id, 'ok': ok}
19591970

1960-
if shipping_options:
1971+
if ok is True:
19611972
data['shipping_options'] = shipping_options
19621973
if error_message:
19631974
data['error_message'] = error_message
@@ -1989,6 +2000,13 @@ def answer_pre_checkout_query(self, pre_checkout_query_id, ok,
19892000
:class:`telegram.TelegramError`
19902001
19912002
"""
2003+
2004+
if (ok is not True and error_message is None) or (ok is True and error_message is not None):
2005+
raise TelegramError(
2006+
'answerPreCheckoutQuery: If ok is True, there should '
2007+
'not be error_message; if ok is False, error_message '
2008+
'should not be empty')
2009+
19922010
url = '{0}/answerPreCheckoutQuery'.format(self.base_url)
19932011

19942012
data = {'pre_checkout_query_id': pre_checkout_query_id, 'ok': ok}

0 commit comments

Comments
 (0)
X Tutup