{"id":19665243,"url":"https://github.com/alttch/tebot","last_synced_at":"2026-04-30T02:34:30.968Z","repository":{"id":57473748,"uuid":"234971529","full_name":"alttch/tebot","owner":"alttch","description":"Telegram bot library for Python and humans","archived":false,"fork":false,"pushed_at":"2020-03-05T23:23:24.000Z","size":155,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-29T00:11:21.300Z","etag":null,"topics":["bot","library","messenger","python","python3","robot","telegram"],"latest_commit_sha":null,"homepage":null,"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/alttch.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}},"created_at":"2020-01-19T21:35:16.000Z","updated_at":"2020-03-05T23:23:26.000Z","dependencies_parsed_at":"2022-09-26T17:40:51.135Z","dependency_job_id":null,"html_url":"https://github.com/alttch/tebot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alttch/tebot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ftebot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ftebot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ftebot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ftebot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alttch","download_url":"https://codeload.github.com/alttch/tebot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alttch%2Ftebot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261289391,"owners_count":23136068,"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","library","messenger","python","python3","robot","telegram"],"created_at":"2024-11-11T16:21:46.172Z","updated_at":"2026-04-30T02:34:25.949Z","avatar_url":"https://github.com/alttch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TeBot - Telegram bot library for Python and humans\n\nThe goal is to to keep it simple.\n\n\u003cimg src=\"https://img.shields.io/pypi/v/tebot.svg\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-MIT-green.svg\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg\" /\u003e\n\n## How to install\n\n```shell\npip3 install tebot\n```\n\n## How to use\n\n### Start bot\n\nIf your project uses [neotasker](https://github.com/alttch/neotasker)\n\n```python\nfrom tebot import TeBot\n\n# delay - delay between pollings, must be specified\nmybot = TeBot(delay=2)\n# obtain token from https://telegram.me/BotFather\nmybot.set_token('botsecrettoken')\n# optionally - load previous state\nimport json\nwith open('bot-state.json') as fh:\n    mybot.load(json.loads(fh.read()))\n# start bot\nmybot.start()\n```\n\nIf it doesn't:\n\n```python\nfrom neotasker import task_supervisor\nfrom tebot import TeBot\n\ntask_supervisor.create_aloop('default', default=True)\ntask_supervisor.start()\nmybot = TeBot(delay=2)\nmybot.set_token('botsecrettoken')\nmybot.start()\n```\n\n(refer to **neotasker** documentation for more info)\n\n### Stop bot\n\n```python\nmybot.stop()\n# if your project doesn't use neotasker\ntask_supervisor.stop()\n# optionally - save bot state\nwith open('bot-state.json', 'w') as fh:\n    fh.write(json.dumps(mybot.serialize()))\n```\n\n### Send messages\n\n```python\n# text\nmybot.send(text='hello world', chat_id=chat_id)\n# files\nwith open('image.jpg', 'rb') as fh:\n    mybot.send(media=fh.read(), chat_id=chat_id)\n```\n\nIf message is being sent from the handler and *chat_id* is not specified,\ncurrent chat ID is used:\n\n```python\n@mybot.route(path='/start')\ndef start(**kwargs):\n    mybot.send('bot started')\n```\n\n### Download files\n\n```python\ndef somehandler(**kwargs):\n    payload = kwargs.get('payload')\n    if 'document' in payload:\n        try:\n            content = mybot.get_file_content(payload['document'].get('file_id'))\n            # process file content\n        except:\n            # unable to download file\n```\n\n### High-level API: routes\n\n**TeBot** has flask-style routes, which may be registered either by calling\n\n```python\n    mybot.register_route(fn, path, methods)\n```\n\nor with function decorator:\n\n```python\n# message handler. can be only one, registered to handle all regular messages\n@mybot.route(methods='message')\ndef my_message(chat_id, text, **kwargs):\n    # some code\n\n# command handler for /start and /help\n@mybot.route(path=['/start', '/help'])\ndef start(**kwargs):\n    mybot.send('got HELP command')\n\n# command and callback query handler\n@mybot.route(methods='*')\ndef default_cmd_handler(path, **kwargs):\n    mybot.send(f'command not implemented: {path}')\n```\n\n#### Route parameters\n\n* **path** command path, can be string or list/tuple for multiple commands\n\n* **methods** can be either a string or a list/tuple. Valid values are:\n  \"message\", \"command\" (default if no methods specified) and\n  \"query\" / \"callback_query\". If \"\\*\" specified, the method is registered for\n  both commands and callback queries\n\n\n#### Handler kwargs\n\nThe following kwargs are sent to registered handlers:\n\n* **text** message text (only for message handler)\n\n* **path** command path (e.g. \"/select\" for \"/select \\* from data\")\n\n* **query_string** command query string (e.g. \"\\* from data\" for the above\n  example)\n\n* **chat_id** current chat id\n\n* **query_id** callback query id, if handler is executed as a callback query\n  handler\n\n* **payload** full request payload\n\n* **method** \"command\" or \"query\" for callback query\n\n#### Handler return data\n\n* If command is handled, the handler may return nothing\n\n* If callback query is handled, the handler may return dict, which is used as a\n  payload for the callback query answer (e.g. include \"url\", \"show_alert\" etc,\n  see Telegram Bot API for more details)\n\n### Low-level API: handlers\n\nOverride class methods:\n\n* **handle_message** handle regular messages\n\n* **handle_command** handle commands (starting\n  with '/')\n\n* **handle_query** handle callback queries\n\n* **on_message** override to implement advanced message handling\n\n* **on_query** override to implement advanced callback query handling\n\n## Bot options\n\n```python\nmybot.timeout = 5 # set Telegram API timeout (default: 10 sec)\nmybot.retry_interval = 1 # if API command fails, re-send it in 1 second\n                         # (default: None, don't re-send)\n```\n\n## Web hooks\n\nTo use web hooks, init bot object, **but don't start it**. Use\n*process_update(payload)* method to process webhook payloads.\n\nTeBot doesn't have own web server module, you may use any available.\n\nTo register webhook, use *set_webhook* bot object method (args are the same as\nfor https://core.telegram.org/bots/api#setwebhook)\n\nTo delete webhook, use *delete_webhook* bot object method (no args required).\n\n## Everything else\n\nRefer to function pydoc for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Ftebot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falttch%2Ftebot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falttch%2Ftebot/lists"}