Skip to content

Commit 179fc14

Browse files
committed
Merge branch 'master' of github.com:python-telegram-bot/python-telegram-bot
2 parents 9d6c394 + da8a3ce commit 179fc14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2068
-154
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ target/
6565
# unitests files
6666
telegram.mp3
6767
telegram.mp4
68+
telegram2.mp4
6869
telegram.ogg
6970
telegram.png
7071
telegram.webp

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ install:
1818
script:
1919
- nosetests -v --with-flaky --no-flaky-report --with-coverage --cover-package=telegram/ tests
2020
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then pre-commit run --all-files; fi
21+
- python ./setup.py bdist_dumb
2122
after_success:
2223
coveralls

AUTHORS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ The following wonderful people contributed directly or indirectly to this projec
2424
- `Eli Gao <https://github.com/eligao>`_
2525
- `ErgoZ Riftbit Vaper <https://github.com/ergoz>`_
2626
- `Eugene Lisitsky <https://github.com/lisitsky>`_
27+
- `Eugenio Panadero <https://github.com/azogue>`_
2728
- `evgfilim1 <https://github.com/evgfilim1>`_
2829
- `franciscod <https://github.com/franciscod>`_
2930
- `Hugo Damer <https://github.com/HakimusGIT>`_
3031
- `Jacob Bom <https://github.com/bomjacob>`_
3132
- `JASON0916 <https://github.com/JASON0916>`_
33+
- `jeffffc <https://github.com/jeffffc>`_
3234
- `jh0ker <https://github.com/jh0ker>`_
3335
- `John Yong <https://github.com/whipermr5>`_
3436
- `jossalgon <https://github.com/jossalgon>`_

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Changes
9292

9393
- Rework ``JobQueue``
9494
- Introduce ``ConversationHandler``
95+
- Introduce ``telegram.constants`` - https://github.com/python-telegram-bot/python-telegram-bot/pull/342
9596

9697
**2016-07-12**
9798

docs/source/conf.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#
1212
# All configuration values have a default; values that are commented out
1313
# serve to show the default.
14-
1514
import sys
1615
import os
1716
import shlex
@@ -25,7 +24,7 @@
2524
# -- General configuration ------------------------------------------------
2625

2726
# If your documentation needs a minimal Sphinx version, state it here.
28-
#needs_sphinx = '1.0'
27+
needs_sphinx = '1.5.4' # fixes issues with autodoc-skip-member and napoleon
2928

3029
# Add any Sphinx extension module names here, as strings. They can be
3130
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
@@ -136,7 +135,7 @@
136135
# The name of an image file (within the static path) to use as favicon of the
137136
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
138137
# pixels large.
139-
#html_favicon = None
138+
html_favicon = 'ptb-logo-orange.ico'
140139

141140
# Add any paths that contain custom static files (such as style sheets) here,
142141
# relative to this directory. They are copied after the builtin static files,
@@ -289,3 +288,21 @@
289288

290289
# If true, do not generate a @detailmenu in the "Top" node's menu.
291290
#texinfo_no_detailmenu = False
291+
292+
# -- script stuff --------------------------------------------------------
293+
294+
import inspect
295+
296+
297+
def autodoc_skip_member(app, what, name, obj, skip, options):
298+
try:
299+
if inspect.getmodule(obj).__name__.startswith('telegram') and inspect.isfunction(obj):
300+
if name.lower() != name:
301+
return True
302+
except AttributeError:
303+
pass
304+
# Return None so napoleon can handle it
305+
306+
307+
def setup(app):
308+
app.connect('autodoc-skip-member', autodoc_skip_member)

docs/source/ptb-logo-orange.ico

361 KB
Binary file not shown.

examples/paymentbot.py

Whitespace-only changes.

telegram/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
from .messageentity import MessageEntity
5151
from .animation import Animation
5252
from .game import Game
53+
from .shippingaddress import ShippingAddress
54+
from .orderinfo import OrderInfo
55+
from .successfulpayment import SuccessfulPayment
56+
from .invoice import Invoice
5357
from .message import Message
5458
from .inputmessagecontent import InputMessageContent
5559
from .callbackquery import CallbackQuery
@@ -82,6 +86,10 @@
8286
from .inputlocationmessagecontent import InputLocationMessageContent
8387
from .inputvenuemessagecontent import InputVenueMessageContent
8488
from .inputcontactmessagecontent import InputContactMessageContent
89+
from .labeledprice import LabeledPrice
90+
from .shippingoption import ShippingOption
91+
from .precheckoutquery import PreCheckoutQuery
92+
from .shippingquery import ShippingQuery
8593
from .webhookinfo import WebhookInfo
8694
from .gamehighscore import GameHighScore
8795
from .videonote import VideoNote
@@ -114,5 +122,6 @@
114122
'Video', 'Voice', 'MAX_MESSAGE_LENGTH', 'MAX_CAPTION_LENGTH', 'SUPPORTED_WEBHOOK_PORTS',
115123
'MAX_FILESIZE_DOWNLOAD', 'MAX_FILESIZE_UPLOAD', 'MAX_MESSAGES_PER_SECOND_PER_CHAT',
116124
'MAX_MESSAGES_PER_SECOND', 'MAX_MESSAGES_PER_MINUTE_PER_GROUP', 'WebhookInfo', 'Animation',
117-
'Game', 'GameHighScore', 'VideoNote'
125+
'Game', 'GameHighScore', 'VideoNote', 'LabeledPrice', 'SuccessfulPayment', 'ShippingOption',
126+
'ShippingAddress', 'PreCheckoutQuery', 'OrderInfo', 'Invoice', 'ShippingQuery'
118127
]

telegram/bot.py

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,214 @@ def get_game_high_scores(self,
18181818

18191819
return [GameHighScore.de_json(hs, self) for hs in result]
18201820

1821+
@log
1822+
@message
1823+
def send_invoice(self,
1824+
chat_id,
1825+
title,
1826+
description,
1827+
payload,
1828+
provider_token,
1829+
start_parameter,
1830+
currency,
1831+
prices,
1832+
photo_url=None,
1833+
photo_size=None,
1834+
photo_width=None,
1835+
photo_height=None,
1836+
need_name=None,
1837+
need_phone_number=None,
1838+
need_email=None,
1839+
need_shipping_address=None,
1840+
is_flexible=None,
1841+
disable_notification=False,
1842+
reply_to_message_id=None,
1843+
reply_markup=None,
1844+
timeout=None,
1845+
**kwargs):
1846+
"""
1847+
Use this method to send invoices.
1848+
1849+
Args:
1850+
chat_id (int|str): Unique identifier for the target private chat
1851+
title (str): Product name
1852+
description (str): Product description
1853+
payload (str): Bot-defined invoice payload, 1-128 bytes. This will not be displayed
1854+
to the user, use for your internal processes.
1855+
provider_token (str): Payments provider token, obtained via Botfather
1856+
start_parameter (str): Unique deep-linking parameter that can be used to generate
1857+
this invoice when used as a start parameter
1858+
currency (str): Three-letter ISO 4217 currency code
1859+
prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of components
1860+
(e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
1861+
photo_url (Optional[str]): URL of the product photo for the invoice. Can be a photo of
1862+
the goods or a marketing image for a service. People like it better when they
1863+
see what they are paying for.
1864+
photo_size (Optional[str]): Photo size
1865+
photo_width (Optional[int]): Photo width
1866+
photo_height (Optional[int]): Photo height
1867+
need_name (Optional[bool]): Pass True, if you require the user's full name to complete
1868+
the order
1869+
need_phone_number (Optional[bool]): Pass True, if you require the user's phone number
1870+
to complete the order
1871+
need_email (Optional[bool]): Pass True, if you require the user's email to
1872+
complete the order
1873+
need_shipping_address (Optional[bool]): Pass True, if you require the user's shipping
1874+
address to complete the order
1875+
is_flexible (Optional[bool]): Pass True, if the final price depends on the shipping
1876+
method
1877+
disable_notification (Optional[bool]): Sends the message silently. iOS users will not
1878+
receive a notification, Android users will receive a notification with no sound.
1879+
reply_to_message_id (Optional[int]): If the message is a reply, ID of the original
1880+
message.
1881+
reply_markup (Optional[:class:`telegram.ReplyMarkup`]): Additional interface options.
1882+
An inlinekeyboard. If empty, one 'Pay total price' button will be shown. If not
1883+
empty, the first button must be a Pay button.
1884+
timeout (Optional[int|float]): If this value is specified, use it as the read timeout
1885+
from the server (instead of the one specified during creation of the connection
1886+
pool).
1887+
**kwargs (dict): Arbitrary keyword arguments.
1888+
1889+
Returns:
1890+
:class:`telegram.Message`: On success, instance representing the message posted.
1891+
1892+
Raises:
1893+
:class:`telegram.TelegramError`
1894+
1895+
"""
1896+
url = '{0}/sendInvoice'.format(self.base_url)
1897+
1898+
data = {
1899+
'chat_id': chat_id,
1900+
'title': title,
1901+
'description': description,
1902+
'payload': payload,
1903+
'provider_token': provider_token,
1904+
'start_parameter': start_parameter,
1905+
'currency': currency,
1906+
'prices': [p.to_dict() for p in prices]
1907+
}
1908+
1909+
if photo_url is not None:
1910+
data['photo_url'] = photo_url
1911+
if photo_size is not None:
1912+
data['photo_size'] = photo_size
1913+
if photo_width is not None:
1914+
data['photo_width'] = photo_width
1915+
if photo_height is not None:
1916+
data['photo_height'] = photo_height
1917+
if need_name is not None:
1918+
data['need_name'] = need_name
1919+
if need_phone_number is not None:
1920+
data['need_phone_number'] = need_phone_number
1921+
if need_email is not None:
1922+
data['need_email'] = need_email
1923+
if need_shipping_address is not None:
1924+
data['need_shipping_address'] = need_shipping_address
1925+
if is_flexible is not None:
1926+
data['is_flexible'] = is_flexible
1927+
1928+
return url, data
1929+
1930+
def answer_shipping_query(self,
1931+
shipping_query_id,
1932+
ok,
1933+
shipping_options=None,
1934+
error_message=None,
1935+
timeout=None,
1936+
**kwargs):
1937+
"""
1938+
If you sent an invoice requesting a shipping address and the parameter is_flexible was
1939+
specified, the Bot API will send an Update with a shipping_query field to the bot. Use
1940+
this method to reply to shipping queries.
1941+
1942+
Args:
1943+
shipping_query_id (str): Unique identifier for the query to be answered
1944+
ok (bool): Specify True if delivery to the specified address is possible and False if
1945+
there are any problems (for example, if delivery to the specified address
1946+
is not possible)
1947+
shipping_options (Optional[List[:class:`telegram.ShippingOption`]]): Required if ok is
1948+
True. A list of available shipping options.
1949+
error_message (Optional[str]): Required if ok is False. Error message in human readable
1950+
form that explains why it is impossible to complete the order (e.g. "Sorry,
1951+
delivery to your desired address is unavailable'). Telegram will display this
1952+
message to the user.
1953+
**kwargs (dict): Arbitrary keyword arguments.
1954+
1955+
Returns:
1956+
bool: On success, `True` is returned.
1957+
1958+
Raises:
1959+
:class:`telegram.TelegramError`
1960+
1961+
"""
1962+
1963+
if ok is True and (shipping_options is None or error_message is not None):
1964+
raise TelegramError(
1965+
'answerShippingQuery: If ok is True, shipping_options '
1966+
'should not be empty and there should not be error_message')
1967+
1968+
if ok is False and (shipping_options is not None or error_message is None):
1969+
raise TelegramError(
1970+
'answerShippingQuery: If ok is False, error_message '
1971+
'should not be empty and there should not be shipping_options')
1972+
1973+
url_ = '{0}/answerShippingQuery'.format(self.base_url)
1974+
1975+
data = {'shipping_query_id': shipping_query_id, 'ok': ok}
1976+
1977+
if ok is True:
1978+
data['shipping_options'] = shipping_options
1979+
if error_message is not None:
1980+
data['error_message'] = error_message
1981+
1982+
result = self._request.post(url_, data, timeout=timeout)
1983+
1984+
return result
1985+
1986+
def answer_pre_checkout_query(self, pre_checkout_query_id, ok,
1987+
error_message=None, timeout=None, **kwargs):
1988+
"""
1989+
If you sent an invoice requesting a shipping address and the parameter is_flexible was
1990+
specified, the Bot API will send an Update with a shipping_query field to the bot.
1991+
Use this method to reply to shipping queries.
1992+
1993+
Args:
1994+
pre_checkout_query_id (str): Unique identifier for the query to be answered
1995+
ok (bool): Specify True if everything is alright (goods are available, etc.) and the
1996+
bot is ready to proceed with the order. Use False if there are any problems.
1997+
error_message (Optional[str]): Required if ok is False. Error message in human readable
1998+
form that explains the reason for failure to proceed with the checkout (e.g.
1999+
"Sorry, somebody just bought the last of our amazing black T-shirts while you were
2000+
busy filling out your payment details. Please choose a different color or
2001+
garment!"). Telegram will display this message to the user.
2002+
**kwargs (dict): Arbitrary keyword arguments.
2003+
2004+
Returns:
2005+
bool: On success, `True` is returned.
2006+
2007+
Raises:
2008+
:class:`telegram.TelegramError`
2009+
2010+
"""
2011+
2012+
if not (ok ^ (error_message is None)):
2013+
raise TelegramError(
2014+
'answerPreCheckoutQuery: If ok is True, there should '
2015+
'not be error_message; if ok is False, error_message '
2016+
'should not be empty')
2017+
2018+
url_ = '{0}/answerPreCheckoutQuery'.format(self.base_url)
2019+
2020+
data = {'pre_checkout_query_id': pre_checkout_query_id, 'ok': ok}
2021+
2022+
if error_message is not None:
2023+
data['error_message'] = error_message
2024+
2025+
result = self._request.post(url_, data, timeout=timeout)
2026+
2027+
return result
2028+
18212029
@staticmethod
18222030
def de_json(data, bot):
18232031
data = super(Bot, Bot).de_json(data, bot)
@@ -1873,3 +2081,6 @@ def __reduce__(self):
18732081
getWebhookInfo = get_webhook_info
18742082
setGameScore = set_game_score
18752083
getGameHighScores = get_game_high_scores
2084+
sendInvoice = send_invoice
2085+
answerShippingQuery = answer_shipping_query
2086+
answerPreCheckoutQuery = answer_pre_checkout_query

telegram/chat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Chat(TelegramObject):
4141
username(Optional[str]):
4242
first_name(Optional[str]):
4343
last_name(Optional[str]):
44-
bot (Optional[Bot]): The Bot to use for instance methods
44+
bot (Optional[telegram.Bot]): The Bot to use for instance methods
4545
**kwargs (dict): Arbitrary keyword arguments.
4646
4747
"""

0 commit comments

Comments
 (0)