{"id":13409489,"url":"https://github.com/mymmrac/telego","last_synced_at":"2025-03-14T14:31:29.835Z","repository":{"id":37582539,"uuid":"380799735","full_name":"mymmrac/telego","owner":"mymmrac","description":"Telegram Bot API library for Go","archived":false,"fork":false,"pushed_at":"2024-10-29T14:07:04.000Z","size":3479,"stargazers_count":548,"open_issues_count":2,"forks_count":42,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-29T17:14:27.246Z","etag":null,"topics":["bot","bot-api","bot-framework","go","golang","telego","telegram","telegram-api","telegram-bot","telegram-bot-api"],"latest_commit_sha":null,"homepage":"https://telego.pixelbox.dev","language":"Go","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/mymmrac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"docs/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":"mymmrac","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2021-06-27T17:26:14.000Z","updated_at":"2024-10-29T14:07:12.000Z","dependencies_parsed_at":"2023-12-23T23:21:32.669Z","dependency_job_id":"19eca164-62d7-4dcc-ae06-8fd8a27924fc","html_url":"https://github.com/mymmrac/telego","commit_stats":{"total_commits":749,"total_committers":12,"mean_commits":"62.416666666666664","dds":"0.16555407209612816","last_synced_commit":"282aecf782ced7f0861da363f1e19deb894c00bf"},"previous_names":["mymmrac/go-telegram-bot-api"],"tags_count":82,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mymmrac%2Ftelego","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mymmrac%2Ftelego/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mymmrac%2Ftelego/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mymmrac%2Ftelego/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mymmrac","download_url":"https://codeload.github.com/mymmrac/telego/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243593419,"owners_count":20316182,"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","bot-api","bot-framework","go","golang","telego","telegram","telegram-api","telegram-bot","telegram-bot-api"],"created_at":"2024-07-30T20:01:01.287Z","updated_at":"2025-03-14T14:31:24.813Z","avatar_url":"https://github.com/mymmrac.png","language":"Go","funding_links":["https://patreon.com/mymmrac"],"categories":["Bot建设","Bot Building","Telegram Libraries","Go","Uncategorized"],"sub_categories":["Go","Free e-books"],"readme":"# Telego • Go Telegram Bot API\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/mymmrac/telego#section-readme.svg)](https://pkg.go.dev/github.com/mymmrac/telego)\n[![Telego Docs](https://img.shields.io/static/v1?label=Telego\u0026message=docs\u0026color=8ed6fb\u0026logo=hugo)](https://telego.pixelbox.dev)\n[![Go Version](https://img.shields.io/github/go-mod/go-version/mymmrac/telego?logo=go)](go.mod)\n[![Telegram Bot API Version][TelegramVersionBadge]][TelegramLastVersion]\n\u003cbr\u003e\n[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)\n[![Discussions](https://img.shields.io/github/discussions/mymmrac/telego?color=58a6ff\u0026label=Discussions\u0026logo=github)](https://github.com/mymmrac/telego/discussions)\n[![Telegram Chat](https://img.shields.io/static/v1?label=Discussion\u0026message=chat\u0026color=29a1d4\u0026logo=telegram)](https://t.me/telegoLibrary)\n\n[![CI Status](https://github.com/mymmrac/telego/actions/workflows/ci.yml/badge.svg)](https://github.com/mymmrac/telego/actions/workflows/ci.yml)\n[![Race Testing](https://github.com/mymmrac/telego/actions/workflows/race-tests.yml/badge.svg)](https://github.com/mymmrac/telego/actions/workflows/race-tests.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mymmrac_telego\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=mymmrac_telego)\n[![Go Report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)](https://goreportcard.com/report/github.com/mymmrac/telego)\n\u003cbr\u003e\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=mymmrac_telego\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=mymmrac_telego)\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=mymmrac_telego\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=mymmrac_telego)\n[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=mymmrac_telego\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=mymmrac_telego)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/logo/telego-long.png\" alt=\"Telego logo\" width=\"512px\" style=\"border-radius: 12px;\"\u003e\n\u003c/p\u003e\n\nTelego is Telegram Bot API library for Golang with full [API][TelegramBotAPI] implementation (one-to-one)\n\nThe goal of this library was to create API with the same types and methods as actual Telegram Bot API.\nEvery type and method have been represented in [`types.go`](types.go) and [`methods.go`](methods.go) files with mostly\nall documentation from Telegram.\n\n:warning: Telego is still in v0.x.x version, so do expect breaking changes! :warning:\n\nFor more detailed documentation, see docs at [telego.pixelbox.dev](https://telego.pixelbox.dev).\n\n\u003e Note: Telego uses [fasthttp](https://github.com/valyala/fasthttp) instead of `net/http`\n\u003e and [go-json](https://github.com/goccy/go-json) instead of `encoding/json` by default (both can be changed).\n\n### :clipboard: Table Of Content\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to show • hide\u003c/summary\u003e\n\n- [:zap: Getting Started](#zap-getting-started)\n    - [:jigsaw: Basic setup](#jigsaw-basic-setup)\n    - [:envelope_with_arrow: Getting updates](#envelope_with_arrow-getting-updates)\n    - [:kite: Using Telegram methods](#kite-using-telegram-methods)\n    - [:soap: Utility methods](#soap-utility-methods)\n    - [:mechanical_arm: Helper `With...` methods](#mechanical_arm-helper-with-methods)\n    - [:sun_behind_large_cloud: Bot handlers](#sun_behind_large_cloud-bot-handlers)\n    - [:gear: Build configuration](#gear-build-configuration)\n- [:art: Contribution](#art-contribution)\n- [:star: Stargazers over time](#star-stargazers-over-time)\n- [:closed_lock_with_key: License](#closed_lock_with_key-license)\n\n\u003c/details\u003e\n\n## :zap: Getting Started\n\nHow to get the library:\n\n```shell\ngo get github.com/mymmrac/telego\n```\n\nMake sure you get the latest version to have all new features \u0026 fixes.\n\nMore examples can be seen here:\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to show • hide\u003c/summary\u003e\n\n- [Basic](examples/basic/main.go)\n- [Configuration](examples/configuration/main.go)\n- [Methods](examples/methods/main.go)\n- [Updates (long polling)](examples/updates_long_polling/main.go)\n- [Updates (webhook)](examples/updates_webhook/main.go)\n- [Ngrok webhook](examples/ngrok/main.go)\n- [Echo bot](examples/echo_bot/main.go)\n- [Echo bot (with handlers)](examples/echo_bot_with_handlers/main.go)\n- [Echo bot (handlers + webhook + graceful shutdown + docker)](https://github.com/mymmrac/echo-bot)\n- [Conversation bot (state machine)](examples/conversation_bot/main.go)\n- [Sending files (documents, photos, media groups)](examples/sending_files/main.go)\n- [Downloading files](examples/download_file/main.go)\n- [Inline keyboard](examples/inline_keyboard/main.go)\n- [Keyboard](examples/keyboard/main.go)\n- [Edit message](examples/edit_message/main.go)\n- [Utility methods](examples/utility_methods/main.go)\n- [Inline query bot](examples/inline_query_bot/main.go)\n- [Bot handlers](examples/handler/main.go)\n- [Bot handles (groups + middleware)](examples/handler_groups_and_middleware/main.go)\n- [Update's context](examples/handler_with_context/main.go)\n- [Graceful shutdown (no helpers)](examples/graceful_shutdown_no_helpers/main.go)\n- [Graceful shutdown (long polling)](examples/graceful_shutdown_long_polling/main.go)\n- [Graceful shutdown (webhook)](examples/graceful_shutdown_webhook/main.go)\n- [Custom predicates for handlers](examples/handler_custom/main.go)\n- [Handler ordering](examples/handler_ordering/main.go)\n- [Specific handlers](examples/handler_specific/main.go)\n- [Predicate as middleware](examples/middleware_with_predicates/main.go)\n- [Update processor](examples/update_processor/main.go)\n- [Message entities](examples/message_entity/main.go)\n- [Multi bot webhook](examples/multi_bot_webhook/main.go)\n- [Retry caller](examples/retry_caller/main.go)\n- [Menu bot](examples/menu_bot/main.go)\n- [Test server](examples/test_server/main.go)\n\n\u003c/details\u003e\n\n\u003e Note: Error handling may be missing in examples, but I strongly recommend handling all errors.\n\nGenerally, useful information about Telegram Bots and their features:\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to show • hide\u003c/summary\u003e\n\n- [:page_facing_up: Telegram Bot API](https://core.telegram.org/bots/api) • Telegram documentation of Bot API (full\n  reference)\n- [:jigsaw: Telegram Bot Fundamentals](https://core.telegram.org/bots) • Bots: An introduction for developers\n- [:star2: Telegram Bot Features](https://core.telegram.org/bots/features) • Describes individual bot elements and\n  features in detail\n- [:headphones: Telegram Bot Webhooks](https://core.telegram.org/bots/webhooks) • Marvin's Marvellous Guide to All\n  Things Webhook\n- [:moneybag: Telegram Bot Payments](https://core.telegram.org/bots/payments) • Describes payment system and payment\n  lifecycle\n- [:iphone: Telegram Bot WebApps](https://core.telegram.org/bots/webapps) • Describes WebApps and interactions with them\n- [:link: Ngrok](https://ngrok.com) • Connect localhost to the Internet\n- [:shield: Let's Encrypt](https://letsencrypt.org) • TLS certificates for free\n\n\u003c/details\u003e\n\n### :jigsaw: Basic setup\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nFor start, you need to create an instance of your bot and\nspecify [token](https://core.telegram.org/bots/api#authorizing-your-bot).\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mymmrac/telego\"\n)\n\nfunc main() {\n\t// Get Bot token from environment variables\n\tbotToken := os.Getenv(\"TOKEN\")\n\n\t// Create bot and enable debugging info\n\t// Note: Please keep in mind that default logger may expose sensitive information,\n\t// use in development only\n\t// (more on configuration in examples/configuration/main.go)\n\tbot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Call method getMe (https://core.telegram.org/bots/api#getme)\n\tbotUser, err := bot.GetMe()\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t}\n\n\t// Print Bot information\n\tfmt.Printf(\"Bot user: %+v\\n\", botUser)\n}\n```\n\n### :envelope_with_arrow: Getting updates\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nIn order to receive updates, you can use one of two methods:\n\n- using long polling (`bot.UpdatesViaLongPolling`)\n- using webhook (`bot.UpdatesViaWebhook`)\n\nLet's start from long polling (easier for local testing):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mymmrac/telego\"\n)\n\nfunc main() {\n\tbotToken := os.Getenv(\"TOKEN\")\n\n\t// Note: Please keep in mind that default logger may expose sensitive information,\n\t// use in development only\n\tbot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Get updates channel\n\t// (more on configuration in examples/updates_long_polling/main.go)\n\tupdates, _ := bot.UpdatesViaLongPolling(nil)\n\n\t// Stop reviving updates from update channel\n\tdefer bot.StopLongPolling()\n\n\t// Loop through all updates when they came\n\tfor update := range updates {\n\t\tfmt.Printf(\"Update: %+v\\n\", update)\n\t}\n}\n```\n\nWebhook example (recommended way):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mymmrac/telego\"\n)\n\nfunc main() {\n\tbotToken := os.Getenv(\"TOKEN\")\n\n\t// Note: Please keep in mind that default logger may expose sensitive information,\n\t// use in development only\n\tbot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Set up a webhook on Telegram side\n\t_ = bot.SetWebhook(\u0026telego.SetWebhookParams{\n\t\tURL: \"https://example.com/bot\" + bot.Token(),\n\t})\n\n\t// Receive information about webhook\n\tinfo, _ := bot.GetWebhookInfo()\n\tfmt.Printf(\"Webhook Info: %+v\\n\", info)\n\n\t// Get an update channel from webhook.\n\t// (more on configuration in examples/updates_webhook/main.go)\n\tupdates, _ := bot.UpdatesViaWebhook(\"/bot\" + bot.Token())\n\n\t// Start server for receiving requests from the Telegram\n\tgo func() {\n\t\t_ = bot.StartWebhook(\"localhost:443\")\n\t}()\n\n\t// Stop reviving updates from update channel and shutdown webhook server\n\tdefer func() {\n\t\t_ = bot.StopWebhook()\n\t}()\n\n\t// Loop through all updates when they came\n\tfor update := range updates {\n\t\tfmt.Printf(\"Update: %+v\\n\", update)\n\t}\n}\n```\n\nFor running multiple bots from a single server, see [this](examples/multi_bot_webhook/main.go) example.\n\n\u003e Tip: For testing webhooks, you can use [Ngrok](https://ngrok.com) to make a tunnel to your localhost,\n\u003e and get a random domain available from the Internet.\n\u003e It's as simple as `ngrok http 8080`.\n\u003e Or follow [Telego + Ngrok example](examples/ngrok/main.go) using [ngrok/ngrok-go](https://github.com/ngrok/ngrok-go)\n\u003e for most convenient bot testing.\n\n\u003e Tip: You may wish to use [Let's Encrypt](https://letsencrypt.org) in order to generate your free TLS certificate.\n\n### :kite: Using Telegram methods\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nAll Telegram Bot API methods described in [documentation](https://core.telegram.org/bots/api#available-methods) can be\nused by the library. They have the same names and the same parameters, parameters represented by struct with\nname: `\u003cmethodName\u003e` + `Params`. If method doesn't have required parameters `nil` value can be used as a parameter.\n\n\u003e Note: [`types.go`](types.go) and [`methods.go`](methods.go) were automatically [generated](internal/generator)\n\u003e from [documentation][TelegramBotAPI], and it's possible that they have errors or missing parts both in comments and\n\u003e actual code. Feel free to report such things.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mymmrac/telego\"\n\ttu \"github.com/mymmrac/telego/telegoutil\"\n)\n\nfunc main() {\n\tbotToken := os.Getenv(\"TOKEN\")\n\n\t// Note: Please keep in mind that default logger may expose sensitive information,\n\t// use in development only\n\tbot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Call method getMe\n\tbotUser, _ := bot.GetMe()\n\tfmt.Printf(\"Bot User: %+v\\n\", botUser)\n\n\tupdates, _ := bot.UpdatesViaLongPolling(nil)\n\tdefer bot.StopLongPolling()\n\n\tfor update := range updates {\n\t\tif update.Message != nil {\n\t\t\t// Retrieve chat ID\n\t\t\tchatID := update.Message.Chat.ID\n\n\t\t\t// Call method sendMessage.\n\t\t\t// Send a message to sender with the same text (echo bot).\n\t\t\t// (https://core.telegram.org/bots/api#sendmessage)\n\t\t\tsentMessage, _ := bot.SendMessage(\n\t\t\t\ttu.Message(\n\t\t\t\t\ttu.ID(chatID),\n\t\t\t\t\tupdate.Message.Text,\n\t\t\t\t),\n\t\t\t)\n\n\t\t\tfmt.Printf(\"Sent Message: %v\\n\", sentMessage)\n\t\t}\n\t}\n}\n```\n\n### :soap: Utility methods\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nIn Telego even though you have all [`types`](types.go) and [`methods`](methods.go) available, it's often not so\nconvenient to use them directly. To solve this issues [`telegoutil`](telegoutil) package was created. It contains\nutility-helper function that will make your life a bit easier.\n\nI suggest including it with alias to get cleaner code:\n\n```go\nimport tu \"github.com/mymmrac/telego/telegoutil\"\n```\n\nThe package contains couple methods for creating send parameters with all required parameters like:\n\n- `Message(chatID, text) =\u003e SendMessageParams`\n- `Photo(chatID, photoFile) =\u003e SendPhotoParams`\n- `Location(chatID, latitude, longitude) =\u003e SendLocationParams`\n- ...\n\nOr other useful methods like:\n\n- `ID(intID) =\u003e ChatID`\n- `File(namedReader) =\u003e InputFile`\n- ...\n\nUtils related to [`methods`](methods.go) can be found in [`telegoutil/methods`](telegoutil/methods.go), for\n[`types`](types.go) in [`telegoutil/types`](telegoutil/types.go), for [`handlers`](telegohandler/bot_handler.go) in\n[`telegoutil/handler`](telegoutil/handler.go), for [`api`](telegoapi/api.go) in [`telegoutil/api`](telegoutil/api.go).\n\n\u003e Note: If you think that something can be added to [`telegoutil`](telegoutil) package\n\u003e fill free to create an issue or pull request with desired changes.\n\n### :mechanical_arm: Helper `With...` methods\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nCreating method parameters is sometimes bulky and not convenient, so you can use `with` methods in combination with\n`utility` methods.\n\nHere is a simple example of creating a message with a keyboard that has 4 buttons with different parameters.\n\n```go\npackage main\n\nimport (\n\t\"github.com/mymmrac/telego\"\n\ttu \"github.com/mymmrac/telego/telegoutil\"\n)\n\nfunc main() {\n\t// ... initializing bot (full example in examples/keyboard/main.go)\n\n\t// Creating keyboard\n\tkeyboard := tu.Keyboard(\n\t\ttu.KeyboardRow( // Row 1\n\t\t\t// Column 1\n\t\t\ttu.KeyboardButton(\"Button\"),\n\n\t\t\t// Column 2, `with` method\n\t\t\ttu.KeyboardButton(\"Poll Regular\").\n\t\t\t\tWithRequestPoll(tu.PollTypeRegular()),\n\t\t),\n\t\ttu.KeyboardRow( // Row 2\n\t\t\t// Column 1, `with` method \n\t\t\ttu.KeyboardButton(\"Contact\").WithRequestContact(),\n\n\t\t\t// Column 2, `with` method \n\t\t\ttu.KeyboardButton(\"Location\").WithRequestLocation(),\n\t\t),\n\t).WithResizeKeyboard().WithInputFieldPlaceholder(\"Select something\")\n\t// Multiple `with` methods can be chained\n\n\t// Creating message\n\tmsg := tu.Message(\n\t\ttu.ID(123),\n\t\t\"Hello World\",\n\t).WithReplyMarkup(keyboard).WithProtectContent() // Multiple `with` method \n\n\tbot.SendMessage(msg)\n}\n```\n\nThose methods allow you to modify values without directly accessing them, also as you saw `with` methods can be staked\none to another in order to update multiple values.\n\n### :sun_behind_large_cloud: Bot handlers\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nProcessing updates just in for loop is not the most pleasing thing to do, so Telego provides `net/http` like handlers,\nbut instead of the path, you provide predicates.\n\nOne update will only match to the first handler whose predicates are satisfied, predicates checked in order of handler\nregistration (it's useful to first specify the most specific predicates and then more general).\n\nAlso, all handlers (but not their predicates) are processed in parallel.\n\nI suggest including it with alias to get cleaner code:\n\n```go\nimport th \"github.com/mymmrac/telego/telegohandler\"\n```\n\nHere is an example of using handlers with long polling updates.\nYou can see the full list of available predicates in [`telegohandler/predicates`](telegohandler/predicates.go),\nor define your own.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mymmrac/telego\"\n\tth \"github.com/mymmrac/telego/telegohandler\"\n\ttu \"github.com/mymmrac/telego/telegoutil\"\n)\n\nfunc main() {\n\tbotToken := os.Getenv(\"TOKEN\")\n\n\t// Note: Please keep in mind that default logger may expose sensitive information,\n\t// use in development only\n\tbot, err := telego.NewBot(botToken, telego.WithDefaultDebugLogger())\n\tif err != nil {\n\t\tfmt.Println(err)\n\t\tos.Exit(1)\n\t}\n\n\t// Get updates channel\n\tupdates, _ := bot.UpdatesViaLongPolling(nil)\n\n\t// Create bot handler and specify from where to get updates\n\tbh, _ := th.NewBotHandler(bot, updates)\n\n\t// Stop handling updates\n\tdefer bh.Stop()\n\n\t// Stop getting updates\n\tdefer bot.StopLongPolling()\n\n\t// Register new handler with match on command `/start`\n\tbh.Handle(func(bot *telego.Bot, update telego.Update) {\n\t\t// Send message\n\t\t_, _ = bot.SendMessage(tu.Message(\n\t\t\ttu.ID(update.Message.Chat.ID),\n\t\t\tfmt.Sprintf(\"Hello %s!\", update.Message.From.FirstName),\n\t\t))\n\t}, th.CommandEqual(\"start\"))\n\n\t// Register new handler with match on any command\n\t// Handlers will match only once and in order of registration, \n\t// so this handler will be called on any command except `/start` command\n\tbh.Handle(func(bot *telego.Bot, update telego.Update) {\n\t\t// Send message\n\t\t_, _ = bot.SendMessage(tu.Message(\n\t\t\ttu.ID(update.Message.Chat.ID),\n\t\t\t\"Unknown command, use /start\",\n\t\t))\n\t}, th.AnyCommand())\n\n\t// Start handling updates\n\tbh.Start()\n}\n```\n\nAlso, just handling updates is useful, but handling specific updates like messages or callback queries in most of the\ncases are more straightforward and provides cleaner code.\n\nSo Telego provides specific handles for all fields of `telego.Update`. See the list of all available handler types in\n[`telegohandler/update_handlers`](telegohandler/update_handlers.go), or define your own.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mymmrac/telego\"\n\tth \"github.com/mymmrac/telego/telegohandler\"\n\ttu \"github.com/mymmrac/telego/telegoutil\"\n)\n\nfunc main() {\n\t// ... initializing bot and bot handler \n\t// (full example in examples/handler_specific/main.go)\n\n\t// Register new handler with match on command `/start`\n\tbh.HandleMessage(func(bot *telego.Bot, message telego.Message) {\n\t\t// Send a message with inline keyboard\n\t\t_, _ = bot.SendMessage(tu.Message(\n\t\t\ttu.ID(message.Chat.ID),\n\t\t\tfmt.Sprintf(\"Hello %s!\", message.From.FirstName),\n\t\t).WithReplyMarkup(tu.InlineKeyboard(\n\t\t\ttu.InlineKeyboardRow(\n\t\t\t\ttu.InlineKeyboardButton(\"Go!\").WithCallbackData(\"go\"),\n\t\t\t)),\n\t\t))\n\t}, th.CommandEqual(\"start\"))\n\n\t// Register new handler with match on the call back query \n\t// with data equal to `go` and non-nil message\n\tbh.HandleCallbackQuery(func(bot *telego.Bot, query telego.CallbackQuery) {\n\t\t// Send message\n\t\t_, _ = bot.SendMessage(tu.Message(tu.ID(query.Message.Chat.ID), \"GO GO GO\"))\n\n\t\t// Answer callback query\n\t\t_ = bot.AnswerCallbackQuery(tu.CallbackQuery(query.ID).WithText(\"Done\"))\n\t}, th.AnyCallbackQueryWithMessage(), th.CallbackDataEqual(\"go\"))\n\n\t// ... start bot handler\n}\n```\n\nOne more important part of handlers are groups and middlewares.\nTelego allows creating groups with and without predicates and attaching middleware to groups.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/mymmrac/telego\"\n\tth \"github.com/mymmrac/telego/telegohandler\"\n)\n\nfunc main() {\n\t// Init ...\n\n\t// Add global middleware, it will be applied in order of addition\n\tbh.Use(func(bot *telego.Bot, update telego.Update, next th.Handler) {\n\t\tfmt.Println(\"Global middleware\") // Will be called first\n\t\tnext(bot, update)\n\t})\n\n\t// Create any groups with or without predicates\n\t// Note: Updates first checked by groups and only then by handlers \n\t// (group -\u003e ... -\u003e group -\u003e handler)\n\ttask := bh.Group(th.TextContains(\"task\"))\n\n\t// Add middleware to groups\n\ttask.Use(func(bot *telego.Bot, update telego.Update, next th.Handler) {\n\t\tfmt.Println(\"Group-based middleware\") // Will be called second\n\n\t\tif len(update.Message.Text) \u003c 10 {\n\t\t\tnext(bot, update)\n\t\t}\n\t})\n\n\t// Handle updates on a group\n\ttask.HandleMessage(func(bot *telego.Bot, message telego.Message) {\n\t\tfmt.Println(\"Task...\") // Will be called third\n\t})\n}\n\n```\n\n### :gear: Build configuration\n\n[▲ Go Up ▲](#telego--go-telegram-bot-api)\n\nTelego supports multiple build configurations via Go's build tags\n(right now only to change JSON encoding/decoding library):\n\n- No tags - use [goccy/go-json](https://github.com/goccy/go-json)\n- `sonic` - use [bytedance/sonic](https://github.com/bytedance/sonic)\n- `stdjson` - use `encoding/json`\n\n\u003e Note: Use `sonic` only on supported platforms as it has its own limitations, more\n\u003e [here](https://github.com/bytedance/sonic?tab=readme-ov-file#requirement).\n\n## :art: Contribution\n\nContribution guidelines listed [here](docs/CONTRIBUTING.md).\n\n## :star: Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/mymmrac/telego.svg)](https://starchart.cc/mymmrac/telego)\n\n\u003e Powered by [caarlos0/starcharts](https://github.com/caarlos0/starcharts)\n\n## :closed_lock_with_key: License\n\nTelego is distributed under [MIT licence](LICENSE).\n\n[TelegramBotAPI]: https://core.telegram.org/bots/api\n\n[TelegramVersionBadge]: https://img.shields.io/static/v1?label=Supported%20Telegram%20Bot%20API\u0026color=29a1d4\u0026logo=telegram\u0026message=v7.10\n\n[TelegramLastVersion]: https://core.telegram.org/bots/api#september-6-2024\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmymmrac%2Ftelego","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmymmrac%2Ftelego","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmymmrac%2Ftelego/lists"}