{"id":23800210,"url":"https://github.com/apiad/logbot","last_synced_at":"2025-09-06T14:33:09.888Z","repository":{"id":47630398,"uuid":"168555419","full_name":"apiad/logbot","owner":"apiad","description":"A Telegram bot that you can log to from Python and manage long running processes.","archived":false,"fork":false,"pushed_at":"2022-12-08T07:25:34.000Z","size":174,"stargazers_count":27,"open_issues_count":7,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-17T04:56:31.304Z","etag":null,"topics":["python","requests","sanic","telegram-bot"],"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/apiad.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":"2019-01-31T16:17:58.000Z","updated_at":"2024-04-12T10:38:58.000Z","dependencies_parsed_at":"2023-01-25T08:45:46.775Z","dependency_job_id":null,"html_url":"https://github.com/apiad/logbot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apiad%2Flogbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apiad%2Flogbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apiad%2Flogbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apiad%2Flogbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apiad","download_url":"https://codeload.github.com/apiad/logbot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232129191,"owners_count":18476645,"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":["python","requests","sanic","telegram-bot"],"created_at":"2025-01-01T21:36:43.902Z","updated_at":"2025-01-01T21:36:44.646Z","avatar_url":"https://github.com/apiad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LogBot [![](https://img.shields.io/pypi/v/logbot-telegram.svg?style=flat-square)](https://pypi.org/project/logbot-telegram/) [![](https://img.shields.io/pypi/pyversions/logbot-telegram.svg?style=flat-square)](https://pypi.org/project/logbot-telegram/) [![](https://img.shields.io/badge/chat%20on-telegram-red.svg?style=flat-square\u0026logo=telegram)](https://t.me/apiad_demo_logbot)\n\n\u003e A Telegram bot that you can log to from bash or Python and manage long running processes.\n\n```\npip install logbot-telegram\n```\n\n## Quickstart\n\n\u003e **NOTE:** The following example is using a _demo_ bot that I personally host at [apiad.net:6778](http://apiad.net:6778). This bot can and will be stopped, restarted or even destroyed without notice. Refer to the section on **Setting your own** for more details.\n\nFirst, go to Telegram and open a chat with [LogBot (Demo)](http://t.me/apiad_demo_logbot). You'll see this initial message.\n\n![](img/img1.png)\n\nHit the **Start** button, and the bot will send you a *secret token*:\n\n![](img/img2.png)\n\nNow with this secret token you can communicate to the bot through HTTP. The protocol is very simple. Just a send a `POST` request to the bot's API with an encoded `json` data:\n\n```bash\ncurl -XPOST http://apiad.net:6778 -d \\\n\"{                                   \\\n    \\\"token\\\": \\\"8PmUheSK6Zow\\\",     \\\n    \\\"msg\\\": \\\"Hello World\\\"         \\\n}\"\n{\"msg\":\"Hello World\", \"id\":121}\n```\n\nVoilá, your message will be forwared to Telegram:\n\n![](img/img3.png)\n\nYou can send messages with Markdown formatting:\n\n```bash\ncurl -XPOST http://apiad.net:6778 -d \\\n\"{                                   \\\n    \\\"token\\\": \\\"8PmUheSK6Zow\\\",     \\\n    \\\"msg\\\": \\\"*Hello* _World_\\\"     \\\n}\"\n{\"msg\":\"*Hello* _World_\", \"id\":122}\n```\n\n![](img/img4.png)\n\nFinally, you can send **actions**, that will be rendered as buttons in Telegram.\nWhen you click the button, and **only when you click it**, you will get a response back with the clicked option:\n\n```bash\ncurl -XPOST http://apiad.net:6778 -d    \\\n\"{                                      \\\n    \\\"token\\\": \\\"8PmUheSK6Zow\\\",        \\\n    \\\"msg\\\": \\\"Wanna try?\\\",            \\\n    \\\"actions\\\": [\\\"Yes\\\", \\\"No way\\\"]  \\\n}\"\n{\"msg\":\"Wanna try?\",\"response\":\"Yes\", \"id\":123}\n```\n\n![](img/img5.png)\n\n\u003e **NOTE:** By default you have 60 seconds to answer before a response timeout is raised. This hard limit might be changed in future versions.\n\nIf you send a `progress` key with a value between `0` and `1` (`float`), the message will also render a progress bar.\nIf you send an `edit` key with the value (`int`) of the `id` of a previous response, you will edit that message instead of sending a new one.\nYou can use these two features together to create animated progress bars.\n\n```bash\ncurl -XPOST http://apiad.net:6778 -d    \\\n\"{                                      \\\n    \\\"token\\\": \\\"8PmUheSK6Zow\\\",        \\\n    \\\"msg\\\": \\\"It works\\\",              \\\n    \\\"progress\\\": 0.3                   \\\n}\"\n{\"msg\":\"It works\", \"id\":124}\n```\n\n![](img/img6.png)\n\n## Python API\n\nIf you talk Python, you can clone this project and use a set of simple tools to skip all that `curl`.\n\n```\npip install logbot-telegram\n```\n\n* `send` simply sends the message.\n\n```python\n\u003e\u003e\u003e from logbot import Client\n\u003e\u003e\u003e c = Client(token=\"\u003ctoken\u003e\", host=\"http://apiad.net\", port=6778)\n\u003e\u003e\u003e c.send(\"Hello World\")\n```\n\n* `ask` will send the corresponding questions as buttons and return the reply:\n\n```python\n\u003e\u003e\u003e c.ask(\"Do you?\", \"A\", \"B\", \"C\")\n'C' # Supposedly you hit C in Telegram\n```\n\n* `yes` will simply send `Yes` and `No` and return `True` or `False`:\n\n```python\n\u003e\u003e\u003e if c.yes(\"Do you?\"):\n\u003e\u003e\u003e     print(\"It does!\")\n'It does!' # Supposedly you hit Yes in Telegram\n```\n\nThe `send` method also receives an optional `progress` value to render a progress bar.\nAlso, a parameter `edit=True` will make it edit the last send message, instead of a new one.\nWith these options you can make an animated progress bar like:\n\n```python\n\u003e\u003e\u003e for i in range(0, 11):\n...     c.send(\"Progress\", progress=i/10, edit=True)\n...     time.sleep(1)\n```\n\nThese are also available as simple functions, which receive `token`, `host` and `port` on every call. The `Client` class just simplifies passing those values all the time.\n\n## What can I do with this?\n\nSome simple ideas:\n\n* **Log directly into Telegram from your code**. For example, using Python `request` you can easily make any long-running script to periodically send updates.\n* **Monitor a server**. Using `bash`, `curl` and `cron` you can send yourself periodically info about your CPU, memory and I/O ussage.\n* **Quick responses on Telegram**. By using the response actions, you can interact with running code, either to take decisions, kill long running processes, retry things that broke, etc. Your imagination is the limit.\n\n## Setting up your own\n\nFor testing, and while my server handles it, you can use the bot I have set up. It's free and for that reason I might decide to turn it off at any given time without any advice. So, if you want a long time working solution, you will have to set up your own.\n\n1. Create your Telegram bot with [BotFather](t.me/botfather). If you don't know what I mean, read the Telegram documentation on bots. It's all over the Internet.\n2. BotFather will give you a `TOKEN`. Make sure to write it down.\n3. Run `pip install logbot-telegram`.\n4. Run `export TOKEN=\u003cyour-token\u003e`.\n5. You can run `python -m logbot` now. It will listen by default at `localhost:6778`.\n6. You can change the `HOST` and `PORT` with environment variables.\n\n## Collaboration\n\nIt's MIT, so you know the drill. Fork, edit, pull request, repeat.\n\n## License\n\n\u003e MIT License\n\u003e\n\u003e Copyright (c) 2019 Alejandro Piad\n\u003e\n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy\n\u003e of this software and associated documentation files (the \"Software\"), to deal\n\u003e in the Software without restriction, including without limitation the rights\n\u003e to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\u003e copies of the Software, and to permit persons to whom the Software is\n\u003e furnished to do so, subject to the following conditions:\n\u003e\n\u003e The above copyright notice and this permission notice shall be included in all\n\u003e copies or substantial portions of the Software.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\u003e IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\u003e FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\u003e AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\u003e LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\u003e OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\u003e SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapiad%2Flogbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapiad%2Flogbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapiad%2Flogbot/lists"}