{"id":25846443,"url":"https://github.com/soap9035/simple-telegram-api","last_synced_at":"2025-03-01T09:29:34.832Z","repository":{"id":250946414,"uuid":"835941550","full_name":"SoAp9035/simple-telegram-api","owner":"SoAp9035","description":"A simple and easy-to-use Python library for Telegram bots.","archived":false,"fork":false,"pushed_at":"2025-02-06T16:23:22.000Z","size":34,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-06T17:32:16.184Z","etag":null,"topics":["api","bot","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/simple-telegram-api/","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/SoAp9035.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-07-30T20:45:28.000Z","updated_at":"2025-02-06T16:23:25.000Z","dependencies_parsed_at":"2025-02-06T17:26:26.443Z","dependency_job_id":"c172be80-1053-45f2-8482-a5e0f71d3625","html_url":"https://github.com/SoAp9035/simple-telegram-api","commit_stats":null,"previous_names":["soap9035/simple-telegram-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoAp9035%2Fsimple-telegram-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoAp9035%2Fsimple-telegram-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoAp9035%2Fsimple-telegram-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoAp9035%2Fsimple-telegram-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoAp9035","download_url":"https://codeload.github.com/SoAp9035/simple-telegram-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241348021,"owners_count":19948151,"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":["api","bot","telegram","telegram-bot"],"created_at":"2025-03-01T09:29:33.969Z","updated_at":"2025-03-01T09:29:34.820Z","avatar_url":"https://github.com/SoAp9035.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Telegram Api\r\n\r\nA simple and easy-to-use Python library for Telegram bots. This library allows you to send messages, edit messages, fetch updates, and handle messages easily.\r\n\r\n## Getting a Bot Token\r\n\r\nTo get a bot token, message [@BotFather](https://t.me/botfather) on Telegram and follow the instructions to create a new bot. BotFather will provide you with a token that looks like `123456789:ABCdefGHIjklmNOPQrstUVwxyz`.\r\n\r\n## Installation\r\n\r\nInstallation using pip (a Python package manager):\r\n\r\n```\r\npip install simple-telegram-api\r\n```\r\n\r\n## Usage/Examples\r\n\r\nA simple echo bot:\r\n\r\n```python\r\nfrom simple_telegram_api import TelegramBot\r\n\r\n\r\nBOT_TOKEN = \"BOT_TOKEN\"\r\n\r\nbot = TelegramBot(BOT_TOKEN)\r\n\r\n# Delete old messages before bot is running.\r\nbot.reset_updates()\r\n\r\nprint(\"Bot is running.\")\r\nwhile True:\r\n    updates = bot.get_updates()\r\n\r\n    # Check if it's empty.\r\n    if updates:\r\n        print(updates)\r\n        bot.reset_updates(updates=updates)\r\n\r\n        # For multiple coming up messages.\r\n        for update in updates[\"result\"]:\r\n            chat_id = update[\"message\"][\"chat\"][\"id\"]\r\n            user_message = update[\"message\"][\"text\"]\r\n            \r\n            bot_update = bot.send_message(user_message, chat_id=chat_id)\r\n            print(bot_update)\r\n```\r\n\r\n### Using the TelegramBot Class\r\n\r\n```python\r\nfrom simple_telegram_api import TelegramBot\r\n\r\nbot = TelegramBot('BOT_TOKEN')\r\n```\r\n\r\n### Get Updates\r\n\r\nThis function gets new messages from Telegram.\r\n\r\n```python\r\nupdates = bot.get_updates()\r\n```\r\n\r\n#### Example Get Updates Output\r\n\r\nHere is an example of the output from the `get_updates()` function:\r\n\r\n```python\r\n{\r\n    \"ok\": True,\r\n    \"result\": [\r\n        {\r\n            \"update_id\": 123456789,\r\n            \"message\": {\r\n                \"message_id\": 123,\r\n                \"from\": {\r\n                    \"id\": 123456789,\r\n                    \"is_bot\": False,\r\n                    \"first_name\": \"Person Name\",\r\n                    \"username\": \"person\",\r\n                    \"language_code\": \"en\"\r\n                },\r\n                \"chat\": {\r\n                    \"id\": 123456789,\r\n                    \"first_name\": \"Person Name\",\r\n                    \"username\": \"person\",\r\n                    \"type\": \"private\"\r\n                },\r\n                \"date\": 1733920402,\r\n                \"text\": \"Hi!\"\r\n            }\r\n        }\r\n    ]\r\n}\r\n```\r\n\r\n### Reset Updates\r\n\r\nThis function deletes old messages from updates.\r\n\r\n```python\r\nbot.reset_updates(updates=updates)\r\n```\r\n\r\n### Send Message\r\n\r\nTo send a message:\r\n\r\n```python\r\nbot.send_message(text=text, chat_id=chat_id)\r\n```\r\n\r\nTo reply to a message:\r\n\r\n```python\r\nbot.send_message(text=text, chat_id=chat_id, reply_to_message=True, message_id=message_id)\r\n```\r\n\r\n#### Example Send Message Output\r\n\r\nHere is an example of the output from the `send_message()` function:\r\n\r\n```python\r\n{\r\n    \"ok\": True,\r\n    \"result\": {\r\n        \"message_id\": 124,\r\n        \"from\": {\r\n            \"id\": 123456789,\r\n            \"is_bot\": True,\r\n            \"first_name\": \"Bot\",\r\n            \"username\": \"bot\"\r\n        },\r\n        \"chat\": {\r\n            \"id\": 123456789,\r\n            \"first_name\": \"Person Name\",\r\n            \"username\": \"person\",\r\n            \"type\": \"private\"\r\n        },\r\n        \"date\": 1733920404,\r\n        \"text\": \"Hi!\"\r\n    }\r\n}\r\n```\r\n\r\n### Edit Message\r\n\r\n```python\r\nbot.edit_message(text=text, chat_id=chat_id, message_id=message_id)\r\n```\r\n\r\n## Recommendations\r\n\r\nIf `updates` is not provided in `reset_updates()`, new updates will be fetched automatically. Use the result from `get_updates()` as `updates`, as shown in the example.\r\n\r\n## License\r\n\r\n[MIT](https://choosealicense.com/licenses/mit/)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoap9035%2Fsimple-telegram-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoap9035%2Fsimple-telegram-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoap9035%2Fsimple-telegram-api/lists"}