{"id":41346252,"url":"https://github.com/raisultan/tg-bot-service","last_synced_at":"2026-01-23T06:59:20.680Z","repository":{"id":64010809,"uuid":"354821298","full_name":"raisultan/tg-bot-service","owner":"raisultan","description":"Telegram Bot Microservice implemented with FastAPI and Telethon","archived":false,"fork":false,"pushed_at":"2021-04-11T10:48:31.000Z","size":142,"stargazers_count":57,"open_issues_count":0,"forks_count":21,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-24T21:58:55.424Z","etag":null,"topics":["api-drivers","driver","event-handler","fastapi","generic","microservice","telegram","telegram-bot-microservice","telegram-client","telethon","telethon-bot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raisultan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-05T12:06:01.000Z","updated_at":"2024-07-21T18:37:05.000Z","dependencies_parsed_at":"2022-12-04T12:20:19.219Z","dependency_job_id":null,"html_url":"https://github.com/raisultan/tg-bot-service","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raisultan/tg-bot-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raisultan%2Ftg-bot-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raisultan%2Ftg-bot-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raisultan%2Ftg-bot-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raisultan%2Ftg-bot-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raisultan","download_url":"https://codeload.github.com/raisultan/tg-bot-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raisultan%2Ftg-bot-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28682264,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-drivers","driver","event-handler","fastapi","generic","microservice","telegram","telegram-bot-microservice","telegram-client","telethon","telethon-bot"],"created_at":"2026-01-23T06:59:20.266Z","updated_at":"2026-01-23T06:59:20.672Z","avatar_url":"https://github.com/raisultan.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegram Bot Microservice\nBasis for extendable, high-performance Telegram Bot microservice.\n\n\n## Tech Stack\n- FastAPI\n- Telethon\n- AsyncIO\n- Docker \u0026 docker-compose\n\n\n## Features\n\n### Receiver Service\n- Updates Receiver [Telethon / MTProto] - receive updates on any action made by user directed to Telegram Bot/Account. Similar to Webhook Server or Long Polling, but faster and more stable due to use of MTProto protocol which is Telegram Native. [More on this topic](https://docs.telethon.dev/en/latest/concepts/botapi-vs-mtproto.html#advantages-of-mtproto-over-bot-api).\n- Basic event handler - currently to stay as generic as possible service implements basic conversation. Functionality can be extended by adding new handlers.\n- Async API Driver [HTTPX] - HTTP/REST API Driver to interact with other services.\n- Logger for API Driver [Native Python Logger] - to monitor and log each request and response. Additionally, keeps logs in files to use with monitoring tools, such as ELK, Prometheus+Grafana, etc.\n\n### Sender Service\n- Async API [FastAPI] - receive requests from other services. Endpoints:\n    * `/api_v1/send_message` - send plain message to user\n    * `/api_v1/send_multiple_message` - send multiple messages to multiple users\n    * `/api_v1/create_document` - create document on Telegram Servers and receive its ID, to later reuse\n    * `/api_v1/send_document` - send document by Telegram ID\n    * `/api_v1/send_multiple_documents` - send multiple documents to multiple users\n- Sender [Telethon] - Telegram Client that will be triggered to execute some business logic after successful processing of request received by API, in other words to send updates to user.\n\n\n## Whole Service Workflow\nAs it can be understood, this microservice is not \"killer-beast\" and is not suitable for all use-cases. It is mostly oriented for offload, high-speed interaction with users through Telegram.\n\nIdeal workflow of service is following:\n- user sends update to Telegram Bot/Account, which is received by specific event handler of **Receiver**\n- event handler processes received data, adjusts it if needed and sends this data to **Other Microservice** through **API Driver**, note that you can implement as many API Drivers as you need to interact with your services.\n- **Other Microservice** processes and executes its own business logic and sends result of processing to **API**.\n- **API** receives the data from other service and transfers it Telegram through **Sender**, which is Telegram Client provided by Telethon.\n\nThus, we have fully autonomous, loosely-coupled microservice.\n\n### Workflow Scheme\n\n![workflow_scheme](diagrams/architecture.jpg)\n\n\n## How to Use\n\nRoot directory has docker-compose file through which whole microservice can be started. But firstly, build images:\n```shell\ndocker-compose build\n```\nAnd start up services:\n```shell\ndocker-compose up\n```\n\n**Sender** service API can be found on http://0.0.0.0:8001 and docs on http://0.0.0.0:8001/docs\n\n\n## Enhancement, contribution, and feedback\nAny feedback or contribution to the project is eagerly welcomed. Just create an issue or contact me on ki.xbozz@gmail.com.\n\n\n## Recommended for reading:\n- https://docs.telethon.dev/en/latest/quick-references/faq.html\n\n\n## Todo:\n- [ ] logging for FastAPI\n- [ ] logging for Telethon event handlers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraisultan%2Ftg-bot-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraisultan%2Ftg-bot-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraisultan%2Ftg-bot-service/lists"}