Compare commits

...

28 Commits

Author SHA1 Message Date
Hinrich Mahler 171953f109 Bump version to v20.0 2023-01-01 17:20:54 +01:00
Harshil 606773d8f0 API 6.4 (#3449)
Co-authored-by: poolitzer <github@poolitzer.eu>
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
2023-01-01 17:00:49 +01:00
Bibo-Joshi f408b1a2dd Documentation Improvements (#3428, #3423, #3429, #3441, #3404, #3443)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
Co-authored-by: Viicos <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: Eisberge <22561095+Eisberge@users.noreply.github.com>
Co-authored-by: Joshua Tang <joshuaystang@gmail.com>
2023-01-01 16:24:00 +01:00
Harshil 3e7ab7e7af Downgrade sphinx to 5.3.0 to Fix Search (#3457) 2023-01-01 15:48:48 +01:00
Aditya 456b81d22a Allow Sequence Input for Bot Methods (#3412)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
2023-01-01 14:24:30 +01:00
Bibo-Joshi cb90814829 Update Link-Check CI and Replace a Dead Link (#3456) 2023-01-01 13:48:24 +01:00
Bibo-Joshi 7b61a30fb1 Freeze Classes Without Arguments (#3453) 2023-01-01 13:04:37 +01:00
dependabot[bot] f3a9b74445 Bump sphinx from 5.3.0 to 6.0.0 (#3450)
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
2022-12-31 16:59:49 +01:00
Dmitry Kolomatskiy d996e8f9c9 Add New Constants (#3444) 2022-12-30 14:09:06 +01:00
Bibo-Joshi 0a6725852f Override Bot.__deepcopy__ to Raise TypeError (#3446) 2022-12-30 10:50:49 +01:00
Bibo-Joshi b8fbb89fae Add Log Decorator to Bot.get_webhook_info (#3442) 2022-12-27 19:02:50 +01:00
Bibo-Joshi f3650364b9 Add Documention On Verifying Releases (#3436) 2022-12-21 16:55:58 +01:00
Bibo-Joshi 5b629ede56 Drop Undocumented Job.__lt__ (#3432) 2022-12-19 18:32:53 +01:00
Hinrich Mahler 28afeccf70 Bump version to v20.0b0 2022-12-15 15:54:00 +01:00
Bibo-Joshi 9467847d74 Documentation Improvements (#3386)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
Co-authored-by: Viicos <65306057+Viicos@users.noreply.github.com>
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
2022-12-15 15:20:04 +01:00
Bibo-Joshi b11a0c7778 Make TelegramObject Immutable (#3249) 2022-12-15 15:00:36 +01:00
Bibo-Joshi ff645c6fe2 Reduce Code Duplication in Testing Defaults (#3419) 2022-12-12 10:51:33 +01:00
dependabot[bot] 9c3053b3f9 Bump pytest-xdist from 3.0.2 to 3.1.0 (#3415) 2022-12-11 15:28:12 +01:00
dependabot[bot] 5a6c9cc777 Bump pytest-asyncio from 0.20.2 to 0.20.3 (#3417) 2022-12-11 15:27:51 +01:00
pre-commit-ci[bot] 6e4a1f0a21 pre-commit autoupdate (#3409)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bibo-Joshi <22366557+Bibo-Joshi@users.noreply.github.com>
2022-12-06 11:28:47 +01:00
Aditya f8be97c12c Add Notes and Warnings About Optional Dependencies (#3393) 2022-12-02 12:08:11 +01:00
Harshil 4123e7aa57 Simplify Internals of Bot Methods (#3396) 2022-12-01 19:26:01 +01:00
Dmitry Kolomatskiy 637cc574ab Reduce Code Duplication in Several Bot Methods (#3385) 2022-11-26 19:05:44 +01:00
Hinrich Mahler 3042f187ed Bump version to v20.0a6 2022-11-24 12:32:43 +01:00
Bibo-Joshi 867f742d08 Only Persist Arbitrary callback_data if ExtBot.callback_data_cache is Present (#3384) 2022-11-24 12:13:54 +01:00
Harshil 1724212458 Improve Backwards Compatibility of TelegramObjects Pickle Behavior (#3382)
Co-authored-by: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com>
2022-11-24 12:11:37 +01:00
Bibo-Joshi 05c6ca06f8 Fix Naming and Keyword Arguments of File.download_* Methods (#3380) 2022-11-24 12:09:51 +01:00
Poolitzer 8c03f0e2eb Fix Return Value Annotation of Chat.create_forum_topic (#3381)
Co-authored-by: Dmitry Kolomatskiy <58207913+lemontree210@users.noreply.github.com>
2022-11-23 13:21:10 +01:00
264 changed files with 6264 additions and 2888 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: [3.7]
python-version: [3.9]
os: [ubuntu-latest]
fail-fast: False
steps:
+2 -2
View File
@@ -5,7 +5,7 @@ on:
- master
- doc-fixes
push:
branches:
branches:
- master
- doc-fixes
@@ -15,7 +15,7 @@ jobs:
runs-on: ${{matrix.os}}
strategy:
matrix:
python-version: [3.7]
python-version: [3.9]
os: [ubuntu-latest]
fail-fast: False
steps:
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -16,11 +16,11 @@ repos:
- --diff
- --check
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/pylint
rev: v2.15.5
rev: v2.15.8
hooks:
- id: pylint
files: ^(telegram|examples)/.*\.py$
@@ -38,7 +38,7 @@ repos:
- aiolimiter~=1.0.0
- . # this basically does `pip install -e .`
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
name: mypy-ptb
@@ -65,7 +65,7 @@ repos:
- cachetools~=5.2.0
- . # this basically does `pip install -e .`
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.0
rev: v3.3.0
hooks:
- id: pyupgrade
files: ^(telegram|examples|tests)/.*\.py$
+1
View File
@@ -74,6 +74,7 @@ The following wonderful people contributed directly or indirectly to this projec
- `LRezende <https://github.com/lrezende>`_
- `macrojames <https://github.com/macrojames>`_
- `Matheus Lemos <https://github.com/mlemosf>`_
- `Michael Dix <https://github.com/Eisberge>`_
- `Michael Elovskikh <https://github.com/wronglink>`_
- `miles <https://github.com/miles170>`_
- `Mischa Krüger <https://github.com/Makman2>`_
+107
View File
@@ -2,6 +2,113 @@
Changelog
=========
Version 20.0
============
*Released 2023-01-01*
This is the technical changelog for version 20.0. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel <https://t.me/pythontelegrambotchannel>`_.
Major Changes
-------------
- Full Support For Bot API 6.4 (`#3449`_)
Minor Changes, Documentation Improvements and CI
------------------------------------------------
- Documentation Improvements (`#3428`_, `#3423`_, `#3429`_, `#3441`_, `#3404`_, `#3443`_)
- Allow ``Sequence`` Input for Bot Methods (`#3412`_)
- Update Link-Check CI and Replace a Dead Link (`#3456`_)
- Freeze Classes Without Arguments (`#3453`_)
- Add New Constants (`#3444`_)
- Override ``Bot.__deepcopy__`` to Raise ``TypeError`` (`#3446`_)
- Add Log Decorator to ``Bot.get_webhook_info`` (`#3442`_)
- Add Documentation On Verifying Releases (`#3436`_)
- Drop Undocumented ``Job.__lt__`` (`#3432`_)
Dependencies
------------
- Downgrade ``sphinx`` to 5.3.0 to Fix Search (`#3457`_)
- Bump ``sphinx`` from 5.3.0 to 6.0.0 (`#3450`_)
.. _`#3449`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3449
.. _`#3428`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3428
.. _`#3423`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3423
.. _`#3429`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3429
.. _`#3441`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3441
.. _`#3404`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3404
.. _`#3443`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3443
.. _`#3412`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3412
.. _`#3456`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3456
.. _`#3453`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3453
.. _`#3444`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3444
.. _`#3446`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3446
.. _`#3442`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3442
.. _`#3436`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3436
.. _`#3432`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3432
.. _`#3457`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3457
.. _`#3450`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3450
Version 20.0b0
==============
*Released 2022-12-15*
This is the technical changelog for version 20.0b0. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel <https://t.me/pythontelegrambotchannel>`_.
Major Changes
-------------
- Make ``TelegramObject`` Immutable (`#3249`_)
Minor Changes, Documentation Improvements and CI
------------------------------------------------
- Reduce Code Duplication in Testing ``Defaults`` (`#3419`_)
- Add Notes and Warnings About Optional Dependencies (`#3393`_)
- Simplify Internals of ``Bot`` Methods (`#3396`_)
- Reduce Code Duplication in Several ``Bot`` Methods (`#3385`_)
- Documentation Improvements (`#3386`_, `#3395`_, `#3398`_, `#3403`_)
Dependencies
------------
- Bump ``pytest-xdist`` from 3.0.2 to 3.1.0 (`#3415`_)
- Bump ``pytest-asyncio`` from 0.20.2 to 0.20.3 (`#3417`_)
- ``pre-commit`` autoupdate (`#3409`_)
.. _`#3249`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3249
.. _`#3419`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3419
.. _`#3393`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3393
.. _`#3396`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3396
.. _`#3385`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3385
.. _`#3386`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3386
.. _`#3395`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3395
.. _`#3398`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3398
.. _`#3403`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3403
.. _`#3415`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3415
.. _`#3417`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3417
.. _`#3409`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3409
Version 20.0a6
==============
*Released 2022-11-24*
This is the technical changelog for version 20.0a6. More elaborate release notes can be found in the news channel `@pythontelegrambotchannel <https://t.me/pythontelegrambotchannel>`_.
Bug Fixes
---------
- Only Persist Arbitrary ``callback_data`` if ``ExtBot.callback_data_cache`` is Present (`#3384`_)
- Improve Backwards Compatibility of ``TelegramObjects`` Pickle Behavior (`#3382`_)
- Fix Naming and Keyword Arguments of ``File.download_*`` Methods (`#3380`_)
- Fix Return Value Annotation of ``Chat.create_forum_topic`` (`#3381`_)
.. _`#3384`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3384
.. _`#3382`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3382
.. _`#3380`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3380
.. _`#3381`: https://github.com/python-telegram-bot/python-telegram-bot/pull/3381
Version 20.0a5
==============
*Released 2022-11-22*
+17 -5
View File
@@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot/
:alt: Supported Python versions
.. image:: https://img.shields.io/badge/Bot%20API-6.3-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.4-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions
@@ -93,7 +93,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================
All types and methods of the Telegram Bot API **6.2** are supported.
All types and methods of the Telegram Bot API **6.4** are supported.
Installing
==========
@@ -114,6 +114,18 @@ You can also install ``python-telegram-bot`` from source, though this is usually
$ cd python-telegram-bot
$ python setup.py install
Verifying Releases
------------------
We sign all the releases with a GPG key.
The signatures are uploaded to both the `GitHub releases page <https://github.com/python-telegram-bot/python-telegram-bot/releases>`_ and the `PyPI project <https://pypi.org/project/python-telegram-bot/>`_ and end with a suffix ``.asc``.
Please find the public keys `here <https://github.com/python-telegram-bot/python-telegram-bot/tree/master/public_keys>`_.
The keys are named in the format ``<first_version>-<last_version>.gpg`` or ``<first_version>-current.gpg`` if the key is currently being used for new releases.
In addition, the GitHub release page also contains the sha1 hashes of the release files in the files with the suffix ``.sha1``.
This allows you to verify that a release file that you downloaded was indeed provided by the ``python-telegram-bot`` team.
Dependencies & Their Versions
-----------------------------
@@ -136,9 +148,9 @@ Optional Dependencies
PTB can be installed with optional dependencies:
* ``pip install python-telegram-bot[passport]`` installs the `cryptography>=3.0 <https://cryptography.io/en/stable>`_ library. Use this, if you want to use Telegram Passport related functionality.
* ``pip install python-telegram-bot[socks]`` installs ``httpx[socks]``. Use this, if you want to work behind a Socks5 server.
* ``pip install python-telegram-bot[rate-limiter]`` installs ``aiolimiter~=1.0.0``. Use this, if you want to use ``telegram.ext.AIORateLimiter``.
* ``pip install python-telegram-bot[webhooks]`` installs the `tornado~=6.2 <https://www.tornadoweb.org/en/stable/>`_ library. Use this, if you want to use ``telegram.ext.Updater.start_webhook``/``telegram.ext.Application.start_webhook``.
* ``pip install python-telegram-bot[socks]`` installs `httpx[socks] <https://www.python-httpx.org/#dependencies>`_. Use this, if you want to work behind a Socks5 server.
* ``pip install python-telegram-bot[rate-limiter]`` installs `aiolimiter~=1.0.0 <https://aiolimiter.readthedocs.io/en/stable/>`_. Use this, if you want to use ``telegram.ext.AIORateLimiter``.
* ``pip install python-telegram-bot[webhooks]`` installs the `tornado~=6.2 <https://www.tornadoweb.org/en/stable/>`_ library. Use this, if you want to use ``telegram.ext.Updater.start_webhook``/``telegram.ext.Application.run_webhook``.
* ``pip install python-telegram-bot[callback-data]`` installs the `cachetools~=5.2.0 <https://cachetools.readthedocs.io/en/latest/>`_ library. Use this, if you want to use `arbitrary callback_data <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Arbitrary-callback_data>`_.
* ``pip install python-telegram-bot[job-queue]`` installs the `APScheduler~=3.9.1 <https://apscheduler.readthedocs.io/en/3.x/>`_ library and enforces `pytz>=2018.6 <https://pypi.org/project/pytz/>`_, where ``pytz`` is a dependency of ``APScheduler``. Use this, if you want to use the ``telegram.ext.JobQueue``.
+16 -4
View File
@@ -14,7 +14,7 @@
:target: https://pypi.org/project/python-telegram-bot-raw/
:alt: Supported Python versions
.. image:: https://img.shields.io/badge/Bot%20API-6.3-blue?logo=telegram
.. image:: https://img.shields.io/badge/Bot%20API-6.4-blue?logo=telegram
:target: https://core.telegram.org/bots/api-changelog
:alt: Supported Bot API versions
@@ -34,7 +34,7 @@
:target: https://github.com/python-telegram-bot/python-telegram-bot/
:alt: Github Actions workflow
.. image:: https://app.codecov.io/gh/python-telegram-bot/python-telegram-bot
.. image:: https://codecov.io/gh/python-telegram-bot/python-telegram-bot/branch/master/graph/badge.svg
:target: https://app.codecov.io/gh/python-telegram-bot/python-telegram-bot
:alt: Code coverage
@@ -89,7 +89,7 @@ Installing both ``python-telegram-bot`` and ``python-telegram-bot-raw`` in conju
Telegram API support
====================
All types and methods of the Telegram Bot API **6.2** are supported.
All types and methods of the Telegram Bot API **6.4** are supported.
Installing
==========
@@ -115,6 +115,18 @@ Note
Installing the ``.tar.gz`` archive available on PyPi directly via ``pip`` will *not* work as expected, as ``pip`` does not recognize that it should use ``setup-raw.py`` instead of ``setup.py``.
Verifying Releases
------------------
We sign all the releases with a GPG key.
The signatures are uploaded to both the `GitHub releases page <https://github.com/python-telegram-bot/python-telegram-bot/releases>`_ and the `PyPI project <https://pypi.org/project/python-telegram-bot/>`_ and end with a suffix ``.asc``.
Please find the public keys `here <https://github.com/python-telegram-bot/python-telegram-bot/tree/master/public_keys>`_.
The keys are named in the format ``<first_version>-<last_version>.gpg`` or ``<first_version>-current.gpg`` if the key is currently being used for new releases.
In addition, the GitHub release page also contains the sha1 hashes of the release files in the files with the suffix ``.sha1``.
This allows you to verify that a release file that you downloaded was indeed provided by the ``python-telegram-bot`` team.
Dependencies & Their Versions
-----------------------------
@@ -137,7 +149,7 @@ Optional Dependencies
PTB can be installed with optional dependencies:
* ``pip install python-telegram-bot-raw[passport]`` installs the `cryptography>=3.0 <https://cryptography.io/en/stable>`_ library. Use this, if you want to use Telegram Passport related functionality.
* ``pip install python-telegram-bot-raw[socks]`` installs ``httpx[socks]``. Use this, if you want to work behind a Socks5 server.
* ``pip install python-telegram-bot-raw[socks]`` installs `httpx[socks] <https://www.python-httpx.org/#dependencies>`_. Use this, if you want to work behind a Socks5 server.
To install multiple optional dependencies, separate them by commas, e.g. ``pip install python-telegram-bot-raw[passport,socks]``.
+1 -1
View File
@@ -1,6 +1,6 @@
sphinx==5.3.0
sphinx-pypi-upload
furo==2022.9.29
furo==2022.12.7
git+https://github.com/harshil21/furo-sphinx-search@be5cfa221a01f6e259bb2bb1f76d6ede7ffc1f11#egg=furo-sphinx-search
sphinx-paramlinks==0.5.4
sphinxcontrib-mermaid==0.7.1
+6 -2
View File
@@ -29,9 +29,9 @@ author = "Leandro Toledo"
# built documents.
#
# The short X.Y version.
version = "20.0a5" # telegram.__version__[:3]
version = "20.0" # telegram.__version__[:3]
# The full version, including alpha/beta/rc tags.
release = "20.0a5" # telegram.__version__
release = "20.0" # telegram.__version__
# If your documentation needs a minimal Sphinx version, state it here.
needs_sphinx = "5.1.1"
@@ -44,11 +44,15 @@ extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"sphinx.ext.linkcode",
"sphinx.ext.extlinks",
"sphinx_paramlinks",
"sphinxcontrib.mermaid",
"sphinx_search.extension",
]
# For shorter links to Wiki in docstrings
extlinks = {"wiki": ("https://github.com/python-telegram-bot/python-telegram-bot/wiki/%s", "%s")}
# Use intersphinx to reference the python builtin library docs
intersphinx_mapping = {
"python": ("https://docs.python.org/3", None),
+3
View File
@@ -40,6 +40,7 @@ up a job to send a message to that user after 30 seconds. The user can
also cancel the timer by sending ``/unset``. To learn more about the
``JobQueue``, read `this wiki
article <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Extensions-%E2%80%93-JobQueue>`__.
Note: To use ``JobQueue``, you must install PTB via ``pip install python-telegram-bot[job-queue]``
:any:`examples.conversationbot`
-------------------------------
@@ -115,6 +116,7 @@ Dont forget to enable and configure payments with
`@BotFather <https://telegram.me/BotFather>`_. Check out this
`guide <https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport>`__
on Telegram passports in PTB.
Note: To use Telegram Passport, you must install PTB via ``pip install python-telegram-bot[passport]``
:any:`examples.paymentbot`
--------------------------
@@ -162,6 +164,7 @@ combination with ``telegram.ext.Application``.
This example showcases how PTBs “arbitrary callback data” feature can be
used.
Note: To use arbitrary callback data, you must install PTB via ``pip install python-telegram-bot[callback-data]``
Pure API
--------
+12 -2
View File
@@ -267,16 +267,26 @@
* - :meth:`~telegram.Bot.close_forum_topic`
- Used for closing a forum topic
* - :meth:`~telegram.Bot.close_general_forum_topic`
- Used for closing the general forum topic
* - :meth:`~telegram.Bot.create_forum_topic`
- Used to create a topic
* - :meth:`~telegram.Bot.delete_forum_topic`
- Used for deleting a forum topic
* - :meth:`~telegram.Bot.edit_forum_topic`
- Used to edit a topic
* - :meth:`~telegram.Bot.reopen_forum_topic`
- Used to reopen a topic
* - :meth:`~telegram.Bot.edit_general_forum_topic`
- Used to edit the general topic
* - :meth:`~telegram.Bot.get_forum_topic_icon_stickers`
- Used to get custom emojis to use as topic icons
* - :meth:`~telegram.Bot.hide_general_forum_topic`
- Used to hide the general topic
* - :meth:`~telegram.Bot.unhide_general_forum_topic`
- Used to unhide the general topic
* - :meth:`~telegram.Bot.reopen_forum_topic`
- Used to reopen a topic
* - :meth:`~telegram.Bot.reopen_general_forum_topic`
- Used to reopen the general topic
* - :meth:`~telegram.Bot.unpin_all_forum_topic_messages`
- Used to unpin all messages in a forum topic
+5
View File
@@ -2,6 +2,7 @@ Available Types
---------------
.. toctree::
:titlesonly:
telegram.animation
telegram.audio
@@ -38,7 +39,10 @@ Available Types
telegram.forumtopic
telegram.forumtopicclosed
telegram.forumtopiccreated
telegram.forumtopicedited
telegram.forumtopicreopened
telegram.generalforumtopichidden
telegram.generalforumtopicunhidden
telegram.inlinekeyboardbutton
telegram.inlinekeyboardmarkup
telegram.inputfile
@@ -83,4 +87,5 @@ Available Types
telegram.webappdata
telegram.webappinfo
telegram.webhookinfo
telegram.writeaccessallowed
+2 -1
View File
@@ -3,4 +3,5 @@ telegram.Bot
.. autoclass:: telegram.Bot
:members:
:show-inheritance:
:show-inheritance:
:special-members: __reduce__, __deepcopy__
+1
View File
@@ -2,6 +2,7 @@ Arbitrary Callback Data
-----------------------
.. toctree::
:titlesonly:
telegram.ext.callbackdatacache
telegram.ext.invalidcallbackdata
@@ -2,6 +2,7 @@ Handlers
--------
.. toctree::
:titlesonly:
telegram.ext.basehandler
telegram.ext.callbackqueryhandler
@@ -2,6 +2,7 @@ Persistence
-----------
.. toctree::
:titlesonly:
telegram.ext.basepersistence
telegram.ext.dictpersistence
@@ -2,6 +2,7 @@ Rate Limiting
-------------
.. toctree::
:titlesonly:
telegram.ext.baseratelimiter
telegram.ext.aioratelimiter
@@ -0,0 +1,6 @@
telegram.ForumTopicEdited
=========================
.. autoclass:: telegram.ForumTopicEdited
:members:
:show-inheritance:
+1
View File
@@ -2,6 +2,7 @@ Games
-----
.. toctree::
:titlesonly:
telegram.callbackgame
telegram.game
@@ -0,0 +1,6 @@
telegram.GeneralForumTopicHidden
================================
.. autoclass:: telegram.GeneralForumTopicHidden
:members:
:show-inheritance:
@@ -0,0 +1,6 @@
telegram.GeneralForumTopicUnhidden
==================================
.. autoclass:: telegram.GeneralForumTopicUnhidden
:members:
:show-inheritance:
+1
View File
@@ -2,6 +2,7 @@ Inline Mode
-----------
.. toctree::
:titlesonly:
telegram.choseninlineresult
telegram.inlinequery
+1
View File
@@ -2,6 +2,7 @@ Passport
--------
.. toctree::
:titlesonly:
telegram.credentials
telegram.datacredentials
+1
View File
@@ -2,6 +2,7 @@ Payments
--------
.. toctree::
:titlesonly:
telegram.invoice
telegram.labeledprice
+2
View File
@@ -4,6 +4,8 @@ telegram.request Module
.. versionadded:: 20.0
.. toctree::
:titlesonly:
telegram.request.baserequest
telegram.request.requestdata
telegram.request.httpxrequest
+1
View File
@@ -2,6 +2,7 @@ Stickers
--------
.. toctree::
:titlesonly:
telegram.maskposition
telegram.sticker
+1 -1
View File
@@ -4,4 +4,4 @@ telegram.TelegramObject
.. autoclass:: telegram.TelegramObject
:members:
:show-inheritance:
:special-members: __repr__, __getitem__, __eq__, __hash__, __setstate__, __getstate__, __deepcopy__
:special-members: __repr__, __getitem__, __eq__, __hash__, __setstate__, __getstate__, __deepcopy__, __setattr__, __delattr__
@@ -0,0 +1,6 @@
telegram.WriteAccessAllowed
===========================
.. autoclass:: telegram.WriteAccessAllowed
:members:
:show-inheritance:
+1
View File
@@ -2,6 +2,7 @@ Auxiliary modules
=================
.. toctree::
:titlesonly:
telegram.constants
telegram.error
+12 -2
View File
@@ -34,10 +34,20 @@
.. |allow_sending_without_reply| replace:: Pass :obj:`True`, if the message should be sent even if the specified replied-to message is not found.
.. |caption_entities| replace:: List of special entities that appear in the caption, which can be specified instead of ``parse_mode``.
.. |caption_entities| replace:: Sequence of special entities that appear in the caption, which can be specified instead of ``parse_mode``.
.. |protect_content| replace:: Protects the contents of the sent message from forwarding and saving.
.. |disable_notification| replace:: Sends the message silently. Users will receive a notification with no sound.
.. |reply_to_msg_id| replace:: If the message is a reply, ID of the original message.
.. |reply_to_msg_id| replace:: If the message is a reply, ID of the original message.
.. |sequenceclassargs| replace:: |sequenceargs| The input is converted to a tuple.
.. |tupleclassattrs| replace:: This attribute is now an immutable tuple.
.. |alwaystuple| replace:: This attribute is now always a tuple, that may be empty.
.. |sequenceargs| replace:: Accepts any :class:`collections.abc.Sequence` as input instead of just a list.
.. |captionentitiesattr| replace:: Tuple of special entities that appear in the caption, which can be specified instead of ``parse_mode``.
+4
View File
@@ -6,6 +6,10 @@
For detailed info on arbitrary callback data, see the wiki page at
https://github.com/python-telegram-bot/python-telegram-bot/wiki/Arbitrary-callback_data
Note:
To use arbitrary callback data, you must install PTB via
`pip install python-telegram-bot[callback-data]`
"""
import logging
from typing import List, Tuple, cast
+1 -1
View File
@@ -81,7 +81,7 @@ async def photo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
"""Stores the photo and asks for a location."""
user = update.message.from_user
photo_file = await update.message.photo[-1].get_file()
await photo_file.download_to_memory("user_photo.jpg")
await photo_file.download_to_drive("user_photo.jpg")
logger.info("Photo of %s: %s", user.first_name, "user_photo.jpg")
await update.message.reply_text(
"Gorgeous! Now, send me your location please, or send /skip if you don't want to."
+8 -5
View File
@@ -10,6 +10,9 @@ See https://telegram.org/blog/passport for info about what telegram passport is.
See https://github.com/python-telegram-bot/python-telegram-bot/wiki/Telegram-Passport
for how to use Telegram Passport properly with python-telegram-bot.
Note:
To use Telegram Passport, you must install PTB via
`pip install python-telegram-bot[passport]`
"""
import logging
from pathlib import Path
@@ -77,25 +80,25 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
for file in data.files:
actual_file = await file.get_file()
print(actual_file)
await actual_file.download_to_memory()
await actual_file.download_to_drive()
if (
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
and data.front_side
):
front_file = await data.front_side.get_file()
print(data.type, front_file)
await front_file.download_to_memory()
await front_file.download_to_drive()
if data.type in ("driver_license" and "identity_card") and data.reverse_side:
reverse_file = await data.reverse_side.get_file()
print(data.type, reverse_file)
await reverse_file.download_to_memory()
await reverse_file.download_to_drive()
if (
data.type in ("passport", "driver_license", "identity_card", "internal_passport")
and data.selfie
):
selfie_file = await data.selfie.get_file()
print(data.type, selfie_file)
await selfie_file.download_to_memory()
await selfie_file.download_to_drive()
if data.translation and data.type in (
"passport",
"driver_license",
@@ -111,7 +114,7 @@ async def msg(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
for file in data.translation:
actual_file = await file.get_file()
print(actual_file)
await actual_file.download_to_memory()
await actual_file.download_to_drive()
def main() -> None:
+4
View File
@@ -16,6 +16,10 @@ Usage:
Basic Alarm Bot example, sends a message after a set time.
Press Ctrl-C on the command line or send a signal to the process to stop the
bot.
Note:
To use arbitrary callback data, you must install ptb via
`pip install python-telegram-bot[callback-data]`
"""
import logging
+65
View File
@@ -0,0 +1,65 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBF6AWOIBEAClMRtGdbm2yKAo1GdeybmasMpsCBmGI952/z5VvjSgDlu+ktPJ
QauWkARWrq4Eab2uZEIQrHUw01+9/Ugfu7qHu4safZjc177Tq4Fp0hJDHFRFVdqb
68Rv5mH0xjr7At0eNys2Rx8m7H1dBYQCz4aroUQ0q0TB4qSeKU9FzUzOZZ7/pYri
KFyNdaIjhrBeY/WXbn+7L2/cFJtafJHqkZlyfIgQzpmONfIrtJLnG0nxdBPIxg3m
CYxzrJKCkPPrl8b4TNV0LCO9c4r8zXGiZ6ZOQMAGjgb2Do67AvHTLI3YYd8+iY25
112noIFASabxbW9jBb+nlyMc8nz5kW19JWq6sBfMJYzWaVpI6ofNpiZtKWupIt2V
4GcViZmE/Kh4hBQjrBIAeqLUz6ABidERrhWu6/wP3huNe+R6eMQTfEdYlYeD3LXG
5Upl46/wnodWQeW4llMVBhjkS+5ExtvlVBD9Yz8iQMUsXUSu8+UPRgjy6YIRsvtF
bzGKFXkn4tFWCyQsXJDf8f+lQCtB1XF/DN2IVZF9OjQOvrpRwJk3h3CiQboN5lf7
Mj7I11MusPKzn34vg+3f6loOOQ++GUa+WH2B6Dx6AH3C0BI0V2sh6axu6HYJNo3o
stOXzhhWysPKp9pj41fmaFTcF8bYYlnHoLA17IapttsYo0WuFaBF5UW90QARAQAB
tCpIaW5yaWNoIE1haGxlciA8aGlucmljaC5tYWhsZXJAZnJlZW5ldC5kZT6JAk4E
EwEKADgWIQRlW7T1bNsODkUAz1cung4SfvPygwUCXoBY4gIbAwULCQgHAgYVCgkI
CwIEFgIDAQIeAQIXgAAKCRAung4SfvPyg3fXD/9IMuDgYGl+T98JvN/VHLcrA9rT
idIWr5vDSxjniQaYe8Kc3oTqje1xmRcIR7z3WFKgxErx8yEf3AOUCPqQh53MjS0q
rXNDCoRWqlljpeY2EHZh2xPSvin2pUgOd334BRFeBqyvIfb/IQmwUNDoUp1FxKEq
4veT4XPDnKZlZs/OwRMD1f0v64mtTy60fQzJyM9ICLWzZdCKZULGTKCBLms63l0h
wqznU6RA7qEpKeLEwwZs454maPdDraOebyhBYqf2EbATo1Rf1faqNzjL2T7KtyZg
PB1RDah/tCrsRi2ueFbOakyDms+98Km94lC8cZ0Wp7wlXaBLQHbRgylt49dN5KLP
cgjUxnBDOxM/4iCrwLQ3GxqZksOkwuzkZE3v1BkRy51XPRiaEov+57zhua686BzY
/rQjG6xWEawmodydUPd7qZ8LbO0bGpw+euqVd+FDEmHi4ytB1vyZMQ3Zt7gZjbBm
Wxd0x4TSKz0CQ4XuGxXvVx0ZXv3zbOXE2g06UmxijHbCwNZQazAzOw5EVaZiZPvK
4HzxssBskp49xh+8T8Pgmc085ujstW2+b1XiZcqnVhIkOqEynxKhPghP/5ODtY7/
13dkqbVgAfTZ8JU6Q+jTo5bhaoFohnb8XeEg7O8aLf06WpKvorJ+O8XGKICn1tnD
odL5XTa9xX8WMwiI3bQ9SGlucmljaCBNYWhsZXIgPDIyMzY2NTU3K0JpYm8tSm9z
aGlAdXNlcnMubm9yZXBseS5naXRodWIuY29tPokCTgQTAQoAOBYhBGVbtPVs2w4O
RQDPVy6eDhJ+8/KDBQJjm4maAhsDBQsJCAcCBhUKCQgLAgQWAgMBAh4BAheAAAoJ
EC6eDhJ+8/KDKTcP/ja9/nVePimncHGvrT70Ek53qBheSTujurDtNE6mfUOxOgr8
7m/fcZo3j/3FUssN81ijoNthS6HuhE0kyc+jbL1q4cv9oOeqgniV0P2GxlCOLwrJ
k3BjLNA04P8qSXfS1eefyRgr+dtNaOw2ARetOZm3yja34EW8II6p7Bd7DTRoGOAQ
cwi0Xz0AGyz9drLS0vDZ3VJfB0xIUToS/I/PBjUsIg0eD9M2bEOznFHK422CQMJV
r4pdHJgMfzX7XmwqMQP31oz8zNljsLWYZqpMR9Lw3B2XKziaZlptXgwC9uulcojG
lZv1OTXFKudjKmuOgzd9tW0nwMX/XnNGC7rzCpJCi5//8LeqbLxFqHoK8fXGs/9k
U7EBd3srEnGZHp3ROCsEGmNERTTIIN/rWS3lywnQCQ5kyk8HjT3WztfyLuAIiU+q
fiGQvvkehFF31ONa6tA5Xsm/0ch8rFx9ON8K72KY0fHLJ4FMz0rIdUa47GDYKDAr
n8q+drVCGBVSOWqHYhSZ5C/NCtRr6TebGCsxmhsVuqcXpJSM8CqG8f2xYeQeRw54
bGSrCGMB5TlcMUKQ9wmQWHDHa+khobvYrGBtZaHMt/exnBYqwPna88rp1pWyhIqw
bBiCzKPYOUvzW+nUL0ogCVTfq5XKMJAQh1d1FPPbSLIb/0LYSHC4FavvrmJ3uQIN
BF6AWOIBEADUaTuRBlOcwBBZAFYHgXNM22+TdU+JcYVbdn96A0NPJy0z91SLHotM
w8fr9Sbd/g+xhG8byeFDpdEwTz+sH3GN3SjaSRV3CYIueWApiAFC4ybIoR46kcri
DQJWaTL8YtofBQs7GTtmZ/IbKaxRC/nKXalBnUh3nPgWCLUcIu8axmloBfHP9zFz
+Vn37JrClM66V2TLeJp5/C3Sw2lR2Dj13G65LkSAOX+naoL//PWSSmnfiDef2DA6
Ucd3vh2BoTVkmZoDeLkIP93MfDM23I7NRq9rQSptcvYmtdxo3f3IU25sfjYBi+3g
HIWzbFq2SBeGAbWBufcFkj+kvoP4LzxJ63hVhpA0ql3WWgi5eKOeuhtnBSNaejhC
Axq8ktdAFUpyLMjA53bMUnD7Xkb09tMwW0OcUFPxVz3LG7TT8aQSwA46u/nBFIDN
4D5R14OdAysLHcVp536NSApfvzc/E5OCIx+0TPihq+8EnSEyHMvNXA0QLeGcSn8a
CoIjRK9p7IpKknGNCBx/H54rHGWi0XdPZPNbGHGFypualEB2uIRELFFkCquO2DTi
rYnrYM2Xf/u1ahp1vLNGgM1F6L9u+mC6gUUMGmyBklsz1jTGkTB4HmiMDLBDhAQM
/5UPJQhAdxuZwdfyveGxWYBJSSMtGbR+yOfT7NuTEhtBj0WG4h6tPwARAQABiQI2
BBgBCgAgFiEEZVu09WzbDg5FAM9XLp4OEn7z8oMFAl6AWOICGwwACgkQLp4OEn7z
8oOZ1g/+NE9vZSoxB9yw8uLRthjUUScES2wpA4VBVgpcA0QNEqtq5xE82xXUMhIb
1td6E00+lESoXGo66xoIFQdWEMyr0Df6kfFSTgh2FL4DA5NSSQgiM9u4O8yayu2x
AmBQzRz42V3AquVSH7gu/WhwPcYROq+gYaQT7D/l6Mg/mRUfMS/zvkFIsTJktp+q
yvcuf8ybqoCetDbOw6Uo12IjfxqT1pj8gUVrN/ePlI3HXDzOS6bCiYCgRjCU/Ujj
zcXOupKjA4mvN6LCslgwREciZgDE5W31Ghnjd3tT4OL9TSixugRFD67jr7ZsXpcl
ZReF+nbEsTZlKMXKVDnvwgvrVD4BolSj9rBpPcyftcZtFeuBPSVUE1c6pd5Vo7HJ
I+QDHQA32/hk8dDdqrdVHCn24+yZUkpkuzvNovVJINqt/4GgIRUZot0e5MupFuj9
D+Nn90ffKvFe1YjmRkJ1hblHG9Lh2I4LQOjF2qGKRL+CmtgA3NbO4BKLuTEAJnJz
PeR4FOX756R40p9Z7e0XhUqF4D/GvRyfxYhxkMKbIGEXbfgPjcNvVCDJxElBBtMz
mu6lniNOz/rViivD28dWHIro3ScaGsB4vAo2Eq+4VWTUtvoPo0OHbfX8PDbpcTuU
3a3DN3/RD8DQe+Pm5clbVCpDHzKThq9TpHFC0Iozh6d7QY+hQac=
=VeuH
-----END PGP PUBLIC KEY BLOCK-----
+53
View File
@@ -0,0 +1,53 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGOgNtUBEAC9CnrQYcKeHOVQatup9batI7lOSoXhqnS4v41LmWKt2GgVpiSn
CpWre04UMg+s/oCFto6af97vGxSsGbb2b23mTVHECvUoUBsiM2CMHopvNpMiPG3s
85gIaqQPOyVorET+MgPw96N+Ik/8sevOTb7u6+tUP4wdZcplVXBo5q+3EeK5GDb3
g+WNYbcwZ+x+3jwgphQmryHAXAis4PrdAfuaAXxclN/prJ23245IaAQxWID1Mcxi
ZaT/vZSqDEKbjj3wyzlJBfe5DuAG2IqAqEbWZCYUjjdUrsrGVdjh6Al1CqA+V8px
PYCF+qK6c3M7ilbQSXv9dDjiH1shM7DPrXop657zFandVrmaFVcf7/WLLNSX0KwM
kuYdFXYQXXoptpLsB6edB8Od39l6uETObDDVXiKQdeBypFlkWaqDv2soBY04+o0h
NvQBWT3EPS2zUXGwo7j2pd1Q4j1qC0ceKW64rxF8UqtZXOG2mJrVKeKvbprhq3kF
3+vXHqTgr6ZgjplHkVZmcv31UOBlwGnN+xBi5ooD/brF0rxZ9Pcr0BXdtBhG80V+
q1vxVh9D2K0RFJ7pLaxFdExZoevOwHdtwT411I9VfWdICc3w9KYnH4xSwjoR+Cm2
Jy9aTlft+TkQXfOxWD83QUtu/zE/MYwp2xhHLsJoOTzSLHcRHMOWC4yfrQARAQAB
tG9IaW5yaWNoIE1haGxlciAoS2V5IGZvciBzaWduaW5nIHJlbGVhc2VzIG9mIHB5
dGhvbi10ZWxlZ3JhbS1ib3QpIDwyMjM2NjU1NytCaWJvLUpvc2hpQHVzZXJzLm5v
cmVwbHkuZ2l0aHViLmNvbT6JAk4EEwEKADgWIQRMulGIRwROKJVIvZ+iuYSpBzAi
sgUCY6A21QIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRCiuYSpBzAisgG+
EACXEqRSzuMI/Ca4vs9Q0teaUskjDbmb3tpt/vlPtgtWVBxIwixIrBXXt6VF58pc
4PjnmWd0TQVWHXysVtV1JBdFHJPf7CXD1OXAzDYLS3s0gZJ8Y32oG+94FKVtdcjp
M9XV2ip0DZFd0k8ln0bVultFPR441Q7DVpJFctAvICvccC//TkgD0vMWAV+zKD/9
xctkIa1t0ZQ2xHA+NPDTLEGzs9rADwJTK/OOE528mo8ki37RTM7Ou6kGF9Xb+A5P
iaO2FBDp3b6QyprMvaOF2Xgt18h+wembzsXwVwep3OpjZHYsaImoWn6821HmsS7H
MTjR71aG6BrGZTjFtsWNd9Anu2aYfyZgpZZmeTMC6o81x428YEA9Mr7+yAgFAfd7
BTyShNsyP1LcbMpPoYciFPiL9ieMqfNPOpdluV56Xb4W27/EJ39wx+PQPEs/5A2n
RUfKdtJtqxrGGOWtoLORS0pr+s7JS6WP1dfR/VWeTMiVNG506crAvCkN7VvTlpI0
ASqnRvFeu82cgOiP8toZJ/seRDq5JdRy/dV6EMD442mE6si7RUFJ3ShQsAMdukGw
lCDdUfLATJ/rrMCsoaInIbqWBa49OqEKcpOxyR2qR/91wxS1LDhfkmtumGgIxkjj
utt2XKLSaLNaXIPjX19RMqmFntzMrU2Mk+0HD40dd30bTbkCDQRjoDbVARAA1tN/
R2PhQ++bbLCtqeIjmkx/k5nmLK5P52lOu1zR142XVDC1ByZ8FEMzgnU+n660HN2g
62/p7lrMi1I12RuPZJBvalsRfGVx2DtbX06AEEg8bjABXB48uF1xU35gLOt1nhDp
bEinY0Kx4uBQcXlKme83ceyG2vmZvW0C+2JyLFFjwpUvOwzlzjSMkBFdbDzMBL93
A8gTt36WxcA+IbZlEwYte6w8FE5HcEZgGXsYXCvKEEN2wn3scXg+1R8bXOyQeRCo
KqblMDRO6Qsb/QL3a86so7MBWX4VmW+7714kaQYhMC+DKZq5u7yO//UqnEElHrYw
W8T5KGCYTizXcrM+4giAecdeukdPpeLwOmLhKQ1YfwWkHolsruwjg15vW4QE85dV
LRSTdgH1Is6NCqweOMIozH6uIAYz3b1u1r3C9hlgMqFN1oujI12MjOURLtLUtrN/
LeosSZEUgL3T7a1bmO4ykcVvhWvGrcU0HfR/CX5nXMymhkjGk2x47elottK/O3BP
evinQWPSiF+ABH3605KZQB2cWcr0oH1rLMAIwcYtMdCmGJY9we1fRF2lf/BTcoui
nDqsuuIJJpHg9FIIR167fW1tQH0DYbQBvsDCG6jv5pZ7V4Rl8zJ30Am5h1XZzpIk
/3wPvouskdfsEF1CahpzKF/rdtIB5aaynWO0xHkAEQEAAYkCNgQYAQoAIBYhBEy6
UYhHBE4olUi9n6K5hKkHMCKyBQJjoDbVAhsMAAoJEKK5hKkHMCKypCcP/3pvvpP/
axelSKUgdsmU+mcUK4AHWtPXZxJcLoIGhMEOiNOdeX64XhHYGO0gKDvPn1Bv/ygI
ef49+NGAXWZmaSOqXSKfSWaWwQqlGLuqL76Hes5EqTbAlo4qEEbZoWx/x52zbXz6
1fbcH+rU+3dYVFIzvq2UG2t3L6v+PQXoZL20CWxIAWLGjVmnUPV/7/XJJATg2x1J
IEb7iG9h8XLvC4/+whRWG5J48kPRRPE3vy1kgeUtvHCIsvujoFCosAxRhLR62+5x
F4rREUyY2WKAsuymVCJPEKE/g3LoTtn+f78ucECm6MJNhJpZqdjlqib0mGhjWGeR
XPNHL3iEL4wFlU/DRt25GE7YKTHoPFcjet4wWOUdj9OHdV2DHgsgETEAVxaFwH7W
hnPBtyc9TDLsTtJ1NphxofSiehsesNrfX5sneQVBpUclb5HS8vYqJxLC0KLOulNU
emDwYaQdM4chy1QfKHJhj9uSbqRcoUcms59mLINUlTmdwez2Vbmnh8sLYfuz2S0L
7OANYTUOOmwlw9cQJjF2hgtgvn7lRK/zD38nVesHSBU4dmlYISV5/jnByhIDaIdo
Afq07AF3OUKAI2FfAquDjV2P66GS1K2cWEQAAd3wgze3Qlt7xvifGTxHEXXesfP3
toI3+U6jDIfsuoL4ynzcPdz0IsFwu+yX6bxw
=gtS+
-----END PGP PUBLIC KEY BLOCK-----
+2 -2
View File
@@ -1,9 +1,9 @@
pre-commit
pytest==7.2.0
pytest-asyncio==0.20.2
pytest-asyncio==0.20.3
pytest-timeout==2.1.0 # used to timeout tests
pytest-xdist==3.0.2 # xdist runs tests in parallel
pytest-xdist==3.1.0 # xdist runs tests in parallel
flaky # Used for flaky tests (flaky decorator)
beautifulsoup4 # used in test_official for parsing tg docs
+2
View File
@@ -21,6 +21,7 @@ disable = duplicate-code,too-many-arguments,too-many-public-methods,too-few-publ
missing-class-docstring,too-many-locals,too-many-lines,too-many-branches,
too-many-statements
enable=useless-suppression ; Warns about unused pylint ignores
exclude-protected=_unfrozen
[tool:pytest]
testpaths = tests
@@ -60,6 +61,7 @@ disallow_untyped_defs = True
disallow_incomplete_defs = True
disallow_untyped_decorators = True
show_error_codes = True
implicit_optional = True
# For some files, it's easier to just disable strict-optional all together instead of
# cluttering the code with `# type: ignore`s or stuff like
+14 -1
View File
@@ -70,9 +70,12 @@ __all__ = ( # Keep this alphabetically ordered
"ForumTopic",
"ForumTopicClosed",
"ForumTopicCreated",
"ForumTopicEdited",
"ForumTopicReopened",
"Game",
"GameHighScore",
"GeneralForumTopicHidden",
"GeneralForumTopicUnhidden",
"helpers",
"IdDocumentData",
"InlineKeyboardButton",
@@ -176,6 +179,7 @@ __all__ = ( # Keep this alphabetically ordered
"WebAppData",
"WebAppInfo",
"WebhookInfo",
"WriteAccessAllowed",
)
@@ -234,7 +238,15 @@ from ._files.video import Video
from ._files.videonote import VideoNote
from ._files.voice import Voice
from ._forcereply import ForceReply
from ._forumtopic import ForumTopic, ForumTopicClosed, ForumTopicCreated, ForumTopicReopened
from ._forumtopic import (
ForumTopic,
ForumTopicClosed,
ForumTopicCreated,
ForumTopicEdited,
ForumTopicReopened,
GeneralForumTopicHidden,
GeneralForumTopicUnhidden,
)
from ._games.callbackgame import CallbackGame
from ._games.game import Game
from ._games.gamehighscore import GameHighScore
@@ -326,6 +338,7 @@ from ._videochat import (
from ._webappdata import WebAppData
from ._webappinfo import WebAppInfo
from ._webhookinfo import WebhookInfo
from ._writeaccessallowed import WriteAccessAllowed
#: :obj:`str`: The version of the `python-telegram-bot` library as string.
#: To get detailed information about the version number, please use :data:`__version_info__`
+1053 -823
View File
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -41,8 +41,12 @@ class BotCommand(TelegramObject):
:tg-const:`telegram.BotCommand.MAX_DESCRIPTION` characters.
Attributes:
command (:obj:`str`): Text of the command.
description (:obj:`str`): Description of the command.
command (:obj:`str`): Text of the command; :tg-const:`telegram.BotCommand.MIN_COMMAND`-
:tg-const:`telegram.BotCommand.MAX_COMMAND` characters. Can contain only lowercase
English letters, digits and underscores.
description (:obj:`str`): Description of the command;
:tg-const:`telegram.BotCommand.MIN_DESCRIPTION`-
:tg-const:`telegram.BotCommand.MAX_DESCRIPTION` characters.
"""
@@ -55,6 +59,8 @@ class BotCommand(TelegramObject):
self._id_attrs = (self.command, self.description)
self._freeze()
MIN_COMMAND: ClassVar[int] = constants.BotCommandLimit.MIN_COMMAND
""":const:`telegram.constants.BotCommandLimit.MIN_COMMAND`
+22 -13
View File
@@ -80,6 +80,8 @@ class BotCommandScope(TelegramObject):
self.type = type
self._id_attrs = (self.type,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["BotCommandScope"]:
"""Converts JSON data to the appropriate :class:`BotCommandScope` object, i.e. takes
@@ -128,6 +130,7 @@ class BotCommandScopeDefault(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.DEFAULT, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllPrivateChats(BotCommandScope):
@@ -143,6 +146,7 @@ class BotCommandScopeAllPrivateChats(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_PRIVATE_CHATS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllGroupChats(BotCommandScope):
@@ -157,6 +161,7 @@ class BotCommandScopeAllGroupChats(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_GROUP_CHATS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeAllChatAdministrators(BotCommandScope):
@@ -171,6 +176,7 @@ class BotCommandScopeAllChatAdministrators(BotCommandScope):
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.ALL_CHAT_ADMINISTRATORS, api_kwargs=api_kwargs)
self._freeze()
class BotCommandScopeChat(BotCommandScope):
@@ -193,10 +199,11 @@ class BotCommandScopeChat(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
class BotCommandScopeChatAdministrators(BotCommandScope):
@@ -219,10 +226,11 @@ class BotCommandScopeChatAdministrators(BotCommandScope):
def __init__(self, chat_id: Union[str, int], *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_ADMINISTRATORS, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self._id_attrs = (self.type, self.chat_id)
class BotCommandScopeChatMember(BotCommandScope):
@@ -248,8 +256,9 @@ class BotCommandScopeChatMember(BotCommandScope):
def __init__(self, chat_id: Union[str, int], user_id: int, *, api_kwargs: JSONDict = None):
super().__init__(type=BotCommandScope.CHAT_MEMBER, api_kwargs=api_kwargs)
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self.user_id = user_id
self._id_attrs = (self.type, self.chat_id, self.user_id)
with self._unfrozen():
self.chat_id = (
chat_id if isinstance(chat_id, str) and chat_id.startswith("@") else int(chat_id)
)
self.user_id = user_id
self._id_attrs = (self.type, self.chat_id, self.user_id)
+17 -11
View File
@@ -18,7 +18,7 @@
# along with this program. If not, see [http://www.gnu.org/licenses/].
# pylint: disable=redefined-builtin
"""This module contains an object that represents a Telegram CallbackQuery"""
from typing import TYPE_CHECKING, ClassVar, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence, Tuple, Union
from telegram import constants
from telegram._files.location import Location
@@ -78,23 +78,27 @@ class CallbackQuery(TelegramObject):
inline_message_id (:obj:`str`, optional): Identifier of the message sent via the bot in
inline mode, that originated the query.
game_short_name (:obj:`str`, optional): Short name of a Game to be returned, serves as
the unique identifier for the game
the unique identifier for the game.
Attributes:
id (:obj:`str`): Unique identifier for this query.
from_user (:class:`telegram.User`): Sender.
chat_instance (:obj:`str`): Global identifier, uniquely corresponding to the chat to which
the message with the callback button was sent.
the message with the callback button was sent. Useful for high scores in games.
message (:class:`telegram.Message`): Optional. Message with the callback button that
originated the query.
originated the query. Note that message content and message date will not be available
if the message is too old.
data (:obj:`str` | :obj:`object`): Optional. Data associated with the callback button.
Be aware that the message, which originated the query, can contain no callback buttons
with this data.
Tip:
The value here is the same as the value passed in
:paramref:`telegram.InlineKeyboardButton.callback_data`.
inline_message_id (:obj:`str`): Optional. Identifier of the message sent via the bot in
inline mode, that originated the query.
game_short_name (:obj:`str`): Optional. Short name of a Game to be returned.
inline mode, that originated the query.
game_short_name (:obj:`str`): Optional. Short name of a Game to be returned, serves as
the unique identifier for the game.
"""
@@ -134,6 +138,8 @@ class CallbackQuery(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["CallbackQuery"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -190,7 +196,7 @@ class CallbackQuery(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_web_page_preview: ODVInput[bool] = DEFAULT_NONE,
reply_markup: "InlineKeyboardMarkup" = None,
entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
entities: Sequence["MessageEntity"] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -250,7 +256,7 @@ class CallbackQuery(TelegramObject):
caption: str = None,
reply_markup: "InlineKeyboardMarkup" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -590,7 +596,7 @@ class CallbackQuery(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List["GameHighScore"]:
) -> Tuple["GameHighScore", ...]:
"""Shortcut for either::
await update.callback_query.message.get_game_high_score(*args, **kwargs)
@@ -606,7 +612,7 @@ class CallbackQuery(TelegramObject):
:meth:`telegram.Message.get_game_high_scores`.
Returns:
List[:class:`telegram.GameHighScore`]
Tuple[:class:`telegram.GameHighScore`]
"""
if self.inline_message_id:
@@ -718,7 +724,7 @@ class CallbackQuery(TelegramObject):
chat_id: Union[int, str],
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple["MessageEntity", ...], List["MessageEntity"]] = None,
caption_entities: Sequence["MessageEntity"] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
+228 -29
View File
@@ -20,15 +20,17 @@
"""This module contains an object that represents a Telegram Chat."""
from datetime import datetime
from html import escape
from typing import TYPE_CHECKING, ClassVar, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence, Tuple, Union
from telegram import constants
from telegram._chatlocation import ChatLocation
from telegram._chatpermissions import ChatPermissions
from telegram._files.chatphoto import ChatPhoto
from telegram._forumtopic import ForumTopic
from telegram._menubutton import MenuButton
from telegram._telegramobject import TelegramObject
from telegram._utils import enum
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import DVInput, FileInput, JSONDict, ODVInput, ReplyMarkup
from telegram.helpers import escape_markdown
@@ -152,7 +154,7 @@ class Chat(TelegramObject):
(has topics_ enabled).
.. versionadded:: 20.0
active_usernames (List[:obj:`str`], optional): If set, the list of all `active chat
active_usernames (Sequence[:obj:`str`], optional): If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels. Returned
only in :meth:`telegram.Bot.get_chat`.
@@ -162,6 +164,16 @@ class Chat(TelegramObject):
status of the other party in a private chat. Returned only in
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
has_aggressive_anti_spam_enabled (:obj:`bool`, optional): :obj:`True`, if aggressive
anti-spam checks are enabled in the supergroup. The field is only available to chat
administrators. Returned only in :meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
has_hidden_members (:obj:`bool`, optional): :obj:`True`, if non-administrators can only
get the list of bots and administrators in the chat. Returned only in
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
Attributes:
@@ -233,16 +245,28 @@ class Chat(TelegramObject):
(has topics_ enabled).
.. versionadded:: 20.0
active_usernames (List[:obj:`str`]): Optional. If set, the list of all `active chat
active_usernames (Tuple[:obj:`str`]): Optional. If set, the list of all `active chat
usernames <https://telegram.org/blog/topics-in-groups-collectible-usernames\
#collectible-usernames>`_; for private chats, supergroups and channels. Returned
only in :meth:`telegram.Bot.get_chat`.
This list is empty if the chat has no active usernames or this chat instance was not
obtained via :meth:`~telegram.Bot.get_chat`.
.. versionadded:: 20.0
emoji_status_custom_emoji_id (:obj:`str`): Optional. Custom emoji identifier of emoji
status of the other party in a private chat. Returned only in
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
has_aggressive_anti_spam_enabled (:obj:`bool`): Optional. :obj:`True`, if aggressive
anti-spam checks are enabled in the supergroup. The field is only available to chat
administrators. Returned only in :meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
has_hidden_members (:obj:`bool`): Optional. :obj:`True`, if non-administrators can only
get the list of bots and administrators in the chat. Returned only in
:meth:`telegram.Bot.get_chat`.
.. versionadded:: 20.0
.. _topics: https://telegram.org/blog/topics-in-groups-collectible-usernames#topics-in-groups
@@ -275,6 +299,8 @@ class Chat(TelegramObject):
"is_forum",
"active_usernames",
"emoji_status_custom_emoji_id",
"has_hidden_members",
"has_aggressive_anti_spam_enabled",
)
SENDER: ClassVar[str] = constants.ChatType.SENDER
@@ -317,8 +343,10 @@ class Chat(TelegramObject):
join_by_request: bool = None,
has_restricted_voice_and_video_messages: bool = None,
is_forum: bool = None,
active_usernames: List[str] = None,
active_usernames: Sequence[str] = None,
emoji_status_custom_emoji_id: str = None,
has_aggressive_anti_spam_enabled: bool = None,
has_hidden_members: bool = None,
*,
api_kwargs: JSONDict = None,
):
@@ -351,11 +379,15 @@ class Chat(TelegramObject):
self.join_by_request = join_by_request
self.has_restricted_voice_and_video_messages = has_restricted_voice_and_video_messages
self.is_forum = is_forum
self.active_usernames = active_usernames
self.active_usernames = parse_sequence_arg(active_usernames)
self.emoji_status_custom_emoji_id = emoji_status_custom_emoji_id
self.has_aggressive_anti_spam_enabled = has_aggressive_anti_spam_enabled
self.has_hidden_members = has_hidden_members
self._id_attrs = (self.id,)
self._freeze()
@property
def full_name(self) -> Optional[str]:
"""
@@ -545,7 +577,7 @@ class Chat(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> List["ChatMember"]:
) -> Tuple["ChatMember", ...]:
"""Shortcut for::
await bot.get_chat_administrators(update.effective_chat.id, *args, **kwargs)
@@ -554,7 +586,7 @@ class Chat(TelegramObject):
:meth:`telegram.Bot.get_chat_administrators`.
Returns:
List[:class:`telegram.ChatMember`]: A list of administrators in a chat. An Array of
Tuple[:class:`telegram.ChatMember`]: A tuple of administrators in a chat. An Array of
:class:`telegram.ChatMember` objects that contains information about all
chat administrators except other bots. If the chat is a group or a supergroup
and no administrators were appointed, only the creator will be returned.
@@ -1233,7 +1265,7 @@ class Chat(TelegramObject):
reply_to_message_id: int = None,
reply_markup: ReplyMarkup = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -1274,7 +1306,7 @@ class Chat(TelegramObject):
async def send_media_group(
self,
media: List[
media: Sequence[
Union["InputMediaAudio", "InputMediaDocument", "InputMediaPhoto", "InputMediaVideo"]
],
disable_notification: ODVInput[bool] = DEFAULT_NONE,
@@ -1290,8 +1322,8 @@ class Chat(TelegramObject):
api_kwargs: JSONDict = None,
caption: Optional[str] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
) -> List["Message"]:
caption_entities: Sequence["MessageEntity"] = None,
) -> Tuple["Message", ...]:
"""Shortcut for::
await bot.send_media_group(update.effective_chat.id, *args, **kwargs)
@@ -1299,7 +1331,8 @@ class Chat(TelegramObject):
For the documentation of the arguments, please see :meth:`telegram.Bot.send_media_group`.
Returns:
List[:class:`telegram.Message`]: On success, instance representing the message posted.
Tuple[:class:`telegram.Message`]: On success, a tuple of :class:`~telegram.Message`
instances that were sent is returned.
"""
return await self.get_bot().send_media_group(
@@ -1323,6 +1356,7 @@ class Chat(TelegramObject):
async def send_chat_action(
self,
action: str,
message_thread_id: int = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -1343,6 +1377,7 @@ class Chat(TelegramObject):
return await self.get_bot().send_chat_action(
chat_id=self.id,
action=action,
message_thread_id=message_thread_id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
@@ -1362,9 +1397,10 @@ class Chat(TelegramObject):
reply_markup: ReplyMarkup = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
has_spoiler: bool = None,
*,
filename: str = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -1401,6 +1437,7 @@ class Chat(TelegramObject):
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
has_spoiler=has_spoiler,
)
async def send_contact(
@@ -1466,7 +1503,7 @@ class Chat(TelegramObject):
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb: FileInput = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -1522,7 +1559,7 @@ class Chat(TelegramObject):
thumb: FileInput = None,
disable_content_type_detection: bool = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -1656,7 +1693,7 @@ class Chat(TelegramObject):
payload: str,
provider_token: str,
currency: str,
prices: List["LabeledPrice"],
prices: Sequence["LabeledPrice"],
start_parameter: str = None,
photo_url: str = None,
photo_size: int = None,
@@ -1675,7 +1712,7 @@ class Chat(TelegramObject):
send_email_to_provider: bool = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
max_tip_amount: int = None,
suggested_tip_amounts: List[int] = None,
suggested_tip_amounts: Sequence[int] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -1808,9 +1845,10 @@ class Chat(TelegramObject):
reply_to_message_id: int = None,
reply_markup: ReplyMarkup = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
has_spoiler: bool = None,
*,
filename: str = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -1851,6 +1889,7 @@ class Chat(TelegramObject):
filename=filename,
protect_content=protect_content,
message_thread_id=message_thread_id,
has_spoiler=has_spoiler,
)
async def send_sticker(
@@ -1967,9 +2006,10 @@ class Chat(TelegramObject):
supports_streaming: bool = None,
thumb: FileInput = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
has_spoiler: bool = None,
*,
filename: str = None,
read_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -2011,6 +2051,7 @@ class Chat(TelegramObject):
filename=filename,
protect_content=protect_content,
message_thread_id=message_thread_id,
has_spoiler=has_spoiler,
)
async def send_video_note(
@@ -2073,7 +2114,7 @@ class Chat(TelegramObject):
reply_markup: ReplyMarkup = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
caption_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
caption_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -2118,7 +2159,7 @@ class Chat(TelegramObject):
async def send_poll(
self,
question: str,
options: List[str],
options: Sequence[str],
is_anonymous: bool = None,
type: str = None,
allows_multiple_answers: bool = None,
@@ -2132,7 +2173,7 @@ class Chat(TelegramObject):
open_period: int = None,
close_date: Union[int, datetime] = None,
allow_sending_without_reply: ODVInput[bool] = DEFAULT_NONE,
explanation_entities: Union[List["MessageEntity"], Tuple["MessageEntity", ...]] = None,
explanation_entities: Sequence["MessageEntity"] = None,
protect_content: ODVInput[bool] = DEFAULT_NONE,
message_thread_id: int = None,
*,
@@ -2185,7 +2226,7 @@ class Chat(TelegramObject):
message_id: int,
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple["MessageEntity", ...], List["MessageEntity"]] = None,
caption_entities: Sequence["MessageEntity"] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
@@ -2235,7 +2276,7 @@ class Chat(TelegramObject):
message_id: int,
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple["MessageEntity", ...], List["MessageEntity"]] = None,
caption_entities: Sequence["MessageEntity"] = None,
disable_notification: DVInput[bool] = DEFAULT_NONE,
reply_to_message_id: int = None,
allow_sending_without_reply: DVInput[bool] = DEFAULT_NONE,
@@ -2628,7 +2669,7 @@ class Chat(TelegramObject):
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
) -> ForumTopic:
"""Shortcut for::
await bot.create_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs)
@@ -2639,7 +2680,7 @@ class Chat(TelegramObject):
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
:class:`telegram.ForumTopic`
"""
return await self.get_bot().create_forum_topic(
chat_id=self.id,
@@ -2656,8 +2697,8 @@ class Chat(TelegramObject):
async def edit_forum_topic(
self,
message_thread_id: int,
name: str,
icon_custom_emoji_id: str,
name: str = None,
icon_custom_emoji_id: str = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -2818,6 +2859,164 @@ class Chat(TelegramObject):
api_kwargs=api_kwargs,
)
async def edit_general_forum_topic(
self,
name: str,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::
await bot.edit_general_forum_topic(
chat_id=update.effective_chat.id, *args, **kwargs
)
For the documentation of the arguments, please see
:meth:`telegram.Bot.edit_general_forum_topic`.
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().edit_general_forum_topic(
chat_id=self.id,
name=name,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
async def close_general_forum_topic(
self,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::
await bot.close_general_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs)
For the documentation of the arguments, please see
:meth:`telegram.Bot.close_general_forum_topic`.
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().close_general_forum_topic(
chat_id=self.id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
async def reopen_general_forum_topic(
self,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::
await bot.reopen_general_forum_topic(
chat_id=update.effective_chat.id, *args, **kwargs
)
For the documentation of the arguments, please see
:meth:`telegram.Bot.reopen_general_forum_topic`.
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().reopen_general_forum_topic(
chat_id=self.id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
async def hide_general_forum_topic(
self,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::
await bot.hide_general_forum_topic(chat_id=update.effective_chat.id, *args, **kwargs)
For the documentation of the arguments, please see
:meth:`telegram.Bot.hide_general_forum_topic`.
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().hide_general_forum_topic(
chat_id=self.id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
async def unhide_general_forum_topic(
self,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> bool:
"""Shortcut for::
await bot.unhide_general_forum_topic (
chat_id=update.effective_chat.id, *args, **kwargs
)
For the documentation of the arguments, please see
:meth:`telegram.Bot.unhide_general_forum_topic`.
.. versionadded:: 20.0
Returns:
:obj:`bool`: On success, :obj:`True` is returned.
"""
return await self.get_bot().unhide_general_forum_topic(
chat_id=self.id,
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
api_kwargs=api_kwargs,
)
async def get_menu_button(
self,
*,
@@ -2832,7 +3031,7 @@ class Chat(TelegramObject):
await bot.get_chat_menu_button(chat_id=update.effective_chat.id, *args, **kwargs)
For the documentation of the arguments, please see
:meth:`telegram.Bot.set_chat_menu_button`.
:meth:`telegram.Bot.get_chat_menu_button`.
Caution:
Can only work, if the chat is a private chat.
+2
View File
@@ -167,6 +167,8 @@ class ChatAdministratorRights(TelegramObject):
self.can_manage_topics,
)
self._freeze()
@classmethod
def all_rights(cls) -> "ChatAdministratorRights":
"""
+3
View File
@@ -83,6 +83,7 @@ class ChatInviteLink(TelegramObject):
:tg-const:`telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT`-
:tg-const:`telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT`.
name (:obj:`str`): Optional. Invite link name.
0-:tg-const:`telegram.constants.ChatInviteLinkLimit.NAME_LENGTH` characters.
.. versionadded:: 13.8
pending_join_request_count (:obj:`int`): Optional. Number of pending join requests
@@ -141,6 +142,8 @@ class ChatInviteLink(TelegramObject):
self.is_revoked,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatInviteLink"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -88,6 +88,8 @@ class ChatJoinRequest(TelegramObject):
self._id_attrs = (self.chat, self.from_user, self.date)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatJoinRequest"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+7 -2
View File
@@ -40,10 +40,13 @@ class ChatLocation(TelegramObject):
Can't be a live location.
address (:obj:`str`): Location address;
:tg-const:`telegram.ChatLocation.MIN_ADDRESS`-
:tg-const:`telegram.ChatLocation.MAX_ADDRESS` characters, as defined by the chat owner
:tg-const:`telegram.ChatLocation.MAX_ADDRESS` characters, as defined by the chat owner.
Attributes:
location (:class:`telegram.Location`): The location to which the supergroup is connected.
address (:obj:`str`): Location address, as defined by the chat owner
Can't be a live location.
address (:obj:`str`): Location address;
:tg-const:`telegram.ChatLocation.MIN_ADDRESS`-
:tg-const:`telegram.ChatLocation.MAX_ADDRESS` characters, as defined by the chat owner.
"""
@@ -62,6 +65,8 @@ class ChatLocation(TelegramObject):
self._id_attrs = (self.location,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatLocation"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+41 -30
View File
@@ -45,7 +45,7 @@ class ChatMember(TelegramObject):
considered equal, if their :attr:`user` and :attr:`status` are equal.
Examples:
:any:`Chat Member Bot <examples.chatmemberbot>`
:any:`Chat Member Bot <examples.chatmemberbot>`
.. versionchanged:: 20.0
@@ -65,7 +65,10 @@ class ChatMember(TelegramObject):
Attributes:
user (:class:`telegram.User`): Information about the user.
status (:obj:`str`): The member's status in the chat.
status (:obj:`str`): The member's status in the chat. Can be
:attr:`~telegram.ChatMember.ADMINISTRATOR`, :attr:`~telegram.ChatMember.OWNER`,
:attr:`~telegram.ChatMember.BANNED`, :attr:`~telegram.ChatMember.LEFT`,
:attr:`~telegram.ChatMember.MEMBER` or :attr:`~telegram.ChatMember.RESTRICTED`.
"""
@@ -98,6 +101,8 @@ class ChatMember(TelegramObject):
self._id_attrs = (self.user, self.status)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMember"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -159,8 +164,9 @@ class ChatMemberOwner(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.OWNER, user=user, api_kwargs=api_kwargs)
self.is_anonymous = is_anonymous
self.custom_title = custom_title
with self._unfrozen():
self.is_anonymous = is_anonymous
self.custom_title = custom_title
class ChatMemberAdministrator(ChatMember):
@@ -295,20 +301,21 @@ class ChatMemberAdministrator(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.ADMINISTRATOR, user=user, api_kwargs=api_kwargs)
self.can_be_edited = can_be_edited
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title
with self._unfrozen():
self.can_be_edited = can_be_edited
self.is_anonymous = is_anonymous
self.can_manage_chat = can_manage_chat
self.can_delete_messages = can_delete_messages
self.can_manage_video_chats = can_manage_video_chats
self.can_restrict_members = can_restrict_members
self.can_promote_members = can_promote_members
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_post_messages = can_post_messages
self.can_edit_messages = can_edit_messages
self.can_pin_messages = can_pin_messages
self.can_manage_topics = can_manage_topics
self.custom_title = custom_title
class ChatMemberMember(ChatMember):
@@ -337,6 +344,7 @@ class ChatMemberMember(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.MEMBER, user=user, api_kwargs=api_kwargs)
self._freeze()
class ChatMemberRestricted(ChatMember):
@@ -439,17 +447,18 @@ class ChatMemberRestricted(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.RESTRICTED, user=user, api_kwargs=api_kwargs)
self.is_member = is_member
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date
with self._unfrozen():
self.is_member = is_member
self.can_change_info = can_change_info
self.can_invite_users = can_invite_users
self.can_pin_messages = can_pin_messages
self.can_send_messages = can_send_messages
self.can_send_media_messages = can_send_media_messages
self.can_send_polls = can_send_polls
self.can_send_other_messages = can_send_other_messages
self.can_add_web_page_previews = can_add_web_page_previews
self.can_manage_topics = can_manage_topics
self.until_date = until_date
class ChatMemberLeft(ChatMember):
@@ -477,6 +486,7 @@ class ChatMemberLeft(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.LEFT, user=user, api_kwargs=api_kwargs)
self._freeze()
class ChatMemberBanned(ChatMember):
@@ -510,4 +520,5 @@ class ChatMemberBanned(ChatMember):
api_kwargs: JSONDict = None,
):
super().__init__(status=ChatMember.BANNED, user=user, api_kwargs=api_kwargs)
self.until_date = until_date
with self._unfrozen():
self.until_date = until_date
+3 -1
View File
@@ -65,7 +65,7 @@ class ChatMemberUpdated(TelegramObject):
old_chat_member (:class:`telegram.ChatMember`): Previous information about the chat member.
new_chat_member (:class:`telegram.ChatMember`): New information about the chat member.
invite_link (:class:`telegram.ChatInviteLink`): Optional. Chat invite link, which was used
by the user to join the chat.
by the user to join the chat. For joining by invite link events only.
"""
@@ -108,6 +108,8 @@ class ChatMemberUpdated(TelegramObject):
self.new_chat_member,
)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChatMemberUpdated"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -142,6 +142,8 @@ class ChatPermissions(TelegramObject):
self.can_manage_topics,
)
self._freeze()
@classmethod
def all_permissions(cls) -> "ChatPermissions":
"""
+7 -2
View File
@@ -56,8 +56,11 @@ class ChosenInlineResult(TelegramObject):
Attributes:
result_id (:obj:`str`): The unique identifier for the result that was chosen.
from_user (:class:`telegram.User`): The user that chose the result.
location (:class:`telegram.Location`): Optional. Sender location.
inline_message_id (:obj:`str`): Optional. Identifier of the sent inline message.
location (:class:`telegram.Location`): Optional. Sender location, only for bots that
require user location.
inline_message_id (:obj:`str`): Optional. Identifier of the sent inline message. Available
only if there is an inline keyboard attached to the message. Will be also received in
callback queries and can be used to edit the message.
query (:obj:`str`): The query that was used to obtain the result.
"""
@@ -86,6 +89,8 @@ class ChosenInlineResult(TelegramObject):
self._id_attrs = (self.result_id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["ChosenInlineResult"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+12 -2
View File
@@ -52,8 +52,8 @@ class Dice(TelegramObject):
If :attr:`emoji` is :tg-const:`telegram.Dice.SLOT_MACHINE`, each value
corresponds to a unique combination of symbols, which
can be found at our `wiki <https://github.com/python-telegram-bot/python-telegram-bot/wiki\
/Code-snippets#map-a-slot-machine-dice-value-to-the-corresponding-symbols>`_.
can be found in our
:wiki:`wiki <Code-snippets#map-a-slot-machine-dice-value-to-the-corresponding-symbols>`.
However, this behaviour is undocumented and might be changed by Telegram.
..
@@ -75,6 +75,14 @@ class Dice(TelegramObject):
Attributes:
value (:obj:`int`): Value of the dice.
:tg-const:`telegram.Dice.MIN_VALUE`-:tg-const:`telegram.Dice.MAX_VALUE_BOWLING`
for :tg-const:`telegram.Dice.DICE`, :tg-const:`telegram.Dice.DARTS` and
:tg-const:`telegram.Dice.BOWLING` base emoji,
:tg-const:`telegram.Dice.MIN_VALUE`-:tg-const:`telegram.Dice.MAX_VALUE_BASKETBALL`
for :tg-const:`telegram.Dice.BASKETBALL` and :tg-const:`telegram.Dice.FOOTBALL`
base emoji,
:tg-const:`telegram.Dice.MIN_VALUE`-:tg-const:`telegram.Dice.MAX_VALUE_SLOT_MACHINE`
for :tg-const:`telegram.Dice.SLOT_MACHINE` base emoji.
emoji (:obj:`str`): Emoji on which the dice throw animation is based.
"""
@@ -88,6 +96,8 @@ class Dice(TelegramObject):
self._id_attrs = (self.value, self.emoji)
self._freeze()
DICE: ClassVar[str] = constants.DiceEmoji.DICE # skipcq: PTC-W0052
""":const:`telegram.constants.DiceEmoji.DICE`"""
DARTS: ClassVar[str] = constants.DiceEmoji.DARTS
+1 -1
View File
@@ -79,7 +79,7 @@ class _BaseMedium(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file`
"""Convenience wrapper over :meth:`telegram.Bot.get_file`
For the documentation of the arguments, please see :meth:`telegram.Bot.get_file`.
+10 -8
View File
@@ -44,7 +44,8 @@ class Animation(_BaseThumbedMedium):
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): File identifier.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
@@ -82,10 +83,11 @@ class Animation(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
+13 -12
View File
@@ -46,11 +46,11 @@ class Audio(_BaseThumbedMedium):
which the music file belongs.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
duration (:obj:`int`): Duration of the audio in seconds.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which is supposed to be
the same over time and for different bots. Can't be used to download or reuse the file.
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
performer (:obj:`str`): Optional. Performer of the audio as defined by sender or by audio
tags.
title (:obj:`str`): Optional. Title of the audio as defined by sender or by audio tags.
@@ -86,10 +86,11 @@ class Audio(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.duration = duration
# Optional
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.duration = duration
# Optional
self.performer = performer
self.title = title
self.mime_type = mime_type
self.file_name = file_name
+6 -4
View File
@@ -36,7 +36,7 @@ class ChatPhoto(TelegramObject):
equal.
Args:
small_file_id (:obj:`str`): Unique file identifier of small
small_file_id (:obj:`str`): File identifier of small
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
chat photo. This file_id can be used only for photo download and only for as long
as the photo is not changed.
@@ -44,7 +44,7 @@ class ChatPhoto(TelegramObject):
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
chat photo, which is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
big_file_id (:obj:`str`): Unique file identifier of big
big_file_id (:obj:`str`): File identifier of big
(:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
chat photo. This file_id can be used only for photo download and only for as long as
the photo is not changed.
@@ -100,6 +100,8 @@ class ChatPhoto(TelegramObject):
self.big_file_unique_id,
)
self._freeze()
async def get_small_file(
self,
*,
@@ -109,7 +111,7 @@ class ChatPhoto(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the small
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the small
(:tg-const:`telegram.ChatPhoto.SIZE_SMALL` x :tg-const:`telegram.ChatPhoto.SIZE_SMALL`)
chat photo
@@ -140,7 +142,7 @@ class ChatPhoto(TelegramObject):
pool_timeout: ODVInput[float] = DEFAULT_NONE,
api_kwargs: JSONDict = None,
) -> "File":
"""Convenience wrapper over :attr:`telegram.Bot.get_file` for getting the
"""Convenience wrapper over :meth:`telegram.Bot.get_file` for getting the
big (:tg-const:`telegram.ChatPhoto.SIZE_BIG` x :tg-const:`telegram.ChatPhoto.SIZE_BIG`)
chat photo
+2
View File
@@ -66,3 +66,5 @@ class Contact(TelegramObject):
self.vcard = vcard
self._id_attrs = (self.phone_number,)
self._freeze()
+11 -11
View File
@@ -41,16 +41,15 @@ class Document(_BaseThumbedMedium):
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): File identifier.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
thumb (:class:`telegram.PhotoSize`): Optional. Document thumbnail.
file_name (:obj:`str`): Original filename.
mime_type (:obj:`str`): Optional. MIME type of the file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which is supposed to be
the same over time and for different bots. Can't be used to download or reuse the file.
thumb (:class:`telegram.PhotoSize`): Optional. Document thumbnail as defined by sender.
file_name (:obj:`str`): Optional. Original filename as defined by sender.
mime_type (:obj:`str`): Optional. MIME type of the file as defined by sender.
file_size (:obj:`int`): Optional. File size in bytes.
"""
__slots__ = ("file_name", "mime_type")
@@ -73,6 +72,7 @@ class Document(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Optional
self.mime_type = mime_type
self.file_name = file_name
+68 -22
View File
@@ -36,21 +36,21 @@ if TYPE_CHECKING:
class File(TelegramObject):
"""
This object represents a file ready to be downloaded. The file can be e.g. downloaded with
:attr:`download_to_memory`. It is guaranteed that the link will be valid for at least 1 hour.
:attr:`download_to_drive`. It is guaranteed that the link will be valid for at least 1 hour.
When the link expires, a new one can be requested by calling :meth:`telegram.Bot.get_file`.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`file_unique_id` is equal.
.. versionchanged:: 20.0:
``download`` was split into :meth:`download_to_memory` and :meth:`download_to_object`.
.. versionchanged:: 20.0
``download`` was split into :meth:`download_to_drive` and :meth:`download_to_memory`.
Note:
* Maximum file size to download is
:tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD`.
* If you obtain an instance of this class from :attr:`telegram.PassportFile.get_file`,
then it will automatically be decrypted as it downloads when you call e.g.
:meth:`download_to_memory`.
:meth:`download_to_drive`.
Args:
file_id (:obj:`str`): Identifier for this file, which can be used to download
@@ -58,18 +58,19 @@ class File(TelegramObject):
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`int`, optional): Optional. File size in bytes, if known.
file_path (:obj:`str`, optional): File path. Use e.g. :meth:`download_to_memory` to get the
file_size (:obj:`int`, optional): File size in bytes, if known.
file_path (:obj:`str`, optional): File path. Use e.g. :meth:`download_to_drive` to get the
file.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
file_size (:obj:`str`): Optional. File size in bytes.
file_path (:obj:`str`): Optional. File path. Use e.g. :meth:`download_to_memory` to get
the file.
file_size (:obj:`int`): Optional. File size in bytes, if known.
file_path (:obj:`str`): Optional. File path. Use e.g. :meth:`download_to_drive` to get the
file.
"""
__slots__ = (
@@ -102,6 +103,8 @@ class File(TelegramObject):
self._id_attrs = (self.file_unique_id,)
self._freeze()
def _get_encoded_url(self) -> str:
"""Convert any UTF-8 char in :obj:`File.file_path` into a url encoded ASCII string."""
sres = urllib_parse.urlsplit(str(self.file_path))
@@ -114,9 +117,10 @@ class File(TelegramObject):
def _prepare_decrypt(self, buf: bytes) -> bytes:
return decrypt(b64decode(self._credentials.secret), b64decode(self._credentials.hash), buf)
async def download_to_memory(
async def download_to_drive(
self,
custom_path: FilePathInput = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -130,14 +134,15 @@ class File(TelegramObject):
Note:
If :paramref:`custom_path` isn't provided and :attr:`file_path` is the path of a
local file (which is the case when a Bot API Server is running in local mode), this
method will just return the path.
local file (which is the case when a Bot API Server is running in local mode), this
method will just return the path.
The only exception to this are encrypted files (e.g. a passport file). For these, a
file with the prefix `decrypted_` will be created in the same directory as the
original file in order to decrypt the file without changing the existing one
in-place.
file with the prefix `decrypted_` will be created in the same directory as the
original file in order to decrypt the file without changing the existing one
in-place.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
.. versionchanged:: 20.0
@@ -145,12 +150,13 @@ class File(TelegramObject):
* Returns :class:`pathlib.Path` object in cases where previously a :obj:`str` was
returned.
* This method was previously called ``download``. It was split into
:meth:`download_to_memory` and :meth:`download_to_object`.
:meth:`download_to_drive` and :meth:`download_to_memory`.
Args:
custom_path (:class:`pathlib.Path` | :obj:`str` , optional): The path where the file
will be saved to. If not specified, will be saved in the current working directory.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
@@ -207,9 +213,10 @@ class File(TelegramObject):
filename.write_bytes(buf)
return filename
async def download_to_object(
async def download_to_memory(
self,
out: BinaryIO,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
@@ -220,12 +227,15 @@ class File(TelegramObject):
:obj:`io.BufferedIOBase`, the file contents will be saved to that object using the
:obj:`out.write<io.BufferedIOBase.write>` method.
.. versionadded:: 20.0
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
.. versionadded:: 20.0
Args:
out (:obj:`io.BufferedIOBase`): A file-like object. Must be opened for writing in
binary mode.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
@@ -256,12 +266,42 @@ class File(TelegramObject):
buf = self._prepare_decrypt(buf)
out.write(buf)
async def download_as_bytearray(self, buf: bytearray = None) -> bytearray:
async def download_as_bytearray(
self,
buf: bytearray = None,
*,
read_timeout: ODVInput[float] = DEFAULT_NONE,
write_timeout: ODVInput[float] = DEFAULT_NONE,
connect_timeout: ODVInput[float] = DEFAULT_NONE,
pool_timeout: ODVInput[float] = DEFAULT_NONE,
) -> bytearray:
"""Download this file and return it as a bytearray.
Args:
buf (:obj:`bytearray`, optional): Extend the given bytearray with the downloaded data.
Keyword Args:
read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
:paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
:attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
.. versionadded:: 20.0
Returns:
:obj:`bytearray`: The same object as :paramref:`buf` if it was specified. Otherwise a
newly allocated :obj:`bytearray`.
@@ -273,7 +313,13 @@ class File(TelegramObject):
if is_local_file(self.file_path):
bytes_data = Path(self.file_path).read_bytes()
else:
bytes_data = await self.get_bot().request.retrieve(self._get_encoded_url())
bytes_data = await self.get_bot().request.retrieve(
self._get_encoded_url(),
read_timeout=read_timeout,
write_timeout=write_timeout,
connect_timeout=connect_timeout,
pool_timeout=pool_timeout,
)
if self._credentials:
buf.extend(self._prepare_decrypt(bytes_data))
else:
+173 -65
View File
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""Base class for Telegram InputMedia Objects."""
from typing import List, Optional, Tuple, Union
from typing import Optional, Sequence, Union
from telegram._files.animation import Animation
from telegram._files.audio import Audio
@@ -27,6 +27,7 @@ from telegram._files.photosize import PhotoSize
from telegram._files.video import Video
from telegram._messageentity import MessageEntity
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.files import parse_file_input
from telegram._utils.types import FileInput, JSONDict, ODVInput
@@ -39,10 +40,12 @@ class InputMedia(TelegramObject):
"""
Base class for Telegram InputMedia Objects.
.. versionchanged:: 20.0:
.. versionchanged:: 20.0
Added arguments and attributes :attr:`type`, :attr:`media`, :attr:`caption`,
:attr:`caption_entities`, :paramref:`parse_mode`.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
media_type (:obj:`str`): Type of media that the instance represents.
media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \
@@ -55,16 +58,27 @@ class InputMedia(TelegramObject):
caption (:obj:`str`, optional): Caption of the media to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
parse_mode (:obj:`str`, optional): |parse_mode|
Attributes:
type (:obj:`str`): Type of the input media.
media (:obj:`str` | :class:`telegram.InputFile`): Media to send.
caption (:obj:`str`): Optional. Caption of the media to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption (:obj:`str`): Optional. Caption of the media to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
"""
__slots__ = ("caption", "caption_entities", "media", "parse_mode", "type")
@@ -74,7 +88,7 @@ class InputMedia(TelegramObject):
media_type: str,
media: Union[str, InputFile, MediaType],
caption: str = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
*,
api_kwargs: JSONDict = None,
@@ -83,9 +97,11 @@ class InputMedia(TelegramObject):
self.type = media_type
self.media = media
self.caption = caption
self.caption_entities = caption_entities
self.caption_entities = parse_sequence_arg(caption_entities)
self.parse_mode = parse_mode
self._freeze()
@staticmethod
def _parse_thumb_input(thumb: Optional[FileInput]) -> Optional[Union[str, InputFile]]:
# We use local_mode=True because we don't have access to the actual setting and want
@@ -103,6 +119,8 @@ class InputMediaAnimation(InputMedia):
width, height and duration from that video, unless otherwise specified with the optional
arguments.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \
:class:`telegram.Animation`): File to send. |fileinputnopath|
@@ -124,26 +142,43 @@ class InputMediaAnimation(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
width (:obj:`int`, optional): Animation width.
height (:obj:`int`, optional): Animation height.
duration (:obj:`int`, optional): Animation duration in seconds.
has_spoiler (:obj:`bool`, optional): Pass :obj:`True`, if the animation needs to be covered
with a spoiler animation.
.. versionadded:: 20.0
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.ANIMATION`.
media (:obj:`str` | :class:`telegram.InputFile`): Animation to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
thumb (:class:`telegram.InputFile`): Optional. |thumbdocstringbase|
caption (:obj:`str`): Optional. Caption of the animation to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
width (:obj:`int`): Optional. Animation width.
height (:obj:`int`): Optional. Animation height.
duration (:obj:`int`): Optional. Animation duration in seconds.
has_spoiler (:obj:`bool`): Optional. :obj:`True`, if the animation is covered with a
spoiler animation.
.. versionadded:: 20.0
"""
__slots__ = ("duration", "height", "thumb", "width")
__slots__ = ("duration", "height", "thumb", "width", "has_spoiler")
def __init__(
self,
@@ -154,8 +189,9 @@ class InputMediaAnimation(InputMedia):
width: int = None,
height: int = None,
duration: int = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
has_spoiler: bool = None,
*,
api_kwargs: JSONDict = None,
):
@@ -177,15 +213,19 @@ class InputMediaAnimation(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.width = width
self.height = height
self.duration = duration
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.width = width
self.height = height
self.duration = duration
self.has_spoiler = has_spoiler
class InputMediaPhoto(InputMedia):
"""Represents a photo to be sent.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \
:class:`telegram.PhotoSize`): File to send. |fileinputnopath|
@@ -202,27 +242,44 @@ class InputMediaPhoto(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
has_spoiler (:obj:`bool`, optional): Pass :obj:`True`, if the photo needs to be covered
with a spoiler animation.
.. versionadded:: 20.0
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.PHOTO`.
media (:obj:`str` | :class:`telegram.InputFile`): Photo to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption (:obj:`str`): Optional. Caption of the photo to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
has_spoiler (:obj:`bool`): Optional. :obj:`True`, if the photo is covered with a
spoiler animation.
.. versionadded:: 20.0
"""
__slots__ = ()
__slots__ = ("has_spoiler",)
def __init__(
self,
media: Union[FileInput, PhotoSize],
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
has_spoiler: bool = None,
*,
api_kwargs: JSONDict = None,
):
@@ -238,10 +295,15 @@ class InputMediaPhoto(InputMedia):
api_kwargs=api_kwargs,
)
with self._unfrozen():
self.has_spoiler = has_spoiler
class InputMediaVideo(InputMedia):
"""Represents a video to be sent.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Note:
* When using a :class:`telegram.Video` for the :attr:`media` attribute, it will take the
width, height and duration from that video, unless otherwise specified with the optional
@@ -266,7 +328,11 @@ class InputMediaVideo(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
width (:obj:`int`, optional): Video width.
height (:obj:`int`, optional): Video height.
duration (:obj:`int`, optional): Video duration in seconds.
@@ -277,24 +343,37 @@ class InputMediaVideo(InputMedia):
.. versionchanged:: 13.2
Accept :obj:`bytes` as input.
has_spoiler (:obj:`bool`, optional): Pass :obj:`True`, if the video needs to be covered
with a spoiler animation.
.. versionadded:: 20.0
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.VIDEO`.
media (:obj:`str` | :class:`telegram.InputFile`): Video file to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
caption (:obj:`str`): Optional. Caption of the video to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
width (:obj:`int`): Optional. Video width.
height (:obj:`int`): Optional. Video height.
duration (:obj:`int`): Optional. Video duration in seconds.
supports_streaming (:obj:`bool`): Optional. Pass :obj:`True`, if the uploaded video is
supports_streaming (:obj:`bool`): Optional. :obj:`True`, if the uploaded video is
suitable for streaming.
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
thumb (:class:`telegram.InputFile`): Optional. |thumbdocstringbase|
has_spoiler (:obj:`bool`): Optional. :obj:`True`, if the video is covered with a
spoiler animation.
.. versionadded:: 20.0
"""
__slots__ = ("duration", "height", "thumb", "supports_streaming", "width")
__slots__ = ("duration", "height", "thumb", "supports_streaming", "width", "has_spoiler")
def __init__(
self,
@@ -306,8 +385,9 @@ class InputMediaVideo(InputMedia):
supports_streaming: bool = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb: FileInput = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
has_spoiler: bool = None,
*,
api_kwargs: JSONDict = None,
):
@@ -330,16 +410,20 @@ class InputMediaVideo(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.width = width
self.height = height
self.duration = duration
self.thumb = self._parse_thumb_input(thumb)
self.supports_streaming = supports_streaming
with self._unfrozen():
self.width = width
self.height = height
self.duration = duration
self.thumb = self._parse_thumb_input(thumb)
self.supports_streaming = supports_streaming
self.has_spoiler = has_spoiler
class InputMediaAudio(InputMedia):
"""Represents an audio file to be treated as music to be sent.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Note:
When using a :class:`telegram.Audio` for the :attr:`media` attribute, it will take the
duration, performer and title from that video, unless otherwise specified with the
@@ -361,8 +445,12 @@ class InputMediaAudio(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
duration (:obj:`int`, optional): Duration of the audio in seconds as defined by sender.
performer (:obj:`str`, optional): Performer of the audio as defined by sender or by audio
tags.
title (:obj:`str`, optional): Title of the audio as defined by sender or by audio tags.
@@ -375,15 +463,21 @@ class InputMediaAudio(InputMedia):
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.AUDIO`.
media (:obj:`str` | :class:`telegram.InputFile`): Audio file to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
duration (:obj:`int`): Duration of the audio in seconds.
caption (:obj:`str`): Optional. Caption of the audio to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
duration (:obj:`int`): Optional. Duration of the audio in seconds.
performer (:obj:`str`): Optional. Performer of the audio as defined by sender or by audio
tags.
title (:obj:`str`): Optional. Title of the audio as defined by sender or by audio tags.
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
thumb (:class:`telegram.InputFile`): Optional. |thumbdocstringbase|
"""
@@ -398,7 +492,7 @@ class InputMediaAudio(InputMedia):
duration: int = None,
performer: str = None,
title: str = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -421,15 +515,18 @@ class InputMediaAudio(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.duration = duration
self.title = title
self.performer = performer
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.duration = duration
self.title = title
self.performer = performer
class InputMediaDocument(InputMedia):
"""Represents a general file to be sent.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
media (:obj:`str` | :term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | \
:class:`telegram.Document`): File to send. |fileinputnopath|
@@ -446,7 +543,11 @@ class InputMediaDocument(InputMedia):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
thumb (:term:`file object` | :obj:`bytes` | :class:`pathlib.Path` | :obj:`str`, \
optional): |thumbdocstringnopath|
@@ -459,14 +560,20 @@ class InputMediaDocument(InputMedia):
Attributes:
type (:obj:`str`): :tg-const:`telegram.constants.InputMediaType.DOCUMENT`.
media (:obj:`str` | :class:`telegram.InputFile`): File to send.
caption (:obj:`str`): Optional. Caption of the document to be sent.
parse_mode (:obj:`str`): Optional. The parse mode to use for text formatting.
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. List of special
entities that appear in the caption.
thumb (:class:`telegram.InputFile`): Optional. Thumbnail of the file to send.
caption (:obj:`str`): Optional. Caption of the document to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
thumb (:class:`telegram.InputFile`): Optional. |thumbdocstringbase|
disable_content_type_detection (:obj:`bool`): Optional. Disables automatic server-side
content type detection for files uploaded using multipart/form-data. Always true, if
the document is sent as part of an album.
content type detection for files uploaded using multipart/form-data. Always
:obj:`True`, if the document is sent as part of an album.
"""
@@ -479,7 +586,7 @@ class InputMediaDocument(InputMedia):
caption: str = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
disable_content_type_detection: bool = None,
caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, ...]] = None,
caption_entities: Sequence[MessageEntity] = None,
filename: str = None,
*,
api_kwargs: JSONDict = None,
@@ -495,5 +602,6 @@ class InputMediaDocument(InputMedia):
parse_mode,
api_kwargs=api_kwargs,
)
self.thumb = self._parse_thumb_input(thumb)
self.disable_content_type_detection = disable_content_type_detection
with self._unfrozen():
self.thumb = self._parse_thumb_input(thumb)
self.disable_content_type_detection = disable_content_type_detection
+5 -2
View File
@@ -48,10 +48,11 @@ class Location(TelegramObject):
longitude (:obj:`float`): Longitude as defined by sender.
latitude (:obj:`float`): Latitude as defined by sender.
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
measured in meters.
measured in meters; 0-:tg-const:`telegram.Location.HORIZONTAL_ACCURACY`.
live_period (:obj:`int`): Optional. Time relative to the message sending date, during which
the location can be updated, in seconds. For active live locations only.
heading (:obj:`int`): Optional. The direction in which user is moving, in degrees.
heading (:obj:`int`): Optional. The direction in which user is moving, in degrees;
:tg-const:`telegram.Location.MIN_HEADING`-:tg-const:`telegram.Location.MAX_HEADING`.
For active live locations only.
proximity_alert_radius (:obj:`int`): Optional. Maximum distance for proximity alerts about
approaching another chat member, in meters. For sent live locations only.
@@ -93,6 +94,8 @@ class Location(TelegramObject):
self._id_attrs = (self.longitude, self.latitude)
self._freeze()
HORIZONTAL_ACCURACY: ClassVar[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
+6 -4
View File
@@ -39,7 +39,8 @@ class PhotoSize(_BaseMedium):
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
@@ -68,6 +69,7 @@ class PhotoSize(_BaseMedium):
file_size=file_size,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
with self._unfrozen():
# Required
self.width = width
self.height = height
+45 -28
View File
@@ -17,14 +17,14 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains objects that represent stickers."""
from typing import TYPE_CHECKING, ClassVar, List, Optional
from typing import TYPE_CHECKING, ClassVar, Optional, Sequence
from telegram import constants
from telegram._files._basethumbedmedium import _BaseThumbedMedium
from telegram._files.file import File
from telegram._files.photosize import PhotoSize
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -62,10 +62,9 @@ class Sticker(_BaseThumbedMedium):
thumb (:class:`telegram.PhotoSize`, optional): Sticker thumbnail in the ``.WEBP`` or
``.JPG`` format.
emoji (:obj:`str`, optional): Emoji associated with the sticker
set_name (:obj:`str`, optional): Name of the sticker set to which the sticker
belongs.
mask_position (:class:`telegram.MaskPosition`, optional): For mask stickers, the
position where the mask should be placed.
set_name (:obj:`str`, optional): Name of the sticker set to which the sticker belongs.
mask_position (:class:`telegram.MaskPosition`, optional): For mask stickers, the position
where the mask should be placed.
file_size (:obj:`int`, optional): File size in bytes.
premium_animation (:class:`telegram.File`, optional): For premium regular stickers,
@@ -78,7 +77,8 @@ class Sticker(_BaseThumbedMedium):
.. versionadded:: 20.0
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
@@ -150,18 +150,19 @@ class Sticker(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.is_animated = is_animated
self.is_video = is_video
self.type = type
# Optional
self.emoji = emoji
self.set_name = set_name
self.mask_position = mask_position
self.premium_animation = premium_animation
self.custom_emoji_id = custom_emoji_id
with self._unfrozen():
# Required
self.width = width
self.height = height
self.is_animated = is_animated
self.is_video = is_video
self.type = type
# Optional
self.emoji = emoji
self.set_name = set_name
self.mask_position = mask_position
self.premium_animation = premium_animation
self.custom_emoji_id = custom_emoji_id
REGULAR: ClassVar[str] = constants.StickerType.REGULAR
""":const:`telegram.constants.StickerType.REGULAR`"""
@@ -196,7 +197,7 @@ class StickerSet(TelegramObject):
arguments had to be changed. Use keyword arguments to make sure that the arguments are
passed correctly.
.. versionchanged:: 20.0:
.. versionchanged:: 20.0
The parameter ``contains_masks`` has been removed. Use :paramref:`sticker_type` instead.
Args:
@@ -206,7 +207,11 @@ class StickerSet(TelegramObject):
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
stickers (Sequence[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
|sequenceclassargs|
sticker_type (:obj:`str`): Type of stickers in the set, currently one of
:attr:`telegram.Sticker.REGULAR`, :attr:`telegram.Sticker.MASK`,
:attr:`telegram.Sticker.CUSTOM_EMOJI`.
@@ -222,12 +227,18 @@ class StickerSet(TelegramObject):
is_video (:obj:`bool`): :obj:`True`, if the sticker set contains video stickers.
.. versionadded:: 13.11
stickers (List[:class:`telegram.Sticker`]): List of all set stickers.
sticker_type (:obj:`str`): Type of stickers in the set.
stickers (Tuple[:class:`telegram.Sticker`]): List of all set stickers.
.. versionchanged:: 20.0
|tupleclassattrs|
sticker_type (:obj:`str`): Type of stickers in the set, currently one of
:attr:`telegram.Sticker.REGULAR`, :attr:`telegram.Sticker.MASK`,
:attr:`telegram.Sticker.CUSTOM_EMOJI`.
.. versionadded:: 20.0
thumb (:class:`telegram.PhotoSize`): Optional. Sticker set thumbnail in the ``.WEBP``,
``.TGS`` or ``.WEBM`` format.
``.TGS``, or ``.WEBM`` format.
"""
@@ -246,7 +257,7 @@ class StickerSet(TelegramObject):
name: str,
title: str,
is_animated: bool,
stickers: List[Sticker],
stickers: Sequence[Sticker],
is_video: bool,
sticker_type: str,
thumb: PhotoSize = None,
@@ -258,13 +269,15 @@ class StickerSet(TelegramObject):
self.title = title
self.is_animated = is_animated
self.is_video = is_video
self.stickers = stickers
self.stickers = parse_sequence_arg(stickers)
self.sticker_type = sticker_type
# Optional
self.thumb = thumb
self._id_attrs = (self.name,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["StickerSet"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -305,9 +318,11 @@ class MaskPosition(TelegramObject):
point (:obj:`str`): The part of the face relative to which the mask should be placed.
One of :attr:`FOREHEAD`, :attr:`EYES`, :attr:`MOUTH`, or :attr:`CHIN`.
x_shift (:obj:`float`): Shift by X-axis measured in widths of the mask scaled to the face
size, from left to right.
size, from left to right. For example, choosing ``-1.0`` will place mask just to the
left of the default mask position.
y_shift (:obj:`float`): Shift by Y-axis measured in heights of the mask scaled to the face
size, from top to bottom.
size, from top to bottom. For example, ``1.0`` will place the mask just below the
default mask position.
scale (:obj:`float`): Mask scaling coefficient. For example, ``2.0`` means double size.
"""
@@ -339,3 +354,5 @@ class MaskPosition(TelegramObject):
self.scale = scale
self._id_attrs = (self.point, self.x_shift, self.y_shift, self.scale)
self._freeze()
+7 -2
View File
@@ -55,9 +55,12 @@ class Venue(TelegramObject):
title (:obj:`str`): Name of the venue.
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue. (For example,
"arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue. (See
`supported types <https://developers.google.com/maps/documentation/places/web-service\
/supported_types>`_.)
"""
@@ -97,6 +100,8 @@ class Venue(TelegramObject):
self._id_attrs = (self.location, self.title)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Venue"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+10 -9
View File
@@ -44,7 +44,8 @@ class Video(_BaseThumbedMedium):
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
@@ -56,7 +57,6 @@ class Video(_BaseThumbedMedium):
mime_type (:obj:`str`): Optional. MIME type of a file as defined by sender.
file_size (:obj:`int`): Optional. File size in bytes.
"""
__slots__ = ("duration", "file_name", "height", "mime_type", "width")
@@ -82,10 +82,11 @@ class Video(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
with self._unfrozen():
# Required
self.width = width
self.height = height
self.duration = duration
# Optional
self.mime_type = mime_type
self.file_name = file_name
+8 -5
View File
@@ -42,11 +42,13 @@ class VideoNote(_BaseThumbedMedium):
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
length (:obj:`int`): Video width and height as defined by sender.
length (:obj:`int`): Video width and height (diameter of the video message) as defined
by sender.
duration (:obj:`int`): Duration of the video in seconds as defined by sender.
thumb (:class:`telegram.PhotoSize`): Optional. Video thumbnail.
file_size (:obj:`int`): Optional. File size in bytes.
@@ -73,6 +75,7 @@ class VideoNote(_BaseThumbedMedium):
thumb=thumb,
api_kwargs=api_kwargs,
)
# Required
self.length = length
self.duration = duration
with self._unfrozen():
# Required
self.length = length
self.duration = duration
+8 -6
View File
@@ -34,12 +34,13 @@ class Voice(_BaseMedium):
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
duration (:obj:`int`, optional): Duration of the audio in seconds as defined by sender.
duration (:obj:`int`): Duration of the audio in seconds as defined by sender.
mime_type (:obj:`str`, optional): MIME type of the file as defined by sender.
file_size (:obj:`int`, optional): File size in bytes.
Attributes:
file_id (:obj:`str`): Identifier for this file.
file_id (:obj:`str`): Identifier for this file, which can be used to download
or reuse the file.
file_unique_id (:obj:`str`): Unique identifier for this file, which
is supposed to be the same over time and for different bots.
Can't be used to download or reuse the file.
@@ -67,7 +68,8 @@ class Voice(_BaseMedium):
file_size=file_size,
api_kwargs=api_kwargs,
)
# Required
self.duration = duration
# Optional
self.mime_type = mime_type
with self._unfrozen():
# Required
self.duration = duration
# Optional
self.mime_type = mime_type
+13 -3
View File
@@ -59,9 +59,17 @@ class ForceReply(TelegramObject):
Attributes:
force_reply (:obj:`True`): Shows reply interface to the user, as if they manually selected
the bots message and tapped 'Reply'.
selective (:obj:`bool`): Optional. Force reply from specific users only.
input_field_placeholder (:obj:`str`): Optional. The placeholder shown in the input
field when the reply is active.
selective (:obj:`bool`): Optional. Force reply from specific users only. Targets:
1) Users that are @mentioned in the :attr:`~telegram.Message.text` of the
:class:`telegram.Message` object.
2) If the bot's message is a reply (has ``reply_to_message_id``), sender of the
original message.
input_field_placeholder (:obj:`str`): Optional. The placeholder to be shown in the input
field when the reply is active;
:tg-const:`telegram.ForceReply.MIN_INPUT_FIELD_PLACEHOLDER`-
:tg-const:`telegram.ForceReply.MAX_INPUT_FIELD_PLACEHOLDER`
characters.
.. versionadded:: 13.7
@@ -83,6 +91,8 @@ class ForceReply(TelegramObject):
self._id_attrs = (self.selective,)
self._freeze()
MIN_INPUT_FIELD_PLACEHOLDER: ClassVar[int] = constants.ReplyLimit.MIN_INPUT_FIELD_PLACEHOLDER
""":const:`telegram.constants.ReplyLimit.MIN_INPUT_FIELD_PLACEHOLDER`
+84
View File
@@ -66,6 +66,8 @@ class ForumTopic(TelegramObject):
self._id_attrs = (self.message_thread_id, self.name, self.icon_color)
self._freeze()
class ForumTopicCreated(TelegramObject):
"""
@@ -107,6 +109,8 @@ class ForumTopicCreated(TelegramObject):
self._id_attrs = (self.name, self.icon_color)
self._freeze()
class ForumTopicClosed(TelegramObject):
"""
@@ -118,6 +122,11 @@ class ForumTopicClosed(TelegramObject):
__slots__ = ()
def __init__(self, *, api_kwargs: JSONDict = None) -> None:
super().__init__(api_kwargs=api_kwargs)
self._freeze()
class ForumTopicReopened(TelegramObject):
"""
@@ -128,3 +137,78 @@ class ForumTopicReopened(TelegramObject):
"""
__slots__ = ()
def __init__(self, *, api_kwargs: JSONDict = None) -> None:
super().__init__(api_kwargs=api_kwargs)
self._freeze()
class ForumTopicEdited(TelegramObject):
"""
This object represents a service message about an edited forum topic.
Objects of this class are comparable in terms of equality. Two objects of this class are
considered equal, if their :attr:`name` and :attr:`icon_custom_emoji_id` are equal.
.. versionadded:: 20.0
Args:
name (:obj:`str`, optional): New name of the topic, if it was edited.
icon_custom_emoji_id (:obj:`str`, optional): New identifier of the custom emoji shown as
the topic icon, if it was edited; an empty string if the icon was removed.
Attributes:
name (:obj:`str`): Optional. New name of the topic, if it was edited.
icon_custom_emoji_id (:obj:`str`): Optional. New identifier of the custom emoji shown as
the topic icon, if it was edited; an empty string if the icon was removed.
"""
__slots__ = ("name", "icon_custom_emoji_id")
def __init__(
self,
name: str = None,
icon_custom_emoji_id: str = None,
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
self.name = name
self.icon_custom_emoji_id = icon_custom_emoji_id
self._id_attrs = (self.name, self.icon_custom_emoji_id)
self._freeze()
class GeneralForumTopicHidden(TelegramObject):
"""
This object represents a service message about General forum topic hidden in the chat.
Currently holds no information.
.. versionadded:: 20.0
"""
__slots__ = ()
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self._freeze()
class GeneralForumTopicUnhidden(TelegramObject):
"""
This object represents a service message about General forum topic unhidden in the chat.
Currently holds no information.
.. versionadded:: 20.0
"""
__slots__ = ()
def __init__(self, *, api_kwargs: JSONDict = None):
super().__init__(api_kwargs=api_kwargs)
self._freeze()
+6
View File
@@ -19,9 +19,15 @@
"""This module contains an object that represents a Telegram CallbackGame."""
from telegram._telegramobject import TelegramObject
from telegram._utils.types import JSONDict
class CallbackGame(TelegramObject):
"""A placeholder, currently holds no information. Use BotFather to set up your game."""
__slots__ = ()
def __init__(self, *, api_kwargs: JSONDict = None) -> None:
super().__init__(api_kwargs=api_kwargs)
self._freeze()
+32 -16
View File
@@ -17,14 +17,14 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram Game."""
import sys
from typing import TYPE_CHECKING, Dict, List, Optional
from typing import TYPE_CHECKING, Dict, List, Optional, Sequence
from telegram._files.animation import Animation
from telegram._files.photosize import PhotoSize
from telegram._messageentity import MessageEntity
from telegram._telegramobject import TelegramObject
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -42,30 +42,47 @@ class Game(TelegramObject):
Args:
title (:obj:`str`): Title of the game.
description (:obj:`str`): Description of the game.
photo (List[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game message
in chats.
photo (Sequence[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
message in chats.
.. versionchanged:: 20.0
|sequenceclassargs|
text (:obj:`str`, optional): Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
using :meth:`telegram.Bot.edit_message_text`.
0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
text_entities (List[:class:`telegram.MessageEntity`], optional): Special entities that
text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that
appear in text, such as usernames, URLs, bot commands, etc.
.. versionchanged:: 20.0
|sequenceclassargs|
animation (:class:`telegram.Animation`, optional): Animation that will be displayed in the
game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.
Attributes:
title (:obj:`str`): Title of the game.
description (:obj:`str`): Description of the game.
photo (List[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game message
in chats.
photo (Tuple[:class:`telegram.PhotoSize`]): Photo that will be displayed in the game
message in chats.
.. versionchanged:: 20.0
|tupleclassattrs|
text (:obj:`str`): Optional. Brief description of the game or high scores included in the
game message. Can be automatically edited to include current high scores for the game
when the bot calls :meth:`telegram.Bot.set_game_score`, or manually edited
using :meth:`telegram.Bot.edit_message_text`.
text_entities (List[:class:`telegram.MessageEntity`]): Special entities that
0-:tg-const:`telegram.constants.MessageLimit.MAX_TEXT_LENGTH` characters.
text_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special entities that
appear in text, such as usernames, URLs, bot commands, etc.
This list is empty if the message does not contain text entities.
This tuple is empty if the message does not contain text entities.
.. versionchanged:: 20.0
|tupleclassattrs|
animation (:class:`telegram.Animation`): Optional. Animation that will be displayed in the
game message in chats. Upload via `BotFather <https://t.me/BotFather>`_.
@@ -84,9 +101,9 @@ class Game(TelegramObject):
self,
title: str,
description: str,
photo: List[PhotoSize],
photo: Sequence[PhotoSize],
text: str = None,
text_entities: List[MessageEntity] = None,
text_entities: Sequence[MessageEntity] = None,
animation: Animation = None,
*,
api_kwargs: JSONDict = None,
@@ -95,14 +112,16 @@ class Game(TelegramObject):
# Required
self.title = title
self.description = description
self.photo = photo
self.photo = parse_sequence_arg(photo)
# Optionals
self.text = text
self.text_entities = text_entities or []
self.text_entities = parse_sequence_arg(text_entities)
self.animation = animation
self._id_attrs = (self.title, self.description, self.photo)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["Game"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -178,6 +197,3 @@ class Game(TelegramObject):
for entity in self.text_entities
if entity.type in types
}
def __hash__(self) -> int:
return hash((self.title, self.description, tuple(p for p in self.photo)))
+2
View File
@@ -56,6 +56,8 @@ class GameHighScore(TelegramObject):
self._id_attrs = (self.position, self.user, self.score)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["GameHighScore"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+28 -17
View File
@@ -95,8 +95,7 @@ class InlineKeyboardButton(TelegramObject):
Tip:
The value entered here will be available in :attr:`telegram.CallbackQuery.data`.
.. seealso:: `Arbitrary callback_data <https://github.com/\
python-telegram-bot/python-telegram-bot/wiki/Arbitrary-callback_data>`_
.. seealso:: :wiki:`Arbitrary callback_data <Arbitrary-callback_data>`
web_app (:obj:`telegram.WebAppInfo`, optional): Description of the `Web App
<https://core.telegram.org/bots/webapps>`_ that will be launched when the user presses
@@ -110,7 +109,7 @@ class InlineKeyboardButton(TelegramObject):
specified inline query in the input field. Can be empty, in which case just the bot's
username will be inserted. This offers an easy way for users to start using your bot
in inline mode when they are currently in a private chat with it. Especially useful
when combined with switch_pm* actions - in this case the user will be automatically
when combined with ``switch_pm*`` actions - in this case the user will be automatically
returned to the chat they switched from, skipping the chat selection screen.
switch_inline_query_current_chat (:obj:`str`, optional): If set, pressing the button will
insert the bot's username and the specified inline query in the current chat's input
@@ -118,11 +117,11 @@ class InlineKeyboardButton(TelegramObject):
offers a quick way for the user to open your bot in inline mode in the same chat - good
for selecting something from multiple options.
callback_game (:class:`telegram.CallbackGame`, optional): Description of the game that will
be launched when the user presses the button. This type of button must always be
the ``first`` button in the first row.
be launched when the user presses the button. This type of button **must** always be
the **first** button in the first row.
pay (:obj:`bool`, optional): Specify :obj:`True`, to send a Pay button. This type of button
must always be the `first` button in the first row and can only be used in invoice
messages.
**must** always be the **first** button in the first row and can only be used in
invoice messages.
Attributes:
text (:obj:`str`): Label text on the button.
@@ -148,15 +147,24 @@ class InlineKeyboardButton(TelegramObject):
private chats between a user and the bot.
.. versionadded:: 20.0
switch_inline_query (:obj:`str`): Optional. Will prompt the user to select one of their
chats, open that chat and insert the bot's username and the specified inline query in
the input field. Can be empty, in which case just the bot's username will be inserted.
switch_inline_query_current_chat (:obj:`str`): Optional. Will insert the bot's username and
the specified inline query in the current chat's input field. Can be empty, in which
case just the bot's username will be inserted.
switch_inline_query (:obj:`str`): Optional. If set, pressing the button will prompt the
user to select one of their chats, open that chat and insert the bot's username and the
specified inline query in the input field. Can be empty, in which case just the bot's
username will be inserted. This offers an easy way for users to start using your bot
in inline mode when they are currently in a private chat with it. Especially useful
when combined with ``switch_pm*`` actions - in this case the user will be automatically
returned to the chat they switched from, skipping the chat selection screen.
switch_inline_query_current_chat (:obj:`str`): Optional. If set, pressing the button will
insert the bot's username and the specified inline query in the current chat's input
field. Can be empty, in which case only the bot's username will be inserted. This
offers a quick way for the user to open your bot in inline mode in the same chat - good
for selecting something from multiple options.
callback_game (:class:`telegram.CallbackGame`): Optional. Description of the game that will
be launched when the user presses the button.
pay (:obj:`bool`): Optional. Specify :obj:`True`, to send a Pay button.
be launched when the user presses the button. This type of button **must** always be
the **first** button in the first row.
pay (:obj:`bool`): Optional. Specify :obj:`True`, to send a Pay button. This type of button
**must** always be the **first** button in the first row and can only be used in
invoice messages.
"""
@@ -202,6 +210,8 @@ class InlineKeyboardButton(TelegramObject):
self._id_attrs = ()
self._set_id_attrs()
self._freeze()
def _set_id_attrs(self) -> None:
self._id_attrs = (
self.text,
@@ -239,8 +249,9 @@ class InlineKeyboardButton(TelegramObject):
Args:
callback_data (:class:`object`): The new callback data.
"""
self.callback_data = callback_data
self._set_id_attrs()
with self._unfrozen():
self.callback_data = callback_data
self._set_id_attrs()
MIN_CALLBACK_DATA: ClassVar[int] = constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA
""":const:`telegram.constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA`
+31 -19
View File
@@ -17,8 +17,7 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains an object that represents a Telegram InlineKeyboardMarkup."""
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional, Sequence
from telegram._inline.inlinekeyboardbutton import InlineKeyboardButton
from telegram._telegramobject import TelegramObject
@@ -41,12 +40,20 @@ class InlineKeyboardMarkup(TelegramObject):
* :any:`Inline Keyboard 2 <examples.inlinekeyboard2>`
Args:
inline_keyboard (List[List[:class:`telegram.InlineKeyboardButton`]]): List of button rows,
each represented by a list of InlineKeyboardButton objects.
inline_keyboard (Sequence[Sequence[:class:`telegram.InlineKeyboardButton`]]): Sequence of
button rows, each represented by a sequence of :class:`~telegram.InlineKeyboardButton`
objects.
.. versionchanged:: 20.0
|sequenceclassargs|
Attributes:
inline_keyboard (List[List[:class:`telegram.InlineKeyboardButton`]]): List of button rows,
each represented by a list of InlineKeyboardButton objects.
inline_keyboard (Tuple[Tuple[:class:`telegram.InlineKeyboardButton`]]): Tuple of
button rows, each represented by a tuple of :class:`~telegram.InlineKeyboardButton`
objects.
.. versionchanged:: 20.0
|tupleclassattrs|
"""
@@ -54,21 +61,23 @@ class InlineKeyboardMarkup(TelegramObject):
def __init__(
self,
inline_keyboard: List[List[InlineKeyboardButton]],
inline_keyboard: Sequence[Sequence[InlineKeyboardButton]],
*,
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
if not check_keyboard_type(inline_keyboard):
raise ValueError(
"The parameter `inline_keyboard` should be a list of "
"list of InlineKeyboardButtons"
"The parameter `inline_keyboard` should be a sequence of sequences of "
"InlineKeyboardButtons"
)
# Required
self.inline_keyboard = inline_keyboard
self.inline_keyboard = tuple(tuple(row) for row in inline_keyboard)
self._id_attrs = (self.inline_keyboard,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["InlineKeyboardMarkup"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
@@ -102,7 +111,7 @@ class InlineKeyboardMarkup(TelegramObject):
@classmethod
def from_row(
cls, button_row: List[InlineKeyboardButton], **kwargs: object
cls, button_row: Sequence[InlineKeyboardButton], **kwargs: object
) -> "InlineKeyboardMarkup":
"""Shortcut for::
@@ -111,15 +120,18 @@ class InlineKeyboardMarkup(TelegramObject):
Return an InlineKeyboardMarkup from a single row of InlineKeyboardButtons
Args:
button_row (List[:class:`telegram.InlineKeyboardButton`]): The button to use in the
markup
button_row (Sequence[:class:`telegram.InlineKeyboardButton`]): The button to use
in the markup
.. versionchanged:: 20.0
|sequenceargs|
"""
return cls([button_row], **kwargs) # type: ignore[arg-type]
@classmethod
def from_column(
cls, button_column: List[InlineKeyboardButton], **kwargs: object
cls, button_column: Sequence[InlineKeyboardButton], **kwargs: object
) -> "InlineKeyboardMarkup":
"""Shortcut for::
@@ -128,12 +140,12 @@ class InlineKeyboardMarkup(TelegramObject):
Return an InlineKeyboardMarkup from a single column of InlineKeyboardButtons
Args:
button_column (List[:class:`telegram.InlineKeyboardButton`]): The button to use in the
markup
button_column (Sequence[:class:`telegram.InlineKeyboardButton`]): The button to use
in the markup
.. versionchanged:: 20.0
|sequenceargs|
"""
button_grid = [[button] for button in button_column]
return cls(button_grid, **kwargs) # type: ignore[arg-type]
def __hash__(self) -> int:
return hash(tuple(tuple(button for button in row) for row in self.inline_keyboard))
+9 -2
View File
@@ -72,11 +72,16 @@ class InlineQuery(TelegramObject):
query (:obj:`str`): Text of the query (up to
:tg-const:`telegram.InlineQuery.MAX_QUERY_LENGTH` characters).
offset (:obj:`str`): Offset of the results to be returned, can be controlled by the bot.
location (:class:`telegram.Location`): Optional. Sender location, only for bots that
request user location.
chat_type (:obj:`str`): Optional. Type of the chat, from which the inline query was sent.
Can be either :tg-const:`telegram.Chat.SENDER` for a private chat with the inline query
sender, :tg-const:`telegram.Chat.PRIVATE`, :tg-const:`telegram.Chat.GROUP`,
:tg-const:`telegram.Chat.SUPERGROUP` or :tg-const:`telegram.Chat.CHANNEL`. The chat
type should be always known for requests sent from official clients and most
third-party clients, unless the request was sent from a secret chat.
.. versionadded:: 13.5
location (:class:`telegram.Location`): Optional. Sender location, only for bots that
request user location.
"""
@@ -106,6 +111,8 @@ class InlineQuery(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
@classmethod
def de_json(cls, data: Optional[JSONDict], bot: "Bot") -> Optional["InlineQuery"]:
"""See :meth:`telegram.TelegramObject.de_json`."""
+2
View File
@@ -64,6 +64,8 @@ class InlineQueryResult(TelegramObject):
self._id_attrs = (self.id,)
self._freeze()
MIN_ID_LENGTH: ClassVar[int] = constants.InlineQueryResultLimit.MIN_ID_LENGTH
""":const:`telegram.constants.InlineQueryResultLimit.MIN_ID_LENGTH`
+11 -10
View File
@@ -102,14 +102,15 @@ class InlineQueryResultArticle(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.ARTICLE, id, api_kwargs=api_kwargs)
self.title = title
self.input_message_content = input_message_content
with self._unfrozen():
self.title = title
self.input_message_content = input_message_content
# Optional
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optional
self.reply_markup = reply_markup
self.url = url
self.hide_url = hide_url
self.description = description
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+26 -15
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultAudio."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultAudio(InlineQueryResult):
Alternatively, you can use :attr:`input_message_content` to send a message with the specified
content instead of the audio.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -49,7 +51,10 @@ class InlineQueryResultAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -68,7 +73,12 @@ class InlineQueryResultAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -99,21 +109,22 @@ class InlineQueryResultAudio(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
self.audio_url = audio_url
self.title = title
with self._unfrozen():
self.audio_url = audio_url
self.title = title
# Optionals
self.performer = performer
self.audio_duration = audio_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.performer = performer
self.audio_duration = audio_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedAudio."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
file will be sent by the user. Alternatively, you can use :attr:`input_message_content` to
send a message with the specified content instead of the audio.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -46,7 +48,11 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -61,8 +67,13 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
caption (:obj:`str`): Optional. Caption,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optionals): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -87,17 +98,18 @@ class InlineQueryResultCachedAudio(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.AUDIO, id, api_kwargs=api_kwargs)
self.audio_file_id = audio_file_id
with self._unfrozen():
self.audio_file_id = audio_file_id
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedDocument."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
by the user with an optional caption. Alternatively, you can use :attr:`input_message_content`
to send a message with the specified content instead of the file.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -48,7 +50,11 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -66,7 +72,12 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -95,19 +106,20 @@ class InlineQueryResultCachedDocument(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
self.title = title
self.document_file_id = document_file_id
with self._unfrozen():
self.title = title
self.document_file_id = document_file_id
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+26 -14
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedGif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,17 +38,23 @@ class InlineQueryResultCachedGif(InlineQueryResult):
use :attr:`input_message_content` to send a message with specified content instead of
the animation.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
:tg-const:`telegram.InlineQueryResult.MAX_ID_LENGTH` Bytes.
gif_file_id (:obj:`str`): A valid file identifier for the GIF file.
title (:obj:`str`, optional): Title for the result.caption (:obj:`str`, optional):
title (:obj:`str`, optional): Title for the result.
caption (:obj:`str`, optional): Caption of the GIF file to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -65,7 +71,12 @@ class InlineQueryResultCachedGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -92,18 +103,19 @@ class InlineQueryResultCachedGif(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
self.gif_file_id = gif_file_id
with self._unfrozen():
self.gif_file_id = gif_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
optional caption. Alternatively, you can use :attr:`input_message_content` to send a message
with the specified content instead of the animation.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -48,7 +50,11 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -65,7 +71,12 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -92,18 +103,19 @@ class InlineQueryResultCachedMpeg4Gif(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
self.mpeg4_file_id = mpeg4_file_id
with self._unfrozen():
self.mpeg4_file_id = mpeg4_file_id
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto"""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
:attr:`input_message_content` to send a message with the specified content instead
of the photo.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -49,7 +51,11 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -67,7 +73,12 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -96,19 +107,20 @@ class InlineQueryResultCachedPhoto(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
self.photo_file_id = photo_file_id
with self._unfrozen():
self.photo_file_id = photo_file_id
# Optionals
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -35,6 +35,8 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
be sent by the user. Alternatively, you can use :attr:`input_message_content` to send a
message with the specified content instead of the sticker.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -71,8 +73,9 @@ class InlineQueryResultCachedSticker(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.STICKER, id, api_kwargs=api_kwargs)
self.sticker_file_id = sticker_file_id
with self._unfrozen():
self.sticker_file_id = sticker_file_id
# Optionals
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVideo."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
:attr:`input_message_content` to send a message with the specified content instead
of the video.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -49,7 +51,7 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -67,7 +69,12 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -96,19 +103,20 @@ class InlineQueryResultCachedVideo(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
self.video_file_id = video_file_id
self.title = title
with self._unfrozen():
self.video_file_id = video_file_id
self.title = title
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultCachedVoice."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
message will be sent by the user. Alternatively, you can use :attr:`input_message_content` to
send a message with the specified content instead of the voice message.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -47,7 +49,11 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional):
|captionentitiesattr|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -64,7 +70,12 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -91,18 +102,19 @@ class InlineQueryResultCachedVoice(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
self.voice_file_id = voice_file_id
self.title = title
with self._unfrozen():
self.voice_file_id = voice_file_id
self.title = title
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+11 -10
View File
@@ -101,14 +101,15 @@ class InlineQueryResultContact(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.CONTACT, id, api_kwargs=api_kwargs)
self.phone_number = phone_number
self.first_name = first_name
with self._unfrozen():
self.phone_number = phone_number
self.first_name = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optionals
self.last_name = last_name
self.vcard = vcard
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+30 -18
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultDocument"""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultDocument(InlineQueryResult):
specified content instead of the file. Currently, only .PDF and .ZIP files can be sent
using this method.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -47,7 +49,11 @@ class InlineQueryResultDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
document_url (:obj:`str`): A valid URL for the file.
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
or "application/zip".
@@ -70,7 +76,12 @@ class InlineQueryResultDocument(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
document_url (:obj:`str`): A valid URL for the file.
mime_type (:obj:`str`): Mime type of the content of the file, either "application/pdf"
or "application/zip".
@@ -114,23 +125,24 @@ class InlineQueryResultDocument(InlineQueryResult):
thumb_width: int = None,
thumb_height: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.DOCUMENT, id, api_kwargs=api_kwargs)
self.document_url = document_url
self.title = title
self.mime_type = mime_type
with self._unfrozen():
self.document_url = document_url
self.title = title
self.mime_type = mime_type
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optionals
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+4 -3
View File
@@ -58,7 +58,8 @@ class InlineQueryResultGame(InlineQueryResult):
):
# Required
super().__init__(InlineQueryResultType.GAME, id, api_kwargs=api_kwargs)
self.id = id
self.game_short_name = game_short_name
with self._unfrozen():
self.id = id
self.game_short_name = game_short_name
self.reply_markup = reply_markup
self.reply_markup = reply_markup
+32 -19
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultGif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultGif(InlineQueryResult):
the user with optional caption. Alternatively, you can use :attr:`input_message_content` to
send a message with the specified content instead of the animation.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -54,7 +56,11 @@ class InlineQueryResultGif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -71,13 +77,19 @@ class InlineQueryResultGif(InlineQueryResult):
gif_duration (:obj:`int`): Optional. Duration of the GIF in seconds.
thumb_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for
the result.
thumb_mime_type (:obj:`str`): Optional. MIME type of the thumbnail.
thumb_mime_type (:obj:`str`): Optional. MIME type of the thumbnail, must be one of
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
title (:obj:`str`): Optional. Title for the result.
caption (:obj:`str`): Optional. Caption of the GIF file to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -114,24 +126,25 @@ class InlineQueryResultGif(InlineQueryResult):
gif_duration: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb_mime_type: str = None,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.GIF, id, api_kwargs=api_kwargs)
self.gif_url = gif_url
self.thumb_url = thumb_url
with self._unfrozen():
self.gif_url = gif_url
self.thumb_url = thumb_url
# Optionals
self.gif_width = gif_width
self.gif_height = gif_height
self.gif_duration = gif_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
# Optionals
self.gif_width = gif_width
self.gif_height = gif_height
self.gif_duration = gif_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
+30 -21
View File
@@ -75,13 +75,21 @@ class InlineQueryResultLocation(InlineQueryResult):
longitude (:obj:`float`): Location longitude in degrees.
title (:obj:`str`): Location title.
horizontal_accuracy (:obj:`float`): Optional. The radius of uncertainty for the location,
measured in meters.
live_period (:obj:`int`): Optional. Period in seconds for which the location can be
updated, should be between 60 and 86400.
measured in meters; 0-
:tg-const:`telegram.InlineQueryResultLocation.HORIZONTAL_ACCURACY`.
live_period (:obj:`int`): Optional. Period in seconds for which the location will be
updated, should be between
:tg-const:`telegram.InlineQueryResultLocation.MIN_LIVE_PERIOD` and
:tg-const:`telegram.InlineQueryResultLocation.MAX_LIVE_PERIOD`.
heading (:obj:`int`): Optional. For live locations, a direction in which the user is
moving, in degrees.
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance for
proximity alerts about approaching another chat member, in meters.
moving, in degrees. Must be between
:tg-const:`telegram.InlineQueryResultLocation.MIN_HEADING` and
:tg-const:`telegram.InlineQueryResultLocation.MAX_HEADING` if specified.
proximity_alert_radius (:obj:`int`): Optional. For live locations, a maximum distance
for proximity alerts about approaching another chat member, in meters. Must be
between :tg-const:`telegram.InlineQueryResultLocation.MIN_PROXIMITY_ALERT_RADIUS`
and :tg-const:`telegram.InlineQueryResultLocation.MAX_PROXIMITY_ALERT_RADIUS`
if specified.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -127,22 +135,23 @@ class InlineQueryResultLocation(InlineQueryResult):
):
# Required
super().__init__(constants.InlineQueryResultType.LOCATION, id, api_kwargs=api_kwargs)
self.latitude = latitude
self.longitude = longitude
self.title = title
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
# Optionals
self.live_period = live_period
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)
# Optionals
self.live_period = live_period
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
self.horizontal_accuracy = horizontal_accuracy
self.heading = heading
self.proximity_alert_radius = (
int(proximity_alert_radius) if proximity_alert_radius else None
)
HORIZONTAL_ACCURACY: ClassVar[int] = constants.LocationLimit.HORIZONTAL_ACCURACY
""":const:`telegram.constants.LocationLimit.HORIZONTAL_ACCURACY`
+36 -20
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultMpeg4Gif."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
use :attr:`input_message_content` to send a message with the specified content instead of the
animation.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -46,7 +48,8 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
mpeg4_width (:obj:`int`, optional): Video width.
mpeg4_height (:obj:`int`, optional): Video height.
mpeg4_duration (:obj:`int`, optional): Video duration in seconds.
thumb_url (:obj:`str`): URL of the static thumbnail (jpeg or gif) for the result.
thumb_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for
the result.
thumb_mime_type (:obj:`str`): Optional. MIME type of the thumbnail, must be one of
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
title (:obj:`str`, optional): Title for the result.
@@ -54,7 +57,12 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional):
|captionentitiesattr|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -71,13 +79,20 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
mpeg4_duration (:obj:`int`): Optional. Video duration in seconds.
thumb_url (:obj:`str`): URL of the static (JPEG or GIF) or animated (MPEG4) thumbnail for
the result.
thumb_mime_type (:obj:`str`): Optional. MIME type of the thumbnail.
thumb_mime_type (:obj:`str`): Optional. MIME type of the thumbnail, must be one of
``'image/jpeg'``, ``'image/gif'``, or ``'video/mp4'``. Defaults to ``'image/jpeg'``.
title (:obj:`str`): Optional. Title for the result.
caption (:obj:`str`): Optional. Caption of the MPEG-4 file to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters
after entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -114,24 +129,25 @@ class InlineQueryResultMpeg4Gif(InlineQueryResult):
mpeg4_duration: int = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
thumb_mime_type: str = None,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.MPEG4GIF, id, api_kwargs=api_kwargs)
self.mpeg4_url = mpeg4_url
self.thumb_url = thumb_url
with self._unfrozen():
self.mpeg4_url = mpeg4_url
self.thumb_url = thumb_url
# Optional
self.mpeg4_width = mpeg4_width
self.mpeg4_height = mpeg4_height
self.mpeg4_duration = mpeg4_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
# Optional
self.mpeg4_width = mpeg4_width
self.mpeg4_height = mpeg4_height
self.mpeg4_duration = mpeg4_duration
self.title = title
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_mime_type = thumb_mime_type
+29 -17
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultPhoto."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -37,6 +37,8 @@ class InlineQueryResultPhoto(InlineQueryResult):
caption. Alternatively, you can use :attr:`input_message_content` to send a message with the
specified content instead of the photo.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -52,7 +54,11 @@ class InlineQueryResultPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
@@ -74,7 +80,12 @@ class InlineQueryResultPhoto(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -109,22 +120,23 @@ class InlineQueryResultPhoto(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.PHOTO, id, api_kwargs=api_kwargs)
self.photo_url = photo_url
self.thumb_url = thumb_url
with self._unfrozen():
self.photo_url = photo_url
self.thumb_url = thumb_url
# Optionals
self.photo_width = photo_width
self.photo_height = photo_height
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optionals
self.photo_width = photo_width
self.photo_height = photo_height
self.title = title
self.description = description
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+21 -16
View File
@@ -58,7 +58,7 @@ class InlineQueryResultVenue(InlineQueryResult):
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
message to be sent instead of the location.
message to be sent instead of the venue.
thumb_url (:obj:`str`, optional): Url of the thumbnail for the result.
thumb_width (:obj:`int`, optional): Thumbnail width.
thumb_height (:obj:`int`, optional): Thumbnail height.
@@ -74,8 +74,12 @@ class InlineQueryResultVenue(InlineQueryResult):
address (:obj:`str`): Address of the venue.
foursquare_id (:obj:`str`): Optional. Foursquare identifier of the venue if known.
foursquare_type (:obj:`str`): Optional. Foursquare type of the venue, if known.
(For example, "arts_entertainment/default", "arts_entertainment/aquarium" or
"food/icecream".)
google_place_id (:obj:`str`): Optional. Google Places identifier of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue.
google_place_type (:obj:`str`): Optional. Google Places type of the venue. (See
`supported types <https://developers.google.com/maps/documentation/places/web-service\
/supported_types>`_.)
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
@@ -124,18 +128,19 @@ class InlineQueryResultVenue(InlineQueryResult):
# Required
super().__init__(InlineQueryResultType.VENUE, id, api_kwargs=api_kwargs)
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
with self._unfrozen():
self.latitude = latitude
self.longitude = longitude
self.title = title
self.address = address
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
# Optional
self.foursquare_id = foursquare_id
self.foursquare_type = foursquare_type
self.google_place_id = google_place_id
self.google_place_type = google_place_type
self.reply_markup = reply_markup
self.input_message_content = input_message_content
self.thumb_url = thumb_url
self.thumb_width = thumb_width
self.thumb_height = thumb_height
+46 -32
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVideo."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -42,6 +42,8 @@ class InlineQueryResultVideo(InlineQueryResult):
If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must
replace its content using :attr:`input_message_content`.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -50,11 +52,15 @@ class InlineQueryResultVideo(InlineQueryResult):
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
thumb_url (:obj:`str`): URL of the thumbnail (JPEG only) for the video.
title (:obj:`str`): Title for the result.
caption (:obj:`str`, optional): Caption,
caption (:obj:`str`, optional): Caption of the video to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
video_width (:obj:`int`, optional): Video width.
video_height (:obj:`int`, optional): Video height.
video_duration (:obj:`int`, optional): Video duration in seconds.
@@ -63,7 +69,7 @@ class InlineQueryResultVideo(InlineQueryResult):
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
message to be sent instead of the video. This field is required if
InlineQueryResultVideo is used to send an HTML-page as a result
``InlineQueryResultVideo`` is used to send an HTML-page as a result
(e.g., a YouTube video).
Attributes:
@@ -75,20 +81,27 @@ class InlineQueryResultVideo(InlineQueryResult):
mime_type (:obj:`str`): Mime type of the content of video url, "text/html" or "video/mp4".
thumb_url (:obj:`str`): URL of the thumbnail (JPEG only) for the video.
title (:obj:`str`): Title for the result.
caption (:obj:`str`, optional): Caption of the video to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after
entities parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
video_width (:obj:`int`, optional): Video width.
video_height (:obj:`int`, optional): Video height.
video_duration (:obj:`int`, optional): Video duration in seconds.
description (:obj:`str`, optional): Short description of the result.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
caption (:obj:`str`): Optional. Caption of the video to be sent,
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional.
|captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
video_width (:obj:`int`): Optional. Video width.
video_height (:obj:`int`): Optional. Video height.
video_duration (:obj:`int`): Optional. Video duration in seconds.
description (:obj:`str`): Optional. Short description of the result.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
input_message_content (:class:`telegram.InputMessageContent`, optional): Content of the
input_message_content (:class:`telegram.InputMessageContent`): Optional. Content of the
message to be sent instead of the video. This field is required if
InlineQueryResultVideo is used to send an HTML-page as a result
``InlineQueryResultVideo`` is used to send an HTML-page as a result
(e.g., a YouTube video).
"""
@@ -124,25 +137,26 @@ class InlineQueryResultVideo(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VIDEO, id, api_kwargs=api_kwargs)
self.video_url = video_url
self.mime_type = mime_type
self.thumb_url = thumb_url
self.title = title
with self._unfrozen():
self.video_url = video_url
self.mime_type = mime_type
self.thumb_url = thumb_url
self.title = title
# Optional
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.video_width = video_width
self.video_height = video_height
self.video_duration = video_duration
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optional
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.video_width = video_width
self.video_height = video_height
self.video_duration = video_duration
self.description = description
self.reply_markup = reply_markup
self.input_message_content = input_message_content
+26 -14
View File
@@ -17,12 +17,12 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains the classes that represent Telegram InlineQueryResultVoice."""
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING, Sequence
from telegram._inline.inlinekeyboardmarkup import InlineKeyboardMarkup
from telegram._inline.inlinequeryresult import InlineQueryResult
from telegram._messageentity import MessageEntity
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.defaultvalue import DEFAULT_NONE
from telegram._utils.types import JSONDict, ODVInput
from telegram.constants import InlineQueryResultType
@@ -38,6 +38,8 @@ class InlineQueryResultVoice(InlineQueryResult):
:attr:`input_message_content` to send a message with the specified content instead of
the voice message.
.. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
Args:
id (:obj:`str`): Unique identifier for this result,
:tg-const:`telegram.InlineQueryResult.MIN_ID_LENGTH`-
@@ -48,7 +50,11 @@ class InlineQueryResultVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`, optional): |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`], optional): |caption_entities|
caption_entities (Sequence[:class:`telegram.MessageEntity`], optional): |caption_entities|
.. versionchanged:: 20.0
|sequenceclassargs|
voice_duration (:obj:`int`, optional): Recording duration in seconds.
reply_markup (:class:`telegram.InlineKeyboardMarkup`, optional): Inline keyboard attached
to the message.
@@ -66,7 +72,12 @@ class InlineQueryResultVoice(InlineQueryResult):
0-:tg-const:`telegram.constants.MessageLimit.CAPTION_LENGTH` characters after entities
parsing.
parse_mode (:obj:`str`): Optional. |parse_mode|
caption_entities (List[:class:`telegram.MessageEntity`]): Optional. |caption_entities|
caption_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. |captionentitiesattr|
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
voice_duration (:obj:`int`): Optional. Recording duration in seconds.
reply_markup (:class:`telegram.InlineKeyboardMarkup`): Optional. Inline keyboard attached
to the message.
@@ -96,20 +107,21 @@ class InlineQueryResultVoice(InlineQueryResult):
reply_markup: InlineKeyboardMarkup = None,
input_message_content: "InputMessageContent" = None,
parse_mode: ODVInput[str] = DEFAULT_NONE,
caption_entities: Union[Tuple[MessageEntity, ...], List[MessageEntity]] = None,
caption_entities: Sequence[MessageEntity] = None,
*,
api_kwargs: JSONDict = None,
):
# Required
super().__init__(InlineQueryResultType.VOICE, id, api_kwargs=api_kwargs)
self.voice_url = voice_url
self.title = title
with self._unfrozen():
self.voice_url = voice_url
self.title = title
# Optional
self.voice_duration = voice_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = caption_entities
self.reply_markup = reply_markup
self.input_message_content = input_message_content
# Optional
self.voice_duration = voice_duration
self.caption = caption
self.parse_mode = parse_mode
self.caption_entities = parse_sequence_arg(caption_entities)
self.reply_markup = reply_markup
self.input_message_content = input_message_content
@@ -56,12 +56,12 @@ class InputContactMessageContent(InputMessageContent):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
with self._unfrozen():
# Required
self.phone_number = phone_number
self.first_name = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
# Required
self.phone_number = phone_number
self.first_name = first_name
# Optionals
self.last_name = last_name
self.vcard = vcard
self._id_attrs = (self.phone_number,)
self._id_attrs = (self.phone_number,)
+68 -52
View File
@@ -17,11 +17,11 @@
# You should have received a copy of the GNU Lesser Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
"""This module contains a class that represents a Telegram InputInvoiceMessageContent."""
from typing import TYPE_CHECKING, List, Optional
from typing import TYPE_CHECKING, Optional, Sequence
from telegram._inline.inputmessagecontent import InputMessageContent
from telegram._payment.labeledprice import LabeledPrice
from telegram._utils.argumentparsing import parse_sequence_arg
from telegram._utils.types import JSONDict
if TYPE_CHECKING:
@@ -52,20 +52,30 @@ class InputInvoiceMessageContent(InputMessageContent):
`@Botfather <https://t.me/Botfather>`_.
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_
prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
prices (Sequence[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
etc.)
.. versionchanged:: 20.0
|sequenceclassargs|
max_tip_amount (:obj:`int`, optional): The maximum accepted amount for tips in the
*smallest* units of the currency (integer, **not** float/double). For example, for a
maximum tip of US$ 1.45 pass ``max_tip_amount = 145``. See the ``exp`` parameter in
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it
shows the number of digits past the decimal point for each currency (2 for the majority
of currencies). Defaults to ``0``.
suggested_tip_amounts (List[:obj:`int`], optional): An array of suggested
suggested_tip_amounts (Sequence[:obj:`int`], optional): An array of suggested
amounts of tip in the *smallest* units of the currency (integer, **not** float/double).
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
positive, passed in a strictly increased order and must not exceed
:attr:`max_tip_amount`.
.. versionchanged:: 20.0
* |tupleclassattrs|
* |alwaystuple|
provider_data (:obj:`str`, optional): An object for data about the invoice,
which will be shared with the payment provider. A detailed description of the required
fields should be provided by the payment provider.
@@ -104,15 +114,34 @@ class InputInvoiceMessageContent(InputMessageContent):
`@Botfather <https://t.me/Botfather>`_.
currency (:obj:`str`): Three-letter ISO 4217 currency code, see more on
`currencies <https://core.telegram.org/bots/payments#supported-currencies>`_
prices (List[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
components.
max_tip_amount (:obj:`int`): Optional. The maximum accepted amount for tips in the smallest
units of the currency (integer, not float/double).
suggested_tip_amounts (List[:obj:`int`]): Optional. An array of suggested
amounts of tip in the smallest units of the currency (integer, not float/double).
prices (Tuple[:class:`telegram.LabeledPrice`]): Price breakdown, a list of
components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus,
etc.)
.. versionchanged:: 20.0
|tupleclassattrs|
max_tip_amount (:obj:`int`): Optional. The maximum accepted amount for tips in the
*smallest* units of the currency (integer, **not** float/double). For example, for a
maximum tip of US$ 1.45 ``max_tip_amount`` is ``145``. See the ``exp`` parameter in
`currencies.json <https://core.telegram.org/bots/payments/currencies.json>`_, it
shows the number of digits past the decimal point for each currency (2 for the majority
of currencies). Defaults to ``0``.
suggested_tip_amounts (Tuple[:obj:`int`]): Optional. An array of suggested
amounts of tip in the *smallest* units of the currency (integer, **not** float/double).
At most 4 suggested tip amounts can be specified. The suggested tip amounts must be
positive, passed in a strictly increased order and must not exceed
:attr:`max_tip_amount`.
.. versionchanged:: 20.0
|tupleclassattrs|
provider_data (:obj:`str`): Optional. An object for data about the invoice,
which will be shared with the payment provider.
photo_url (:obj:`str`): Optional. URL of the product photo for the invoice.
which will be shared with the payment provider. A detailed description of the required
fields should be provided by the payment provider.
photo_url (:obj:`str`): Optional. URL of the product photo for the invoice. Can be a photo
of the goods or a marketing image for a service. People like it better when they see
what they are paying for.
photo_size (:obj:`int`): Optional. Photo size.
photo_width (:obj:`int`): Optional. Photo width.
photo_height (:obj:`int`): Optional. Photo height.
@@ -163,9 +192,9 @@ class InputInvoiceMessageContent(InputMessageContent):
payload: str,
provider_token: str,
currency: str,
prices: List[LabeledPrice],
prices: Sequence[LabeledPrice],
max_tip_amount: int = None,
suggested_tip_amounts: List[int] = None,
suggested_tip_amounts: Sequence[int] = None,
provider_data: str = None,
photo_url: str = None,
photo_size: int = None,
@@ -182,51 +211,38 @@ class InputInvoiceMessageContent(InputMessageContent):
api_kwargs: JSONDict = None,
):
super().__init__(api_kwargs=api_kwargs)
# Required
self.title = title
self.description = description
self.payload = payload
self.provider_token = provider_token
self.currency = currency
self.prices = prices
# Optionals
self.max_tip_amount = max_tip_amount
self.suggested_tip_amounts = suggested_tip_amounts
self.provider_data = provider_data
self.photo_url = photo_url
self.photo_size = photo_size
self.photo_width = photo_width
self.photo_height = photo_height
self.need_name = need_name
self.need_phone_number = need_phone_number
self.need_email = need_email
self.need_shipping_address = need_shipping_address
self.send_phone_number_to_provider = send_phone_number_to_provider
self.send_email_to_provider = send_email_to_provider
self.is_flexible = is_flexible
with self._unfrozen():
# Required
self.title = title
self.description = description
self.payload = payload
self.provider_token = provider_token
self.currency = currency
self.prices = parse_sequence_arg(prices)
# Optionals
self.max_tip_amount = max_tip_amount
self.suggested_tip_amounts = parse_sequence_arg(suggested_tip_amounts)
self.provider_data = provider_data
self.photo_url = photo_url
self.photo_size = photo_size
self.photo_width = photo_width
self.photo_height = photo_height
self.need_name = need_name
self.need_phone_number = need_phone_number
self.need_email = need_email
self.need_shipping_address = need_shipping_address
self.send_phone_number_to_provider = send_phone_number_to_provider
self.send_email_to_provider = send_email_to_provider
self.is_flexible = is_flexible
self._id_attrs = (
self.title,
self.description,
self.payload,
self.provider_token,
self.currency,
self.prices,
)
def __hash__(self) -> int:
# we override this as self.prices is a list and not hashable
prices = tuple(self.prices)
return hash(
(
self._id_attrs = (
self.title,
self.description,
self.payload,
self.provider_token,
self.currency,
prices,
self.prices,
)
)
@classmethod
def de_json(

Some files were not shown because too many files have changed in this diff Show More