{"id":26273078,"url":"https://github.com/jonahwhaler/python-telegram-broadcast","last_synced_at":"2025-03-14T08:14:56.460Z","repository":{"id":238393073,"uuid":"796458295","full_name":"JonahWhaler/python-telegram-broadcast","owner":"JonahWhaler","description":"A simple Python package that build on top of python-telegram-bot to make broadcasting easier.","archived":false,"fork":false,"pushed_at":"2024-12-06T07:59:47.000Z","size":173,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T18:48:32.432Z","etag":null,"topics":["bot","broadcast","python","telegram"],"latest_commit_sha":null,"homepage":"https://jonahtzuchi.github.io/python-telegram-broadcast/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonahWhaler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-06T01:16:07.000Z","updated_at":"2024-12-06T07:59:50.000Z","dependencies_parsed_at":"2024-05-06T02:30:56.216Z","dependency_job_id":"36956112-19c7-457a-aac7-43db709906e8","html_url":"https://github.com/JonahWhaler/python-telegram-broadcast","commit_stats":null,"previous_names":["jonahtzuchi/python-telegram-broadcast"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonahWhaler%2Fpython-telegram-broadcast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonahWhaler%2Fpython-telegram-broadcast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonahWhaler%2Fpython-telegram-broadcast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonahWhaler%2Fpython-telegram-broadcast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonahWhaler","download_url":"https://codeload.github.com/JonahWhaler/python-telegram-broadcast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243544615,"owners_count":20308169,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","broadcast","python","telegram"],"created_at":"2025-03-14T08:14:55.802Z","updated_at":"2025-03-14T08:14:56.453Z","avatar_url":"https://github.com/JonahWhaler.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![my-logo](https://jonahwhaler.github.io/python-telegram-broadcast/logo-mini.jpg \"Python-Telegram-Broadcast-Logo\")\n\n# Python Telegram Broadcast\n\nThis is a simple Python package that build on top of [python-telegram-bot](https://pypi.org/project/python-telegram-bot/) to make broadcasting easier.\n\n\n## Features\n- Broadcast message to multiple users\n- Support media type:\n  - Text\n  - Photo\n  - Document\n  - Video\n- Support broadcast strategy:\n  - Asynchronous Sequentially\n  - Asynchronous Process Pool\n  - Asynchronous Multiprocessing Pool\n\n## Dependencies\n- [python-telegram-bot](https://pypi.org/project/python-telegram-bot/)=21.1.1\n- [mypy](https://pypi.org/project/mypy/)\n\n## Installation\n  ```bash\n  pip3 install python_telegram_broadcast\n  ```\n\n## Example\n\n### Get File ID from Telegram\n```python\nimport asyncio\nfrom python_telegram_broadcast import (\n    get_file_id, select_broadcast_method, BroadcastMethodType\n)\n\n\ndef wrapper(token, method, target_id, payload):\n  caption = \"\"\n  seconds = 0.0 # 0.0 means no timeout\n  max_retry = 5 # Maximum retry\n  \n  loop = asyncio.get_event_loop()\n  return loop.run_until_complete(\n      get_file_id(\n          token, method, target_id, payload, caption, seconds, max_retry\n      )\n  )\n  \n\nif __name__ == \"__main__\":\n  bot_token: str = \"TELEGRAM_BOT_TOKEN\"   # \u003c\u003c Change to your bot token\n  user_telegram_id: int = 123456789       # \u003c\u003c Change to your telegram id\n  file_path: str = \"\"                     # \u003c\u003c Change to your file path or the URL of your file\n  \n  broadcast_method = select_broadcast_method(BroadcastMethodType.PHOTO)\n  \n  # If file_path is a URL\n  file_id = wrapper(bot_token, broadcast_method, user_telegram_id, file_path)\n  \n  print(file_id)\n```\n    \n\n### Broadcast Photo\n```python\nfrom typing import Tuple\nfrom python_telegram_broadcast import (\n    handle_broadcast,\n    select_broadcast_strategy, BroadcastStrategyType,\n    write_sent_result\n)\n\ndef broadcast_wrapper(token, method, stg, slist, payload):\n    loop = asyncio.get_event_loop()\n    return loop.run_until_complete(\n        handle_broadcast(\n            slist, token, method, stg, payload, \"...\", \n            use_multiproc=False, use_nproc=1, seconds=0.0, max_retry=5\n        )\n    )\n\n# Use bot_token, broadcast_method, file_path from the previous example!!!\nexport_path = \"./asset\"\nbroadcast_strategy = select_broadcast_strategy(BroadcastStrategyType.ASYNCIO_SEQUENTIAL)\n# Read subscriber list from file, but you can also read from database of your choice\nsubscriber_list: list[Tuple[int, str]] = []\nwith open(\"./asset/subscriber.txt\", \"r\") as file:\n    header = file.readline()\n    while True:\n        line = file.readline()\n        if not line:\n            break\n        telegram_id, username = line.strip().split(\",\")\n        subscriber_list.append((int(telegram_id), username))\n\ns, f = broadcast_wrapper(\n    bot_token, broadcast_method, broadcast_strategy,\n    subscriber_list,\n    file_id\n)\nfor S in s:\n    print(f\"Success: {s}\")\n\nfor F in f:\n    print(f\"Failed: {f}\")\n\nif len(f) \u003e 0:\n    write_sent_result(f\"{export_path}/result_{file_path}.txt\", f, file_path)\n\n```\n\n## Tests\nTODO\n\n## Source Code\n- https://github.com/JonahTzuChi/python-telegram-broadcast\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonahwhaler%2Fpython-telegram-broadcast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonahwhaler%2Fpython-telegram-broadcast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonahwhaler%2Fpython-telegram-broadcast/lists"}