{"id":15024942,"url":"https://github.com/luckydonald/teleflask","last_synced_at":"2025-04-12T12:32:03.538Z","repository":{"id":57454118,"uuid":"73646253","full_name":"luckydonald/teleflask","owner":"luckydonald","description":"A python telegram bot framework based on flask and pytgbot","archived":false,"fork":false,"pushed_at":"2021-01-05T22:18:49.000Z","size":351,"stargazers_count":53,"open_issues_count":4,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T07:36:34.497Z","etag":null,"topics":["flask","pytg","pytgbot","python","teleflask","telegram","telegram-api","telegram-bot-api"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luckydonald.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-13T22:11:39.000Z","updated_at":"2024-06-27T17:27:35.000Z","dependencies_parsed_at":"2022-09-04T23:22:20.384Z","dependency_job_id":null,"html_url":"https://github.com/luckydonald/teleflask","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydonald%2Fteleflask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydonald%2Fteleflask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydonald%2Fteleflask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckydonald%2Fteleflask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luckydonald","download_url":"https://codeload.github.com/luckydonald/teleflask/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248490385,"owners_count":21112741,"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":["flask","pytg","pytgbot","python","teleflask","telegram","telegram-api","telegram-bot-api"],"created_at":"2024-09-24T20:01:15.189Z","updated_at":"2025-04-12T12:32:03.102Z","avatar_url":"https://github.com/luckydonald.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# teleflask\n###### Version 1.0.1\n\nA python telegram bot framework based on flask and pytgbot\nTested to work on python 3. Might work on python 2.\n\n## Install\n##### Python Package Index\n\n```bash\npip install teleflask\n```\n\n#### Soon\n\nCurrently the source version (here on Github) is a work in progress version.\nGreat features are to come, including a Blueprint feature.\nIt is currently at version `2.0.0.dev23`, and will be `2`.`0`.`0` when released.\n\nIf you want to try it out already, run\n```bash\npip install -e git://github.com/luckydonald/teleflask.git@v2.0.0.dev23#egg=teleflask\n```\nSometimes it might additionally be available on PyPI\n```bash\npip install teleflask==2.0.0.dev23\n```\n\n#### Soon: Proxy\n\nAdded proxy script to test webhooks in local environments\nwithout exposing you to the internet.\n\n###### CLI proxy:\n\n```bash\nusage python -m teleflask.proxy [-h|--help] [--https] [--hookpath HOOKPATH] api_key host port\n\nPulls updates from telegram and shoves them into your app.\n\npositional arguments:\n  api_key              api key for the telegram API to use.\n  host                 turn on https on the url\n  port                 the port number\n\noptional arguments:\n  -h, --help           show this help message and exit\n  --https              turn on https on the url\n  --hookpath HOOKPATH  the path for the webhook (default: \"/income/{API_KEY}\")\n```\n\n```bash\npython -m teleflask.proxy \"123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11\" localhost 8080\n```\n\n\n## Usage\n\n### Initalize\n\n```python\nfrom teleflask import Teleflask\n\nbot = Teleflask(API_KEY, app)\n```\n\nor\n\n```python\nfrom teleflask import Teleflask\n\nbot = Teleflask(API_KEY)\nbot.init_app(app)\n```\n\n`app` being your flask app.\n\n### Usage\n```python\n# use bot from initialize above\nfrom teleflask.messages import TextMessage\n\n\n@app.route(\"/\")\ndef index():\n    return \"This is a normal Flask page.\"\n# end def\n\n\n# Register the /start command\n@bot.command(\"start\")\ndef start(update, text):\n    # update is the update object. It is of type pytgbot.api_types.receivable.updates.Update\n    # text is the text after the command. Can be empty. Type is str.\n    return TextMessage(\"\u003cb\u003eHello!\u003c/b\u003e Thanks for using @\" + bot.username + \"!\", parse_mode=\"html\")\n# end def\n\n\n# register a function to be called for updates.\n@bot.on_update\ndef foo(update):\n    from pytgbot.api_types.receivable.updates import Update\n    assert isinstance(update, Update)\n    # do stuff with the update\n    # you can use bot.bot to access the pytgbot.Bot's messages functions\n    if not update.message:\n        return\n        # you could use @bot.on_message instead of this if.\n    # end if\n    if update.message.new_chat_member:\n        return TextMessage(\"Welcome!\")\n    # end if\n# end def\n\n```\n\n\n# Short documentation\n\nFunctions and classes are explained in the docstrings in the sourcecode.\n\n## `Teleflask`\n\n`Teleflask` is the full package, including all provided functionality.\n\n### Components\n\nFunctionality is separated into mixin classes. This means you can plug together a class with just the functions you need.\nThe `Teleflask` class includes all of them.\n\n#### Startup (`teleflask.mixins.StartupMixin`):\n- `app.add_startup_listener` to let the given function be called on server/bot startup\n- `app.remove_startup_listener` to remove the given function again\n- `@app.on_startup` decorator which does the same as add_startup_listener.\n\n#### Commands (`teleflask.mixins.BotCommandsMixin`):\n- `app.add_command` to add command functions\n- `app.remove_command` to remove them again.\n- `@app.command(\"command\")` decorator as alias to `add_command`\n- `@app.on_command(\"command\")` decorator as alias to `add_command`\n\n#### Messages (`teleflask.mixins.MessagesMixin`):\n- `app.add_message_listener` to add functions\n- `app.remove_message_listener` to remove them again.\n- `@app.on_message` decorator as alias to `add_message_listener`\n\n#### Updates (`teleflask.mixins.UpdatesMixin`):\n- `app.add_update_listener` to add functions to be called on incoming telegram updates.\n- `app.remove_update_listener` to remove them again.\n- `@app.on_update` decorator doing the same as `add_update_listener`\n\n### Execution order:\n\nIt will first check for registered commands (`@command`),\nnext for messages listeners (`@on_message`) and\nfinally for update listeners (`@on_update`).\n\n### Running bot commands\n\nThe normal `pytgbot`'s bot is available as `.bot` in your `Teleflask` instance:\n\n```python\nfrom teleflask import Teleflask\n\nbot = Teleflask(API_KEY, app)\nbot.bot.send_message('@luckydonald', 'It works :D')  # please don't spam me :D\n```\n\n\n# Deployment\nThis section is for myself, as I always forget.\nYou can ignore the deployment section.\n\n### Development release\n\n#### Increment \u003ccode\u003e.dev\u003ci\u003eXYZ\u003c/i\u003e\u003c/code\u003e\n\n```bash\nbump2version dev\n# check that tag and every replacement is correct\nmake upload\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckydonald%2Fteleflask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluckydonald%2Fteleflask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckydonald%2Fteleflask/lists"}