{"id":28709056,"url":"https://github.com/eikoshelev/go-telegram-bot-example","last_synced_at":"2025-06-14T19:39:50.031Z","repository":{"id":154746930,"uuid":"631177344","full_name":"eikoshelev/go-telegram-bot-example","owner":"eikoshelev","description":"An example of organizing code and building a user flow for a Telegram bot in Golang","archived":false,"fork":false,"pushed_at":"2024-07-25T09:03:55.000Z","size":2027,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2024-07-25T10:30:52.031Z","etag":null,"topics":["example","golang","telegram","telegram-bot","telegram-bot-example"],"latest_commit_sha":null,"homepage":"","language":"Go","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/eikoshelev.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-22T07:14:57.000Z","updated_at":"2024-07-25T09:03:59.000Z","dependencies_parsed_at":"2024-06-21T15:27:14.148Z","dependency_job_id":"eed7b300-c974-4d41-a266-6ad7f9fb66fb","html_url":"https://github.com/eikoshelev/go-telegram-bot-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eikoshelev/go-telegram-bot-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eikoshelev%2Fgo-telegram-bot-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eikoshelev%2Fgo-telegram-bot-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eikoshelev%2Fgo-telegram-bot-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eikoshelev%2Fgo-telegram-bot-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eikoshelev","download_url":"https://codeload.github.com/eikoshelev/go-telegram-bot-example/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eikoshelev%2Fgo-telegram-bot-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259872862,"owners_count":22924650,"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":["example","golang","telegram","telegram-bot","telegram-bot-example"],"created_at":"2025-06-14T19:39:48.294Z","updated_at":"2025-06-14T19:39:50.018Z","avatar_url":"https://github.com/eikoshelev.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-telegram-bot-example\n\n\u003e [!IMPORTANT]\n\u003e In this repository I used the library https://github.com/go-telegram-bot-api/telegram-bot-api, however today it is outdated and irrelevant, for this reason I advise using alternative libraries, among which I can confidently recommend https://github.com/go-telegram/bot. I hope I will have free time to update this repository with an up-to-date library and a more correct approach in general.\n\nThis repository is an example of the concept of building Telegram (and other) bots, which does not claim to be a standard or an indisputable truth, which provides a simple and readable code divided into separate layers. In particular, a simple concept of working with user scripts has been implemented.  \n\nFor a complete immersion in the implementation, it is better to view the source code, which is commented in sufficient detail.\n\n## Basic concept\n\nAn object-oriented approach is proposed: business entities are implemented at the application level, over which any manipulations are possible. The command in this case refers to a specific entity (object) with which it is planned to perform actions (see diagrams below).\n\n### Project structure\n\nThe code is structured and organized based on the **simplified** concept of [clean architecture](https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html). \n\n```\n├── assets\n│   ...\n├── cmd\n│   └── go-telegram-bot-example\n│       // configuration file and main.go, no more\n├── internal\n│   ├── bot\n│   │   // application's internal packages directory\n│   ├── config\n│   │   // application configuration\n│   ├── database\n│   │   // state store configuration and initialization\n│   ├── flow\n│   │   // the same example of implementing custom scripts\n│   ├── logger\n│   │   // logging initialization with necessary parameters\n│   ├── messages\n│   │   // here are the messages that we broadcast to the user through the bot\n│   ├── model\n│   │   // all business entities of the application and auxiliary methods for them\n│   ├── repository\n│   │   // methods of interaction with the state store (at this level, there can also be calls to external APIs, working with the cache, etc.)\n│   └── service\n│       // all business logic of the application should be implemented here (work with repositories, etc.)\n└── migrations\n    // migration files\n```\n\n## The concept of working with bot commands\n\nIn this example, bot commands are perceived as starters of some user scripts and/or flow in general. At the level of command handlers, any preparatory business logic necessary for further work can be implemented.\n\n![alt text](assets/schemes-commands.png)\n\n## The concept of working with callbacks\n\nAfter executing commands, the user interacts with a specific object and execution script. Therefore, we can use callback data to receive and process user actions.\n\n![alt text](assets/schemes-callbacks.png)\n\n## An example of the described flow\n\n```go\nmodel.Flow{\n  model.ProfileCommand: model.Usecase{\n    \"create\": model.Chain{\n      0: model.Action{\n        Handler: svc.Profile.Create,\n\tMessage: profile.Create(),\n      },\n    },\n  },\n}\n```\n```json\n{\n   \"profile\":{\n      \"create\":{\n         \"0\":{\n            \"handler\": HandlerFunc(),\n            \"message\":\"Click the button below to create a profile\",\n            \"buttons\":[\n               {\n                  \"name\":\"Create profile\",\n                  \"callback_data\":{\n                     \"cmd_key\":\"profile\",\n                     \"case\":\"create\",\n                     \"step\":0,\n                     \"payload\":\"\"\n                  }\n               }\n            ]\n         }\n      }\n   }\n}\n```\n\n## What else?\n\nOpen an issue or PR if you have more suggestions, questions or ideas about what to add.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feikoshelev%2Fgo-telegram-bot-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feikoshelev%2Fgo-telegram-bot-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feikoshelev%2Fgo-telegram-bot-example/lists"}