We have made you a wrapper you can't refuse

Overview
python-telegram-bot Logo

We have made you a wrapper you can't refuse

We have a vibrant community of developers helping each other in our Telegram group. Join us!

Stay tuned for library updates and new releases on our Telegram Channel.

PyPi Package Version Supported Python versions Supported Bot API versions PyPi Package Monthly Download Documentation Status LGPLv3 License Github Actions workflow Code coverage Median time to resolve an issue Code quality Telegram Group IRC Bridge

Table of contents

Introduction

This library provides a pure Python interface for the Telegram Bot API. It's compatible with Python versions 3.6+. PTB might also work on PyPy, though there have been a lot of issues before. Hence, PyPy is not officially supported.

In addition to the pure API implementation, this library features a number of high-level classes to make the development of bots easy and straightforward. These classes are contained in the telegram.ext submodule.

A pure API implementation without telegram.ext is available as the standalone package python-telegram-bot-raw. See here for details.

Note

Installing both python-telegram-bot and python-telegram-bot-raw in conjunction will result in undesired side-effects, so only install one of both.

Telegram API support

All types and methods of the Telegram Bot API 5.0 are supported.

Installing

You can install or upgrade python-telegram-bot with:

$ pip install python-telegram-bot --upgrade

Or you can install from source with:

$ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive
$ cd python-telegram-bot
$ python setup.py install

In case you have a previously cloned local repository already, you should initialize the added urllib3 submodule before installing with:

$ git submodule update --init --recursive

Getting started

Our Wiki contains a lot of resources to get you started with python-telegram-bot:

Other references:

Learning by example

We believe that the best way to learn this package is by example. Here are some examples for you to review. Even if it is not your approach for learning, please take a look at echobot.py, it is the de facto base for most of the bots out there. Best of all, the code for these examples are released to the public domain, so you can start by grabbing the code and building on top of it.

Visit this page to discover the official examples or look at the examples on the wiki to see other bots the community has built.

Logging

This library uses the logging module. To set up logging to standard output, put:

import logging
logging.basicConfig(level=logging.DEBUG,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

at the beginning of your script.

You can also use logs in your application by calling logging.getLogger() and setting the log level you want:

logger = logging.getLogger()
logger.setLevel(logging.INFO)

If you want DEBUG logs instead:

logger.setLevel(logging.DEBUG)

Documentation

python-telegram-bot's documentation lives at readthedocs.io.

Getting help

You can get help in several ways:

  1. We have a vibrant community of developers helping each other in our Telegram group. Join us!
  2. In case you are unable to join our group due to Telegram restrictions, you can use our IRC channel.
  3. Report bugs, request new features or ask questions by creating an issue or a discussion.
  4. Our Wiki pages offer a growing amount of resources.
  5. You can even ask for help on Stack Overflow using the python-telegram-bot tag.

Contributing

Contributions of all sizes are welcome. Please review our contribution guidelines to get started. You can also help by reporting bugs.

License

You may copy, distribute and modify the software provided that modifications are described and licensed for free under LGPL-3. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL-3, but applications that use the library don't have to be.

Issues
  • Type-hinting for IDEs

    Type-hinting for IDEs

    Hi there,

    I like to use the Message.reply_* functions but it's kind of annoying to always look up the parameters manually. There is a lack of type-hinting here. And with python stub files (or type hinting in the python files directly this would not be a problem at all.

    The Problem is, if I have a update instance and I call update.message it doesn't know that this is a Message instance. If I tell my IDE using message = update.message # type: Message it works so far. But when I then type message.reply_text( there is no type-hinting (or variable hinting for that matter) for the named parameters. This is annoying.

    I started to create python stub files like this: message-type-hint

    But it would be awesome if type-hinting a la PEP-484 would be integrated in the project itself.

    I know that python 2 compatibility (at least until EOL) is still a thing, but type-hinting with comments like described above (and at some place in PEP-484) is always possible for both python versions. update-type-hint

    enhancement documentation 
    opened by TiiFuchs 39
  • Refactor how InputMedia* subclasses handle inits

    Refactor how InputMedia* subclasses handle inits

    Currently all the subclasses handle the init completely on their own, while it would make more sense to move all attributes shared between the subclasses to InputMedia, i.e. call super().__init__ like we do for InlineQueryResult*. This includes the attributes caption_entities, parse_mode, type, media & caption

    See https://t.me/c/1494805131/16382 + replies for discussion.

    good first issue hacktoberfest refactor :gear: 
    opened by Bibo-Joshi 36
  • Socks proxy error

    Socks proxy error

    Steps to reproduce

    The code compares behaviour of two libs: urllib3 and python-telegram-bot:

    TOKEN = '<your_api_token>'
    SOCKS_URL = 'socks5://<your_sock5_proxy_host>:1080/'
    SOCKS_USER = '<your_sock5_proxy_user>'
    SOCKS_PASS = '<your_sock5_proxy_password>'
    
    ################## urllib3 ##################
    
    import urllib3
    urllib3.disable_warnings()
    from urllib3.contrib.socks import SOCKSProxyManager
    
    manager = SOCKSProxyManager(
    	SOCKS_URL,
    	username = SOCKS_USER,
    	password = SOCKS_PASS,
    )
    response = manager.request('GET', 'https://api.telegram.org/bot' + TOKEN + '/getMe')
    print response.data
    
    ############ python-telegram-bot ############
    
    from telegram.utils.request import Request
    from telegram import Bot
    
    bot = Bot(
    	TOKEN,
    	request = Request(
    		proxy_url = SOCKS_URL,
    		urllib3_proxy_kwargs = {
    				'username': SOCKS_USER,
    				'password': SOCKS_PASS,
    		},
    	)
    )
    print str(bot.get_me().id)
    

    Expected behaviour

    I expect the same behaviour of both libraries: urllib3 and python-telegram-bot.

    Actual behaviour

    urllib3 works well, but python-telegram-bot raises telegram.error.NetworkError.

    Configuration

    Operating System: Linux test 4.14.30-v7+ #1102 SMP Mon Mar 26 16:45:49 BST 2018 armv7l GNU/Linux Raspbian GNU/Linux 9 (stretch)

    Version of Python, python-telegram-bot & dependencies: python-telegram-bot 10.0.2 certifi 2018.01.18 future 0.16.0 urllib3 1.22 PySocks 1.6.8 Python 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516]

    Logs

    Output of the code:

    {"ok":true,"result":{"id":584331883,"is_bot":true,"first_name":"Test","username":"TestSocksBot"}}
    Traceback (most recent call last):
      File "/usr/lib/test/test.py", line 33, in <module>
    	print str(bot.get_me().id)
      File "/usr/local/lib/python2.7/dist-packages/telegram/bot.py", line 60, in decorator
    	result = func(self, *args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/telegram/bot.py", line 191, in get_me
    	result = self._request.get(url, timeout=timeout)
      File "/usr/local/lib/python2.7/dist-packages/telegram/utils/request.py", line 245, in get
    	result = self._request_wrapper('GET', url, **urlopen_kwargs)
      File "/usr/local/lib/python2.7/dist-packages/telegram/utils/request.py", line 201, in _request_wrapper
    	raise NetworkError('urllib3 HTTPError {0}'.format(error))
    telegram.error.NetworkError: urllib3 HTTPError SOCKSHTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot<your_api_token>/getMe (Caused by NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x7624d7f0>: Failed to establish a new connection: 0x02: Connection not allowed by ruleset',))
    
    bug :bug: 
    opened by maxgrechnev 31
  • Bot stops responding after network fluctuation

    Bot stops responding after network fluctuation

    Steps to reproduce

    1. Start the bot as usual and commands sent from telegram work.

    2. Reboot the modem (internet goes down) and wait for internet to work again (internet goes up again after some time).

    3. Send some command to the bot.

    Expected behaviour

    Commands sent should work after internet goes up again.

    Actual behaviour

    Commands won't work after internet is up again and are totally ignored by bot.

    Configuration

    Operating System: Raspbian Jessie on Raspberry Pi 2 B

    output of uname -a: Linux raspberrypi 4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016 armv7l GNU/Linux

    Version of Python, python-telegram-bot & dependencies:

    python-telegram-bot 5.3.0 urllib3 1.20 certifi 2017.01.23 future 0.16.0 Python 2.7.9 (default, Sep 17 2016, 20:26:04) [GCC 4.9.2]

    Logs

    2017-01-29 20:10:36,943 - JobQueue - DEBUG - JobQueue thread started 2017-01-29 20:10:36,947 - telegram.ext.updater - DEBUG - dispatcher - started 2017-01-29 20:10:36,953 - telegram.ext.updater - DEBUG - updater - started 2017-01-29 20:10:36,954 - telegram.ext.updater - DEBUG - Updater thread started 2017-01-29 20:10:36,954 - telegram.bot - DEBUG - Entering: setWebhook 2017-01-29 20:10:36,961 - telegram.ext.dispatcher - DEBUG - Dispatcher started 2017-01-29 20:10:43,864 - telegram.bot - DEBUG - True 2017-01-29 20:10:43,865 - telegram.bot - DEBUG - Exiting: setWebhook 2017-01-29 20:10:43,866 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:10:51,350 - telegram.bot - DEBUG - Getting updates: [642177351] 2017-01-29 20:10:51,352 - telegram.bot - DEBUG - [<telegram.update.Update object at 0x760a5110>] 2017-01-29 20:10:51,353 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:10:51,354 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:10:51,384 - telegram.ext.dispatcher - DEBUG - Processing Update: {'message': {'migrate_to_chat_id': 0, 'delete_chat_photo': False, 'new_chat_photo': [], 'entities': [{'length': 9, 'type': u'bot_command', 'offset': 0}], 'text': u'/snapshot', 'migrate_from_chat_id': 0, 'channel_chat_created': False, 'from': {'username': u'Ritiek', 'first_name': u'Ritiek', 'last_name': u'Malhotra', 'type': '', 'id': 329187815}, 'supergroup_chat_created': False, 'chat': {'username': u'Ritiek', 'first_name': u'Ritiek', 'all_members_are_admins': False, 'title': '', 'last_name': u'Malhotra', 'type': u'private', 'id': 329187815}, 'photo': [], 'date': 1485700851, 'group_chat_created': False, 'caption': '', 'message_id': 728, 'new_chat_title': ''}, 'update_id': 642177351}

    (i send command now)

    2017-01-29 20:10:51,385 - telegram.bot - DEBUG - Entering: sendChatAction 2017-01-29 20:10:53,243 - telegram.bot - DEBUG - True 2017-01-29 20:10:53,244 - telegram.bot - DEBUG - Exiting: sendChatAction 2017-01-29 20:10:53,284 - requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): localhost 2017-01-29 20:10:53,290 - requests.packages.urllib3.connectionpool - DEBUG - "GET /0/action/snapshot HTTP/1.1" 200 None 2017-01-29 20:10:53,447 - telegram.bot - DEBUG - Entering: sendPhoto 2017-01-29 20:10:54,752 - telegram.bot - DEBUG - {'migrate_to_chat_id': 0, 'delete_chat_photo': False, 'new_chat_photo': [], 'entities': [], 'text': '', 'migrate_from_chat_id': 0, 'channel_chat_created': False, 'from': {'username': u'PersonalPiBot', 'first_name': u'Raspberry Pi', 'last_name': '', 'type': '', 'id': 285030080}, 'supergroup_chat_created': False, 'chat': {'username': u'Ritiek', 'first_name': u'Ritiek', 'all_members_are_admins': False, 'title': '', 'last_name': u'Malhotra', 'type': u'private', 'id': 329187815}, 'photo': [{'width': 90, 'height': 67, 'file_id': 'AgADBQADsacxG6a0cFTxrx6XSJxhJPdKyjIABF6A6kVR2cpsI-gAAgI', 'file_size': 745}, {'width': 320, 'height': 240, 'file_id': 'AgADBQADsacxG6a0cFTxrx6XSJxhJPdKyjIABALoKINajKI-JOgAAgI', 'file_size': 7484}, {'width': 640, 'height': 480, 'file_id': 'AgADBQADsacxG6a0cFTxrx6XSJxhJPdKyjIABdTFtlGmu00l6AACAg', 'file_size': 15483}], 'date': 1485700854, 'group_chat_created': False, 'caption': '', 'message_id': 729, 'new_chat_title': ''} 2017-01-29 20:10:54,755 - telegram.bot - DEBUG - Exiting: sendPhoto 2017-01-29 20:11:01,803 - telegram.bot - DEBUG - No new updates found. 2017-01-29 20:11:01,804 - telegram.bot - DEBUG - [] 2017-01-29 20:11:01,805 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:11:01,806 - telegram.bot - DEBUG - Entering: getUpdates

    (i reboot my modem here)

    2017-01-29 20:11:16,840 - telegram.ext.updater - ERROR - Error while getting Updates: Timed out 2017-01-29 20:11:16,891 - telegram.ext.dispatcher - DEBUG - Processing Update: Timed out 2017-01-29 20:11:17,842 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:11:37,868 - urllib3.connectionpool - WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x760a53d0>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /bot285030xxx:xxx2tuY0lzjxwP_FGgNebD9L_Wuc_R0Hipo/getUpdates 2017-01-29 20:11:57,889 - urllib3.connectionpool - WARNING - Retrying (Retry(total=1, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x760a5530>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /bot285030xxx:xxx2tuY0lzjxwP_FGgNebD9L_Wuc_R0Hipo/getUpdates 2017-01-29 20:12:17,911 - urllib3.connectionpool - WARNING - Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x76085110>: Failed to establish a new connection: [Errno -2] Name or service not known',)': /bot285030xxx:xxx2tuY0lzjxwP_FGgNebD9L_Wuc_R0Hipo/getUpdates 2017-01-29 20:12:31,098 - telegram.bot - DEBUG - No new updates found. 2017-01-29 20:12:31,099 - telegram.bot - DEBUG - [] 2017-01-29 20:12:31,100 - telegram.bot - DEBUG - Exiting: getUpdates

    (my modem is up again and i send another command now)

    2017-01-29 20:12:31,101 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:12:34,704 - telegram.bot - DEBUG - Getting updates: [642177352] 2017-01-29 20:12:34,706 - telegram.bot - DEBUG - [<telegram.update.Update object at 0x760a57b0>] 2017-01-29 20:12:34,707 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:12:34,708 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:12:34,741 - telegram.ext.dispatcher - DEBUG - Processing Update: {'message': {'migrate_to_chat_id': 0, 'delete_chat_photo': False, 'new_chat_photo': [], 'entities': [{'length': 9, 'type': u'bot_command', 'offset': 0}], 'text': u'/snapshot', 'migrate_from_chat_id': 0, 'channel_chat_created': False, 'from': {'username': u'Ritiek', 'first_name': u'Ritiek', 'last_name': u'Malhotra', 'type': '', 'id': 329187815}, 'supergroup_chat_created': False, 'chat': {'username': u'Ritiek', 'first_name': u'Ritiek', 'all_members_are_admins': False, 'title': '', 'last_name': u'Malhotra', 'type': u'private', 'id': 329187815}, 'photo': [], 'date': 1485700954, 'group_chat_created': False, 'caption': '', 'message_id': 730, 'new_chat_title': ''}, 'update_id': 642177352} 2017-01-29 20:12:34,742 - telegram.bot - DEBUG - Entering: sendChatAction 2017-01-29 20:12:45,013 - telegram.bot - DEBUG - No new updates found. 2017-01-29 20:12:45,014 - telegram.bot - DEBUG - [] 2017-01-29 20:12:45,015 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:12:45,016 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:12:50,452 - telegram.bot - DEBUG - Getting updates: [642177353] 2017-01-29 20:12:50,454 - telegram.bot - DEBUG - [<telegram.update.Update object at 0x76c23d90>] 2017-01-29 20:12:50,455 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:12:50,456 - telegram.bot - DEBUG - Entering: getUpdates 2017-01-29 20:13:00,773 - telegram.bot - DEBUG - No new updates found. 2017-01-29 20:13:00,775 - telegram.bot - DEBUG - [] 2017-01-29 20:13:00,776 - telegram.bot - DEBUG - Exiting: getUpdates 2017-01-29 20:13:00,777 - telegram.bot - DEBUG - Entering: getUpdates

    bug :bug: pending reply 
    opened by ritiek 27
  • [QUESTION] raise InvalidToken()telegram.error.InvalidToken: Invalid token

    [QUESTION] raise InvalidToken()telegram.error.InvalidToken: Invalid token

    I'm using a local bot api running with --local, but I can't download anything

    Steps to reproduce

    1. Use self-host bot api, with --local.

    2. Get any file via

    image_file = context.bot.get_file(file_id)
    image_file.download(imagename) 
    

    from telegram server. (Sent by user in my case.)

    Expected behaviour

    It was supposed to download the media, which in this case is a photo

    Actual behaviour

    The API simply cannot download the media

    Configuration

    Operating System: Ubuntu 20.04.2 LTS Python 3.8 Version of Python, python-telegram-bot & dependencies: PTB 13.4.1

    Logs

    2021-04-17 02:34:35,754 - telegram.ext.dispatcher - ERROR - No error handlers are registered, logging exception.
    Traceback (most recent call last):                                                          
    File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/ext/utils/promise.py", line 79, in run
        self._result = self.pooled_function(*self.args, **self.kwargs)
    File "/home/ubuntu/SmudgePTB13/smudge/modules/searchimage.py", line 60, in reverse
        image_file.download(imagename)
    File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/files/file.py", line 159, in download
        buf = self.bot.request.retrieve(url, timeout=timeout)                                   
    File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/utils/request.py", line 373, in retrieve                                                                               
        return self._request_wrapper('GET', url, **urlopen_kwargs)                              
    File "/home/ubuntu/.local/lib/python3.8/site-packages/telegram/utils/request.py", line 274, in _request_wrapper
        raise InvalidToken()
    telegram.error.InvalidToken: Invalid token
    
    question 
    opened by RenatohRibeiro 24
  • [BUG]How can I make the bot ignore the invalid UTF-8 response?

    [BUG]How can I make the bot ignore the invalid UTF-8 response?

    Steps to reproduce

    1. I think it is a small probability event, so I don't know how to reproduce it.

    Expected behaviour

    Run perfectly.

    Actual behaviour

    Bot raise error.

    2019-11-15 12:50:38,048 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
    2019-11-15 12:50:38,048 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8
    2019-11-15 12:50:39,220 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
    2019-11-15 12:50:39,221 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8
    

    Those error message has been constantly appearing and repeating, causing the program to not work properly.

    And I change the logging module form INFO to DEBUG, the more error details show like this.

    2019-11-15 11:02:44,710 - telegram.ext.dispatcher - DEBUG - Setting singleton dispatcher as <telegram.ext.dispatcher.Dispatcher object at 0x7ff7b973f358>
    2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_submission with t=1573815764.714072
    2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_submission_list_clear with t=1573815764.714721
    2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_table_name with t=1573815764.714840
    2019-11-15 11:02:44,714 - JobQueue - DEBUG - Putting job repeat_table_name_ugly with t=1573815764.714952
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_database_process with t=1573815764.715042
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_repeat_list_delete_one with t=1573815764.715124
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_appreciate_list_delete_one with t=1573815764.715253
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_rest_list_delete_one with t=1573815764.715346
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_sort_by_date_list_delete_one with t=1573815764.715449
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_pic_pool_complete with t=1573815764.715537
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_pic_pool_check with t=1573815764.715622
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_complete with t=1573815764.715753
    2019-11-15 11:02:44,715 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_check with t=1573815764.715847
    2019-11-15 11:02:44,716 - JobQueue - DEBUG - Ticking jobs with t=1573815764.716447
    2019-11-15 11:02:44,716 - JobQueue - DEBUG - JobQueue thread started
    2019-11-15 11:02:44,716 - JobQueue - DEBUG - Peeked at repeat_submission with t=1573815764.714072
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_submission
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_submission with t=1573815770.714072
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_submission_list_clear with t=1573815764.714721
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_submission_list_clear
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_submission_list_clear with t=1573816124.714721
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_table_name with t=1573815764.714840
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_table_name
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_table_name with t=1573815770.714840
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_table_name_ugly with t=1573815764.714952
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_table_name_ugly
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Putting job repeat_table_name_ugly with t=1573815770.714952
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Peeked at repeat_database_process with t=1573815764.715042
    2019-11-15 11:02:44,717 - JobQueue - DEBUG - Running job repeat_database_process
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_database_process with t=1573815767.715042
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_repeat_list_delete_one with t=1573815764.715124
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_repeat_list_delete_one
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_repeat_list_delete_one with t=1573816364.715124
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_appreciate_list_delete_one with t=1573815764.715253
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_appreciate_list_delete_one
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_appreciate_list_delete_one with t=1573815824.715253
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_rest_list_delete_one with t=1573815764.715346
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_rest_list_delete_one
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_rest_list_delete_one with t=1573815824.715346
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Peeked at repeat_sort_by_date_list_delete_one with t=1573815764.715449
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Running job repeat_sort_by_date_list_delete_one
    2019-11-15 11:02:44,718 - JobQueue - DEBUG - Putting job repeat_sort_by_date_list_delete_one with t=1573816364.715449
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_complete with t=1573815764.715537
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_pic_pool_complete
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_pic_pool_complete with t=1573815824.715537
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_check with t=1573815764.715622
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_pic_pool_check
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_pic_pool_check with t=1573815765.715622
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_non_pic_pool_complete with t=1573815764.715753
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_non_pic_pool_complete
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_complete with t=1573815824.715753
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_non_pic_pool_check with t=1573815764.715847
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Running job repeat_non_pic_pool_check
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Putting job repeat_non_pic_pool_check with t=1573815765.715847
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Peeked at repeat_pic_pool_check with t=1573815765.715622
    2019-11-15 11:02:44,719 - JobQueue - DEBUG - Next task isn't due yet. Finished!
    2019-11-15 11:02:44,720 - telegram.ext.updater - DEBUG - dispatcher - started
    2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - updater - started
    2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - Updater thread started (polling)
    2019-11-15 11:02:44,723 - telegram.ext.updater - DEBUG - Start network loop retry bootstrap del webhook
    2019-11-15 11:02:44,724 - telegram.bot - DEBUG - Entering: delete_webhook
    2019-11-15 11:02:44,724 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - Starting new HTTPS connection (1): api.telegram.org
    2019-11-15 11:02:44,787 - telegram.ext.dispatcher - DEBUG - Dispatcher started
    2019-11-15 11:02:45,435 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - https://api.telegram.org:443 "POST /bot627323681:AAHBB-8QBgyu7wPhR_GHIrbbH40YjT5kB2I/deleteWebhook HTTP/1.1" 200 68
    2019-11-15 11:02:45,435 - telegram.bot - DEBUG - True
    2019-11-15 11:02:45,435 - telegram.bot - DEBUG - Exiting: delete_webhook
    2019-11-15 11:02:45,435 - telegram.ext.updater - DEBUG - Bootstrap done
    2019-11-15 11:02:45,435 - telegram.ext.updater - DEBUG - Start network loop retry getting Updates
    2019-11-15 11:02:45,436 - telegram.bot - DEBUG - Entering: get_updates
    2019-11-15 11:02:45,593 - telegram.vendor.ptb_urllib3.urllib3.connectionpool - DEBUG - https://api.telegram.org:443 "POST /bot627323681:AAHBB-8QBgyu7wPhR_GHIrbbH40YjT5kB2I/getUpdates HTTP/1.1" 200 5909
    2019-11-15 11:02:45,593 - telegram.utils.request - DEBUG - Logging raw invalid UTF-8 response:
    b'{"ok":true,"result":[{"update_id":XXXXXXXXX,\n"message":{"message_id":79819,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","last_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573803803,"reply_to_message":{"message_id":79818,"from":{"id":XXXXXXXXX,"is_bot":true,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573803744,"photo":[{"file_id":"XXXXXXXXX","file_size":3620,"width":200,"height":70}],"caption":"XXXXXXXXX","caption_entities":[{"offset":3,"length":4,"type":"text_mention","user":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","last_name":"XXXXXXXXX","username":"XXXXXXXXX"}}],"reply_markup":{"inline_keyboard":[[{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"}],[{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"},{"text":"XXXXXXXXX","callback_data":"XXXXXXXXX"}]]}},"text":"XXXXXXXXX"}},{"update_id":XXXXXXXXX,\n"message":{"message_id":1807,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573804787,"new_chat_participant":{"id":XXXXXXXXX,"is_bot":false,"first_name":" XXXXXXXXX"},"new_chat_member":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"},"new_chat_members":[{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129646,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","language_code":"zh-hans"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573805383,"text":"XXXXXXXXX","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129647,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","language_code":"zh-hans"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573805420,"text":"XXXXXXXXX","entities":[{"offset":0,"length":2,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129648,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810865,"text":"XXXXXXXXX","entities":[{"offset":0,"length":24,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129649,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810886,"text":"XXXXXXXXX","entities":[{"offset":0,"length":24,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129650,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573810890,"text":"XXXXXXXXX","entities":[{"offset":0,"length":17,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":109851,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":XXXXXXXXX,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811048,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":XXXXXXXXX,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":366039180,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811339,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":XXXXXXXXX,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","language_code":"en"},"chat":{"id":XXXXXXXXX,"first_name":"XXXXXXXXX","username":"XXXXXXXXX","type":"private"},"date":1573811393,"text":"XXXXXXXXX","entities":[{"offset":0,"length":12,"type":"bot_command"}]}},{"update_id":XXXXXXXXX,\n"message":{"message_id":129651,"from":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"chat":{"id":-XXXXXXXXX,"title":"XXXXXXXXX","username":"XXXXXXXXX","type":"supergroup"},"date":1573813538,"new_chat_participant":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"new_chat_member":{"id":XXXXXXXXX,"is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"},"new_chat_members":[{"id":XXXXXXXXX,is_bot":false,"first_name":"XXXXXXXXX","username":"XXXXXXXXX"}]}}]}'
    2019-11-15 11:02:45,593 - telegram.ext.updater - ERROR - Error while getting Updates: Server response could not be decoded using UTF-8
    2019-11-15 11:02:45,593 - telegram.ext.dispatcher - DEBUG - Processing Update: Server response could not be decoded using UTF-8
    2019-11-15 11:02:45,594 - xxbot.__main__ - WARNING - Update None caused error Server response could not be decoded using UTF-8
    

    I have replaced some sensitive information with xxxxx.

    Configuration

    Operating System: Linux Debian10-1 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux

    Version of Python, python-telegram-bot & dependencies:

    $ python -m telegram

    Output.

    >>> python3 -m telegram
    python-telegram-bot 11.1.0
    certifi 2018.08.24
    future 0.17.1
    Python 3.7.3 (default, Apr  3 2019, 05:39:12)  [GCC 8.3.0]
    

    So how to make the program ignore this unresolvable data without affecting other processing?

    THX.

    Logs

    Insert logs here (if necessary)

    bug :bug: good first issue 
    opened by rikonaka 24
  • clean pending update based on Timedelta or datetime

    clean pending update based on Timedelta or datetime

    Follow-up of #1978

    Add option to pass a timedelta or datetime as var clean to .start_polling() or .start_webhook(). Updates with a timestamp before now - timedelta will be ignored. Updates before datetime will be ignored.

    I'm not familiar with the test-module to write these from scratch as this is not a 'direct' function to test. Can put in some time if y'all can point me to similar examples?

    Maybe needs some cleanup but need the gh test bot results for that.

    pending review 
    opened by ikkemaniac 22
  • Fix Filters documentation

    Fix Filters documentation

    documentation 
    opened by revolter 22
  • Bot API 2.0

    Bot API 2.0

    Official announcement: https://core.telegram.org/bots/2-0-intro Changelog: https://core.telegram.org/bots/api-changelog

    • [x] New inline keyboards with callback and URL buttons. Added new objects InlineKeyboardMarkup, InlineKeyboardButton and CallbackQuery, added reply_markup fields to all InlineQueryResult objects. Added field callback_query to the Update object, new method answerCallbackQuery.
    • [x] Bots can now edit their messages. Added methods editMessageText, editMessageCaption, editMessageReplyMarkup.
    • [x] Bots can request location and phone number from the user. The keyboard field in the object ReplyKeyboardMarkup now supports KeyboardButton, a new object that can have the fields request_location and request_contact.
    • [x] Added support for all content types available on Telegram. 19 types of InlineQueryResult objects are now supported.
    • [x] Inline bots can now subsitute all kinds of content with text. Added 4 types of InputMessageContent objects.
    • [x] You inline bot can also ask users for permission to use their location. Added the new Botfather command /setinlinegeo, added field location to the InlineQuery object, added fields location and inline_message_id to the ChosenInlineResult object.
    • [x] Added an easy way to switch between inline mode and a private chat with the bot – useful for settings, establishing external connections and teaching users how to use your bot in inline mode. Added parameters switch_pm_text and switch_pm_parameter to the method answerInlineQuery.
    • [x] Added group administration tools. New methods kickChatMember and unbanChatMember.
    • [x] Added fields venue, pinned_message and entities to the Message object. Added new objects MessageEntity and Venue, new methods sendVenue and sendContact.
    • [x] Renamed the fields new_chat_participant and left_chat_participant of the Message object to new_chat_member and left_chat_member.
    enhancement API 
    opened by leandrotoledo 21
  • Add default values

    Add default values

    Supersedes/Closes #1226 and closes #1527

    To meet the requirements stated by @Eldinnie in #1226, I added a new class DefaultValue to the helpers module. It's purpose is to allow to differentiate check if a value is just the default or was set specifically:

    With def f(arg=None) we don't know, if arg is None results from f() or from f(None). With def f(arg=DefaultValue(None), we can handle those differently.

    This makes it necessary to add some stuff to the InlineQueryResult* for bot.answer_inline_query to parse the new default_parse_mode correctly. But it does the job :) Maybe DefaultValue also comes in handy with a future use case … How do the @python-telegram-bot/maintainers feel about this?

    For the tests, I tried and added them for the send_* and edit_message_* methods. I'm still not too familiar with pytest, so please tell if those can be improved. However, I couldn't find a clever way to test the default_parse_mode for answer_inline_query since I'd somehow have to get hold of the resulting message. Any idea is appreciated :)

    enhancement pending review 
    opened by Bibo-Joshi 21
  • Docs improvements: referencing

    Docs improvements: referencing

    • bump sphinx
    • try to render base classes better
    • use sphinx-paramref to make parameters referencable
    • use nitpicky mode for sphinx
    • add new CI task to build the docs

    Checklist for PRs

    • [ ] Added .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
    • [ ] Created new or adapted existing unit tests
    • [ ] Added myself alphabetically to AUTHORS.rst (optional)
    • [ ] Added new classes & modules to the docs

    If the PR contains API changes (otherwise, you can delete this passage)

    • New classes:

      • [ ] Added self._id_attrs and corresponding documentation
      • [ ] __init__ accepts **_kwargs
    • Added new shortcuts:

      • [ ] In Chat & User for all methods that accept chat/user_id
      • [ ] In Message for all methods that accept chat_id and message_id
      • [ ] For new Message shortcuts: Added quote argument if methods accepts reply_to_message_id
      • [ ] In CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id
    • If relevant:

      • [ ] Added new constants at telegram.constants and shortcuts to them as class variables
      • [ ] Added new handlers for new update types
      • [ ] Added new filters for new message (sub)types
      • [ ] Added or updated documentation for the changed class(es) and/or method(s)
      • [ ] Updated the Bot API version number in all places: README.rst and README_RAW.rst (including the badge), as well as telegram.constants.BOT_API_VERSION
      • [ ] Added logic for arbitrary callback data in tg.ext.Bot for new methods that either accept a reply_markup in some form or have a return type that is/contains telegram.Message
    documentation 
    opened by Bibo-Joshi 1
  • [FEATURE]  a conversation class to include all dialogues of a conversation + its handler

    [FEATURE] a conversation class to include all dialogues of a conversation + its handler

    What kind of feature are you missing? Where do you notice a shortcoming of PTB?

    I believe conversation handlers can become a mess very quickly, especially if they are nested. There is a need for some structure where you can gather the handler, functions, and keys of each conversation all in one place, separate from the others.

    Describe the solution you'd like

    For my own use I've created a simple class where I have a handler attribute, keys for the states, and obviously all the related functions. This helps a lot in separating conversations, having loose coupling, and generally being less confused.

    I think it would be a good idea to have something similar in PTB itself. It could also include a class for managing keys to states.

    Describe alternatives you've considered

    No response

    Additional context

    No response

    enhancement pending reply 
    opened by evakdev 1
  • [Discussion:] ConversationHandler

    [Discussion:] ConversationHandler

    Several ideas for changes and/or additions have been gathered in the v14 project, mentioned in the user group or issues or dwelled in the back of my head. So I'm writing this issue to keep track of them better.

    The following list of ideas should be discussed before release of v14 because at least some of them are easier to implement if we do them non-backwards compatible. I'd like to emphasize that most of these are very rough first thoughts and I'm fully aware that we may scrape many of them.


    • Make CH.fallbacks optional. I've seen a lot of people (including me) setting at to an empty list for some use cases … Poolitzer already expressed support for this ideaget_persisted_data(persistence) or initialize_persistence(persistence)
    • ConverstanionHandler + run_async: Problem is that we can't persist futures/promises. But we should be able to guarantee that all futures are done on (clean) shutdown. One could add something like BasePersistence.resolve_conversation_promises that persistence classes can call before flushing on shutdown.
    • #2390
    • add a "prefallbacks" list, i.e. the state-handlers only trigger, if the "prefallback" handlers don't trigger. The current alternative is to add those handlers to the fallbacks list, which requires to make all state handlers ignore updates that should be handled by the fallbacks. see also #2764
    • Include entry_points, fallbacks (and eventual "prefallbacks") into the states dict. We already have special states for TIMEOUT and WAITING, so I think it would make the interface cleaner if we used special states (PRE)FALLBACK and END as keys for these lists rather than making them standalone kwargs of __init__
    • Think about "conversation related data", e.g. context.conversation_data. It should be an object unique per conversation key and ConversationHandler instance. It may even be automatically deleted when the conversation ends
    • Rethink which parts of ConversationHandler we consider public.
      • e.g. the conversations is currently public, although undocumented and basically part of the internals. If we make it private, we can rework the setters of persistence and conversations to something like get_persisted_data(persistence) or initialize_persistence(persistence)
      • We also rather regularly get questions like "how do I access the current state of the conversation" and "how do I check if a user has an active conversation". Making the logic of how the keys are build and how conversations works public may help with some of these and also with the above context.conversation_data
      • One could take this one step further and let the user customize how the key is generated. This could be useful e.g. in situations where one wants to handle 3rd-party updates (e.g. login into an external service) within the conversation, which are not of type telegram.Update
    • think about conversation_timeout:
      • Is it worth to allow timeout handlers to put the conversation in a non-end state?
      • it it worth to try & allow a different timeout duration per state?
    opened by Bibo-Joshi 0
  • Added impementation of

    Added impementation of "prefallbacks" list.

    Imagine you have such CH:

    ch = tg_ext.ConversationHandler(
        entry_points=[
            tg_ext.CommandHandler("start", callback=lambda *args, **kwargs: 0)],
    
        states={
            0: [
                tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                      callback=lambda *args, **kwargs: 1)],
    
            1: [
                tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                      callback=lambda *args, **kwargs: 2)],
    
            2: [
                tg_ext.MessageHandler(filters=tg_ext.Filters.text & ~Filters.regex("cancel"), 
                                      callback=lambda *args, **kwargs: -1)],
        },
        fallbacks=[
            tg_ext.CommandHandler("cancel", callback=lambda *args, **kwargs: -1),
        ])
    

    Here you should apply & ~Filter for every handler in states to prevent catching a cancel command. But it can be easily avoided by adding list of handlers that should to trigger before any another update.

    Checklist for PRs

    • [ ] Added .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
    • [ ] Created new or adapted existing unit tests
    • [ ] Added myself alphabetically to AUTHORS.rst (optional)

    If the PR contains API changes (otherwise, you can delete this passage)

    • New classes:

      • [ ] Added self._id_attrs and corresponding documentation
      • [ ] __init__ accepts **_kwargs
    • Added new shortcuts:

      • [ ] In Chat & User for all methods that accept chat/user_id
      • [ ] In Message for all methods that accept chat_id and message_id
      • [ ] For new Message shortcuts: Added quote argument if methods accepts reply_to_message_id
      • [ ] In CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id
    • If relevant:

      • [ ] Added new constants at telegram.constants and shortcuts to them as class variables
      • [ ] Added new handlers for new update types
      • [ ] Added new filters for new message (sub)types
      • [ ] Added or updated documentation for the changed class(es) and/or method(s)
      • [ ] Updated the Bot API version number in all places: README.rst and README_RAW.rst (including the badge), as well as telegram.constants.BOT_API_VERSION
      • [ ] Added logic for arbitrary callback data in tg.ext.Bot for new methods that either accept a reply_markup in some form or have a return type that is/contains telegram.Message
    Do not merge (yet) 
    opened by david-shiko 3
  • [DISCUSSION] Adding public submodules to `__all__`

    [DISCUSSION] Adding public submodules to `__all__`

    What kind of feature are you missing? Where do you notice a shortcoming of PTB?

    Currently, in the v14 branch we for e.g do: from telegram import error. But if a user does from telegram import *, it does not import the public submodule error, when it should.

    PEP-8 says that documented interfaces are considered public and "To better support introspection, modules should explicitly declare the names in their public API using the __all__ attribute.".

    Additionally, PEP-8 also says that __all__ should be placed above the imports.

    Describe the solution you'd like

    Import and add public submodules to __all__, place __all__ above imports.

    Additional context

    Original discussion: https://github.com/python-telegram-bot/python-telegram-bot/pull/2759#discussion_r740045558

    enhancement 
    opened by harshil21 0
  • [BUG] ptb hardpins dependencies, causing problems for sub-dependencies

    [BUG] ptb hardpins dependencies, causing problems for sub-dependencies

    Steps to Reproduce

    Create a project with ptb and cachetools (for example) in requirements

    requirements.txt

    python-telegram-bot==13.7
    cachetools==4.2.4
    

    install that project

    pip install -r requirements.txt

    Collecting cachetools==4.2.4
      Downloading cachetools-4.2.4-py3-none-any.whl (10 kB)
    ERROR: Cannot install cachetools==4.2.4 and python-telegram-bot==13.7 because these package versions have conflicting dependencies.
    

    The proposed workaround from https://github.com/python-telegram-bot/python-telegram-bot/pull/2757#issuecomment-955209372 does NOT work with uptodate pip versions, and fails with the following approach.

    pip install cachetools==4.2.4 -U
    Collecting cachetools==4.2.4
      Using cached cachetools-4.2.4-py3-none-any.whl (10 kB)
    Installing collected packages: cachetools
      Attempting uninstall: cachetools
        Found existing installation: cachetools 4.2.2
        Uninstalling cachetools-4.2.2:
          Successfully uninstalled cachetools-4.2.2
    ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
    python-telegram-bot 13.7 requires cachetools==4.2.2, but you have cachetools 4.2.4 which is incompatible.
    

    Expected behaviour

    Installation would not fail.

    A library should not hard-pin install-dependencies (in setup.py) but instead use range-pinning.

    Hard-pinned dependencies should only be used in requirements.txt - but not in setup.py - preventing other projects from updating. to avoid unexpected failures, it's best-practice to range-pin dependencies, preventing major updates without proper testing, which ptb fails to do.

    Actual behaviour

    Installation fails

    Operating System

    not relevant uptodate pip version

    other

    I've attempted a fix in #2757 - but one of the maintainers decided to rather try and discuss the issue away than fixing this, therefore i'm now asking this as issue, and i consider this a breaking bug (it breaks updates of dependent modules).

    I'd expect a fix for this for both 13.x (minor version update) and 14.0 versions - as this can have security implications (you're preventing updating to a more uptodate version).

    bug :bug: 
    opened by xmatthias 0
  • [BUG] Previous data is reloaded after using persistence.update_user_data

    [BUG] Previous data is reloaded after using persistence.update_user_data

    Steps to Reproduce

    persistence = PicklePersistence('my_file', store_user_data=True, store_chat_data=True, store_bot_data=True, on_flush=False) After running persistence.update_user_data(update.message.from_user.id, user_data), the previous user_data is restored, thus having no effect on the persistence and making it unusable

    Expected behaviour

    self.user_data should be saved after running persistence.update_user_data without restoring the previous data

    Actual behaviour

    After running persistence.update_user_data , dispatcher is calling __update_persistence. on line 729, the code runs over the new saved data with the old saved data: self.persistence.update_user_data(user_id, self.user_data[user_id]),

    Operating System

    Windows

    Version of Python, python-telegram-bot & dependencies

    Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
    
    python-telegram-bot 13.7
    Bot API 5.3
    certifi 2020.12.05
    Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
    

    Relevant log output

    No response

    Additional Context

    No response

    bug :bug: 
    opened by Noam5 3
  • Update _message.py - issue #2606

    Update _message.py - issue #2606

    closes #2606

    Checklist for PR

    • [x] modified message.photo = None instead of an empty list []
    • [ ] Added .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
    • [x] Created new or adapted existing unit tests
    • [ ] Added myself alphabetically to AUTHORS.rst (optional)
    bug :bug: pending reply 
    opened by nivramam 15
  • [FEATURE] Purge persistent chat_data from empty entries

    [FEATURE] Purge persistent chat_data from empty entries

    What kind of feature are you missing? Where do you notice a shortcoming of PTB?

    When using persistent chat_data, there's no method for purging entries which have been emptied. The chat_id key will always remain in the chat_data defaultdict. I believe it's the same for user_data.

    Because of the Dispatcher.__update_persistence() implementation, even deleting the keys with del chat_data[k] won't remove them from the persistence file. See: https://github.com/python-telegram-bot/python-telegram-bot/blob/bc7c422a11a60a3064601aac3fd5a26fd9b45ae9/telegram/ext/dispatcher.py#L665-L669

    Describe the solution you'd like

    • Add a method to the Dispatcher class for removing a key from the persistence file, with the key as parameter. It should not matter to the method whether the related value is empty or not.
    • Add another method for purging all orphaned keys from the persistence file.

    There probably should be 4 methods, 2 for chat_data and 2 for user_data.

    Describe alternatives you've considered

    No response

    Additional context

    No response

    enhancement 
    opened by ria4 5
  • Not even WIP: Asyncio

    Not even WIP: Asyncio

    Supersedes #2402. Closes #2288 when ready - which is not in the forseable future :D

    • ext-tests are deleted for now so that we can first concentrate on getting telegram to work
    • any changes to v14 should be merged into this ASAP

    TODO

    Let's use this as place to write everything down that comes to mind while working on this - will be a lot

    • [ ] Add .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings
    • [x] move PtbRequestBase and HttpxRequest to a tg.request module/package. Maybe rename to RequestBase and HTTPXRequest
    • [x] Improve handling of files in request - probably move that logic into a standalone method or even into Bot?
    • [ ] Also manually check whether thumbs are properly handled everywhere(!) where you can pass a thumb
    • [x] Update error code handling in request, use the enum from the std-lib
    • [ ] Discuss if we need both of Request.{retrieve, download}. IIRC download is used nowhere.
    • [x] Check if we get coroutine was never awaited somewhere in the tests and also check if we can make those warnings fail the tests
    • [ ] Some test_slots_behavior tests went missing for some reason. check the diff and re-add them
    • [ ] Check if it's worth to use https://colin-b.github.io/pytest_httpx/
    • [ ] check back with noam on whether the timeout parameter should be used for write_timeout as well in in BaseRequest
    • [ ] Check back with Noam about httpx connection pool limits: IISC on pool_timeout we want to create a new connection instead of dropping the request?!

    Review

    Thinks to look out for in a review

    • [ ] double check if we need to update docs regarding accepted types
    • [ ] Check for unwanted changes (also in tests!) - these are likely to be there because merging v14 was a mess
    enhancement refactor :gear: breaking :boom: 
    opened by Bibo-Joshi 0
Releases(v13.8.1)
Python linting made easy. Also a casual yet honorific way to address individuals who have entered an organization prior to you.

pysen What is pysen? pysen aims to provide a unified platform to configure and run day-to-day development tools. We envision the following scenarios i

Preferred Networks, Inc. 392 Nov 27, 2021
A discord bot wrapper for python have slash command

A discord bot wrapper for python have slash command

null 2 Nov 24, 2021
❤️ Hi There Im EzilaX ❤️ A next gen powerful telegram group manager bot 😱 for manage your groups and have fun with other cool modules Made By Sadew Jayasekara 🔥

❤️ EzilaX v1 ❤️ Unmaintained. The new repo of @EzilaXBot is Public. (It is no longer based on this source code. The completely rewritten bot available

Sadew Jayasekara 19 Nov 8, 2021
aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

aws-lambda-scheduler aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future. This functionality is achieved by dyn

Oğuzhan Yılmaz 59 Nov 17, 2021
If you only have hash, you can still operate exchange

PTH Exchange If you only have hash, you can still operate exchange This project module is the same as my other project Exchange_SSRF, This project use

Jumbo 27 Nov 23, 2021
🚀 An asynchronous python API wrapper meant to replace discord.py - Snappy discord api wrapper written with aiohttp & websockets

Pincer An asynchronous python API wrapper meant to replace discord.py ❗ The package is currently within the planning phase ?? Links |Join the discord

Pincer 77 Dec 1, 2021
A wrapper for slurm especially on Taiwania2 (HPC CLI)A wrapper for slurm especially on Taiwania2 (HPC CLI)

TWCC-slurm-wrapper A wrapper for slurm especially on Taiwania2 (HPC CLI). For Taiwania2 (HPC CLI) usage, please refer to here. (中文) How to Install? gi

Chi-Liang, Liu 2 Nov 4, 2021
Techie Sneh 17 Nov 23, 2021
Discord Panel is an AIO panel for Discord that aims to have all the needed tools related to user token interactions, as in nuking and also everything you could possibly need for raids

Discord Panel Discord Panel is an AIO panel for Discord that aims to have all the needed tools related to user token interactions, as in nuking and al

null 9 Nov 28, 2021
A python Discord wrapper made in well, python.

discord.why A python Discord wrapper made in well, python. Made to be used by devs who want something a bit more, general. Basic Examples Sending a me

HellSec 5 Nov 13, 2021
just a program i made cuz a friend got tokenlogged and spammed me with these scam/phishing links so i made a programm to spam these websides with fake logins

scam-webside-spammer just a program i made cuz a friend got tokenlogged and spammed me with these scam/phishing links so i made a programm to spam the

TerrificTable 3 Nov 19, 2021
Discord Auto bumper made in python, just a simple auto bumper that I made.

Discord Auto bumper made in python, just a simple auto bumper that I made.

XPTGR 9 Nov 30, 2021
A custom Discord Rich Presence to display when you're studying so you're stupid friends won't disturb you when you're studying.

Studying RPC Description A custom Discord Rich Presence to display when you're studying so you're stupid friends won't disturb you when you're studyin

John Edmerson Pizarra 2 Nov 9, 2021
❤️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. ☆ Video by Sadew Jayas

Pawan Theekshana 6 Nov 8, 2021
Confirm that files have been uploaded to Backblaze Cloud Backup successfully

Backblaze Backup Checker This Python script compares metadata captured from files within source folders against data parsed from Backblaze Cloud Backu

null 16 Oct 10, 2021
Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Amanda-A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules.

Team Amanda 1 Oct 19, 2021
RevSpotify is a fast, useful telegram bot to have Spotify music on Telegram.

RevSpotify A Telegram Bot that can download music from Spotify RevSpotify is a fast, useful telegram bot to have Spotify music on Telegram. ✨ Features

Alireza Shabani 3 Nov 23, 2021
A discord bot to check if messages have the correct code formatting.

discord-code-formatter A discord bot to check if messages have the correct code formatting. This was a basic project to help me learn Python and learn

Nash Boisvert 1 Nov 23, 2021