Community-based extensions for the python-telegram-bot library.

Overview
ptbcontrib Logo

Community-based extensions for the python-telegram-bot library.

Supported Python versions LGPLv3 License Github Actions workflow Median time to resolve an issue Code quality Telegram Group IRC Bridge

Table of contents

Introduction

This library provides extensions for the python-telegram-bot library written and maintained by the community of PTB users.

Installing

Because this library is subject to more frequent changes than PTB, it is not available via PyPi. You can still install it via pip:

$ pip install git+https://github.com/python-telegram-bot/ptbcontrib.git

If you want to use an extension that has some special requirements, you can install them on the fly as e.g.

$ pip install "ptbcontrib[extension1,extension2] @ git+https://github.com/python-telegram-bot/ptbcontrib.git"

Or you can install from source with:

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

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.

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.

Comments
  • [FEATURE] Forward message as copy

    [FEATURE] Forward message as copy

    Hello again! In Pyrogram there's a nice feature that helps with some tasks like editing posts before publications: https://docs.pyrogram.org/api/bound-methods/Message.forward https://github.com/pyrogram/pyrogram/blob/develop/pyrogram/client/methods/messages/forward_messages.py

    It just get the whole message and resends it as if it's written by bot, without a forwarding header.I have a solution in rather ugly manner, but it's not good with photo albums (many pics with caption viewed as single message in the client) cause it force 'em to be send as many single photo-messages not a whole one.

     
        def determine_msg_type_then_send( ... , msg, ... ): 
            if msg.photo:   
                ...
                send_a_photo_function( <someargs> ) 
            elif msg.document:  
                ...
                send_a_document_function( <someargs> ) 
            elif msg.sticker:  
                ...
                send_a_sticker_function( <someargs> )  
            ...
            else:  
                ... 
                send_a_message_function( <someargs> ) 
     
    
    
    enhancement 
    opened by moonbaseDelta 14
  • added chat_to_link

    added chat_to_link

    I still haven't added tests and completed the README. I'll fix those when the code is complete. If you think of a better name than chat_to_link and get_chat_link, kindly suggest it.

    opened by allerter 8
  • Roles

    Roles

    Reworking of ptb/#1789 for ptbcontrib.

    Currently will fail, as the persistence setup needs ptb/#2212 to be fixed (hence marking as WIP)

    On the fly edits some stuff in conftest.py allowing to actually run the tests. Overlooked that on the initial repo setup b/c extract_urls doesn't use dispatcher/bot

    enhancement 
    opened by Bibo-Joshi 7
  • [FEATURE] allow chat link for private groups/channels

    [FEATURE] allow chat link for private groups/channels

    Right now, chat.link only returns the username in a link form. We could also return the chat_link there if it exists, or potentially (with a flag?) go even further and call export link and then return the link.

    Might also be a nice fit for the contrib repo if this feature is a bit over the top.

    enhancement 
    opened by Poolitzer 6
  • [QUESTION] ptb_sqlalchemy_jobstore ptb>20

    [QUESTION] ptb_sqlalchemy_jobstore ptb>20

    Module this question is about

    ptb_sqlalchemy_jobstore

    Issue I am facing

    How do I adapt this for python-telegram-bot 20.0a4?

    And if so, how should I change the code:

    updater = Updater("TOKEN")
    dispatcher = updater.dispatcher
    dispatcher.job_queue.scheduler.add_jobstore(
       PTBSQLAlchemyJobStore(
           dispatcher=dispatcher, url=DB_URI,
        ),
    )
    

    Traceback to the issue

    Traceback (most recent call last):
      File "E:\YandexDisk\github\namaz_bot\main.py", line 26, in <module>
        from ptbcontrib.ptb_sqlalchemy_jobstore import PTBSQLAlchemyJobStore
      File "E:\YandexDisk\github\namaz_bot\venv\lib\site-packages\ptbcontrib\ptb_sqlalchemy_jobstore\__init__.py", line 18, in <module>
        from .jobstore import PTBSQLAlchemyJobStore
      File "E:\YandexDisk\github\namaz_bot\venv\lib\site-packages\ptbcontrib\ptb_sqlalchemy_jobstore\jobstore.py", line 27, in <module>
        from telegram.ext import CallbackContext, Dispatcher
    ImportError: cannot import name 'Dispatcher' from 'telegram.ext' (E:\YandexDisk\github\namaz_bot\venv\lib\site-packages\telegram\ext\__init__.py)
    

    Related part of your code

    Python 3.9, python-telegram-bot==20.0a4
    
    enhancement 
    opened by jekeam 5
  • Update Prostgres Persistence

    Update Prostgres Persistence

    I started out with just updating to v20, but ended up also

    • refactoring the internals to better leverage the parent class DictPersistence and
    • adding support for callback_data

    Unfortunately I'm not familiar for postgres (& databases in general), so I didn't try to actually test this with a real database (instead of just mocking as in the tests). If would be great if someone could cover that part :) CCing @starry69 for completeness 🙆‍♂️

    It's not necessary that this is merged into v20-updates before #47 is merged. Just chose that as target branch so that the differences to main are more clearly visible.

    opened by Bibo-Joshi 5
  • V20 updates

    V20 updates

    so far:

    • ReplyToMessageFilter
    • get_chat_link
    • send_by_kwargs (also closes #39)
    • roles - here I removed the Roles.chat_admins/owner thingies, which made api requests in the check_update (rather: filter) step. Don't know why I even thought that were a good idea …

    Based on #46. Selected that branch as target so that it's easier to see the changes. Should be merged into baster once #46 is merged.

    opened by Bibo-Joshi 5
  • Improve PostgresSQL Persistence class

    Improve PostgresSQL Persistence class

    • Added url parameter, now it's not necessary to manually build scoped session. though it can still be passed instead or url if needed.
    • Added on_flush parameter when set True persistence will only save data on shutdown else it'll update the database on every update.
    • Improved data saving query now it'll update the existing data in table instead of deleting and adding new data.
    opened by starry69 5
  • [QUESTION] Getting the user ID

    [QUESTION] Getting the user ID

    Hi @Poolitzer,

    @harshil21 recently suggested me UsernameToChatAPI solution.

    I tried to use example with the telegram public api like presented below however get error:

    wrapper = UsernameToChatAPI("https://api.telegram.org/", "AnimusBoom", bot)
    
    try:
        chat = wrapper.resolve("@julien59247787")
        print("Found")
    except error.RetryAfter as e:
        time.sleep(e.retry_after)
        # both variants work
        chat = wrapper.resolve("julien59247787")
        print("found 2")
    
    chat = wrapper.resolve("@julien59247787")
    raise error.TelegramError(result["description"])
    telegram.error.TelegramError: Not Found
    

    Could you give me please some hints on what could be the issues?

    Thank you for your time and answer

    Animus

    question stale 
    opened by AnimusXCASH 4
  • Improve tests

    Improve tests

    Currently we install extra-requirements of contributions during runtime in the tests, which has culprits (see https://github.com/python-telegram-bot/ptbcontrib/pull/27#issuecomment-904366995).

    I suggest to instead run pytest several times and tell it to just consider one specific file each time. We probably could try to make each of that a standalone workflow, but this gives (number of python versions) × (number of contributions) suits and this seems a waste of resources to me. We can maybe write a simple script (bash? python?) that iterates over the contributions & calls pytest. Then we can run that script in the GH workflow and even locally as well.

    enhancement 
    opened by Bibo-Joshi 4
  • [Feature] create chat link for private groups/channels

    [Feature] create chat link for private groups/channels

    This feature should introduce a give_me_a_link_to_the_chat_no_matter_what(chat: Chat) -> str function. This means, it should check if a username exists and then return it like chat.link does. If the chat doesnt have a username and is a group/channel, check if the bot is an admin with add member rights (I think this is required), then check if get_chat returns a link. If not, export a new one. Then return the invite link. And definitely document that calling this might result in three API calls

    enhancement 
    opened by Poolitzer 3
  • Support for PTB ~v20.0

    Support for PTB ~v20.0

    Now that v20.0 is out, we can update the requirements files to be a bit more permissive by specifying e.g. ~=20.0. Contrubtions that were already updated to one of the pre-release versions should be rather easy to update to v20.0 as few breaking changes have happend since then. A PR in this direction would be welcome and would probably only have to update the requirements.txt files as well as the README.md files.

    opened by Bibo-Joshi 0
  • [FEATURE] Support MySQL in  PTB_sqlalchemy_persistence

    [FEATURE] Support MySQL in PTB_sqlalchemy_persistence

    PTB_sqlalchemy_persistence

    Because other data in the project is already stored in mysql i've tried to adapt the code for using mysql instead of postgres. (And never run postgres myself, maybe this is already the source of the bug.)

    Steps to reproduce

    1. Altering the test for postgres-uri in line 71.
    2. Use sqlalchemy-scoped-session bound to a mysql-database.
    3. start the updater

    Actual behaviour

    File "persistence.py", line 108, in __load_database: self._chat_data = defaultdict(dict, self._key_mapper(data.get("chat_data", {}), int)) AttributeError: 'str' object has no attribute 'get'

    For some reasons 'data' is of type 'str'. ("{}" after calling __init_database())

    Solution

    adding two lines of code at 105:

    if isinstance(data, str):
        data = json.loads(data)
    

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

    $ python -m telegram python-telegram-bot 13.11 Bot API 5.7 certifi 2021.10.08 Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]

    mysql 8.0 sqlalchemy 1.4.27 conda 4.11.0 Windows 11

    I thought somebody could find this interessting. Apart from this minor fix could this module named more general.

    enhancement 
    opened by kolja-wagner 2
  • [BUG] PTBSQLAlchemyJobStore can't handle conversation timeout jobs

    [BUG] PTBSQLAlchemyJobStore can't handle conversation timeout jobs

    Module in question: ptb_sqlalchemy_jobstore

    Steps to reproduce

    1. Create a ConversationHandler with conversation_timeout set to any supported value other than None.

    2. Add PTBSQLAlchemyJobStore to dispatcher.job_queue.scheduler .

    3. Start the bot.

    4. Enter ConversationHandler created in step 1.

    Expected behaviour

    Conversation Timeout job should be added to job store.

    Actual behaviour

    Job cannot be stored due to serialisation error.

    Configuration

    MacOs 12.0.1, python 3.9.7

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

    python-telegram-bot 13.8.1
    Bot API 5.4
    certifi 2021.10.08
    Python 3.9.7 (default, Oct 22 2021, 13:39:39)  [Clang 13.0.0 (clang-1300.0.29.3)]
    ptbcontrib 0.0.0
    

    Logs

    Traceback (most recent call last):
      File "venv/lib/python3.9/site-packages/telegram/ext/conversationhandler.py", line 497, in _schedule_job
        self.timeout_jobs[conversation_key] = j_queue.run_once(  # type: ignore[union-attr]
      File "venv/lib/python3.9/site-packages/telegram/ext/jobqueue.py", line 196, in run_once
        j = self.scheduler.add_job(
      File "venv/lib/python3.9/site-packages/apscheduler/schedulers/base.py", line 444, in add_job
        self._real_add_job(job, jobstore, replace_existing)
      File "venv/lib/python3.9/site-packages/apscheduler/schedulers/base.py", line 868, in _real_add_job
        store.add_job(job)
      File "venv/lib/python3.9/site-packages/ptbcontrib-0.0.0-py3.9.egg/ptbcontrib/ptb_sqlalchemy_jobstore/jobstore.py", line 65, in add_job
        super().add_job(job)
      File "venv/lib/python3.9/site-packages/apscheduler/jobstores/sqlalchemy.py", line 95, in add_job
        'job_state': pickle.dumps(job.__getstate__(), self.pickle_protocol)
    TypeError: cannot pickle '_thread.lock' object
    2021-11-11 23:15:26,089 - cannot pickle '_thread.lock' object
    Traceback (most recent call last):
      File "venv/lib/python3.9/site-packages/telegram/ext/conversationhandler.py", line 497, in _schedule_job
        self.timeout_jobs[conversation_key] = j_queue.run_once(  # type: ignore[union-attr]
      File "venv/lib/python3.9/site-packages/telegram/ext/jobqueue.py", line 196, in run_once
        j = self.scheduler.add_job(
      File "venv/lib/python3.9/site-packages/apscheduler/schedulers/base.py", line 444, in add_job
        self._real_add_job(job, jobstore, replace_existing)
      File "venv/lib/python3.9/site-packages/apscheduler/schedulers/base.py", line 868, in _real_add_job
        store.add_job(job)
      File "venv/lib/python3.9/site-packages/ptbcontrib-0.0.0-py3.9.egg/ptbcontrib/ptb_sqlalchemy_jobstore/jobstore.py", line 65, in add_job
        super().add_job(job)
      File "venv/lib/python3.9/site-packages/apscheduler/jobstores/sqlalchemy.py", line 95, in add_job
        'job_state': pickle.dumps(job.__getstate__(), self.pickle_protocol)
    TypeError: cannot pickle '_thread.lock' object
    
    bug :bug: 
    opened by l0rem 1
  • Adding versioning through CI

    Adding versioning through CI

    This idea came up in a discussion group, https://t.me/c/1101839433/8235. One can increase the major version every time a new module is added, and a minor increase if a module gets updated.

    The benefit would be to enable installing ptbcontrib with pip install git+https://github.com/python-telegram-bot/[email protected].

    This should be possible, according to this document: https://github.com/release-it/release-it/blob/master/docs/ci.md#github-actions

    Great issue for someone foreign to the project trying to make a small change :)

    enhancement hacktoberfest 
    opened by Poolitzer 2
null 1 Feb 18, 2022
Local community telegram bot

Бот на районе Телеграм-бот для поиска адресов и заведений в вашем районе города или в небольшом городке. Требует недели прогулок по району д

Ilya Zverev 32 Jan 19, 2022
Telegram bot implementing Lex Arcana using python-telegram-bot library.

Lex Arcana Telegram Bot ?? Telegram bot implementing Lex Arcana using python-telegram-bot library. This bot was evaluated for the course "Computer Eng

Nicolò Sonnino 6 Jun 22, 2022
A simple telegram voting bot based on the python-telegram-bot api.

A simple telegram voting bot based on the python-telegram-bot api. *To make it more easy to use, I might make a C++ code in the future so you don't ha

null 3 Sep 13, 2021
A Powerful telegram giveawayz bot based on the python-telegram-bot API

GiveawayZ Bot A Powerful telegram giveawayz bot based on the python-telegram-bot API. Powered by Team Zyntax and Team DFX Developed by @Zycho-Dev A pr

Zycho #AFK 5 Jul 31, 2022
WallAlley.bot is an open source and free to use financial discord bot originaly build for WallAlley server's community

WallAlley.bot About WallAlley.bot is an open source and free to use financial discord bot originaly build for WallAlley server's community. All data a

Mohammad KHADDAN 1 Jan 22, 2022
Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot

- [ MAYBE UPDATE & ADD MORE MODULE ] Bagas Mirror&Leech Bot Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring file

null 4 Nov 23, 2021
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram VCVideoPlayBot An Telegram Bot By @ZauteKm To Stream Videos in Telegram Voice Chat. NOTE: Make sure you have started a VoiceChat in your Grou

Zaute 20 Oct 21, 2022
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

SUBIN 449 Dec 27, 2022
A simple Telegram bot that analyses a given word, built with python-telegram-bot

Telegram Word Bot A simple Telegram bot that analyses a given word, built with python-telegram-bot. The bot is fairly useless - unless you often need

Chris N 2 Jul 14, 2022
A discord bot made by the community (uses python)

discord community bot context: this is a discord bot made by the community by community i mean people adding commands to the bot or changing the bot b

TR ASH 0 Oct 11, 2022
The Python version of the official Discord bot for the Astura Studios Discord community server.

About Astura (Python version) is the official Discord bot for the Astura Studios Discord community server developed and maintained by Ascendus and the

Ascendus 1 Apr 21, 2022
A community made discord bot coded in Python and running on AWS.

Pogbot Project Open Group Discord This is an open source community ran project. Join the discord for more information on how to participate. Coded in

Project Open Group 2 Jul 27, 2022
This is telegram bot to generate string session for using user bots. You can see live bot in https://telegram.dog/string_session_Nsbot

TG String Session Generate Pyrogram String Session Using this bot. Demo Bot: Configs: API_HASH Get from Here. API_ID Get from Here. BOT_TOKEN Telegram

Anonymous 27 Oct 28, 2022
A telegram bot which can show you the status of telegram bot

BotStatus-Ts-Bot An open source telegram Bot Status bot For demo you can check here The status is updated in every 1 hour About Bot This is a Bot stat

Ts_Bots 8 Nov 17, 2022
Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API.

Tg_PHub_Bot Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API. OS Support All linu

TheProgrammerCat 13 Oct 21, 2022
veez music bot is a telegram music bot project, allow you to play music on voice chat group telegram.

?? Veez Music Bot Music bot for playing music on telegram voice chat group. Requirements ?? FFmpeg NodeJS nodesource.com Python 3.7+ PyTgCalls ?? Get

levina 143 Jun 19, 2022
An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. This is Also The Source Code of The Bot Which is Being Used In @SafoTheBot Group! ❤️

Telegram Video Player Bot (Beta) An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. Special Features Supports Live Streaming From

SAF ONE 206 Jan 3, 2023