{"id":37106264,"url":"https://github.com/vitaliy-ukiru/telebot-filter","last_synced_at":"2026-01-14T12:48:24.878Z","repository":{"id":228506256,"uuid":"773961014","full_name":"vitaliy-ukiru/telebot-filter","owner":"vitaliy-ukiru","description":"Is addon for telebot module with support filters","archived":false,"fork":false,"pushed_at":"2025-03-15T15:15:59.000Z","size":136,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"dev/v2","last_synced_at":"2025-05-20T10:02:44.789Z","etag":null,"topics":["go-telebot-utils","golang-telebot-utils","golang-telegram-bot","telebot","telebot-utils"],"latest_commit_sha":null,"homepage":"","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/vitaliy-ukiru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-03-18T17:43:36.000Z","updated_at":"2025-03-15T15:04:37.000Z","dependencies_parsed_at":"2024-06-21T12:54:12.893Z","dependency_job_id":"e78976c1-d789-45f1-9833-84c822c897ab","html_url":"https://github.com/vitaliy-ukiru/telebot-filter","commit_stats":null,"previous_names":["vitaliy-ukiru/telebot-filter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vitaliy-ukiru/telebot-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitaliy-ukiru%2Ftelebot-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitaliy-ukiru%2Ftelebot-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitaliy-ukiru%2Ftelebot-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitaliy-ukiru%2Ftelebot-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitaliy-ukiru","download_url":"https://codeload.github.com/vitaliy-ukiru/telebot-filter/tar.gz/refs/heads/dev/v2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitaliy-ukiru%2Ftelebot-filter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28420814,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["go-telebot-utils","golang-telebot-utils","golang-telegram-bot","telebot","telebot-utils"],"created_at":"2026-01-14T12:48:24.137Z","updated_at":"2026-01-14T12:48:24.871Z","avatar_url":"https://github.com/vitaliy-ukiru.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# telebot-filter\n\u003c!-- TOC --\u003e\n* [telebot-filter](#telebot-filter)\n* [Motivation](#motivation)\n* [Quick Start](#quick-start)\n  * [Install module](#install-module)\n  * [Select flow](#select-flow)\n    * [Package dispatcher](#package-dispatcher)\n      * [Make base setup](#make-base-setup)\n      * [Setups handlers](#setups-handlers)\n      * [Add middlewares](#add-middlewares)\n    * [Package routing](#package-routing)\n      * [Setups handlers](#setups-handlers-1)\n      * [Add middlewares](#add-middlewares-1)\n  * [Execute bot](#execute-bot)\n* [Migrate to v2](#migrate-to-v2)\n  * [Get new telebot version](#get-new-telebot-version)\n  * [Delete builder usage](#delete-builder-usage)\n  * [Delete multibot usage](#delete-multibot-usage)\n  * [Update RawHandler bindings](#update-rawhandler-bindings)\n* [Technical information](#technical-information)\n\u003c!-- TOC --\u003e\n# Motivation\n\nThis module provides use telebot module but with filters\nand upgraded middlewares system.\n\nThe module is also compatible with standard handlers.\nProvided that their end points do not intersect with\nendpoints of this module.\n\n# Quick Start\n\n## Install module\n\n```\ngo get github.com/vitaliy-ukiru/telebot-filter/v2\n```\n\n## Select flow\n\nYou can use different method to register handlers.\nThese methods separated into packages\n\n- dispatcher\n- routing\n\nYou can use both package in one program, but endpoints\nmust not intersect.\nThe packages do not monitor this behavior.\n\nRead more about their differences and features [here](./TECHNICAL.md).\n\nI'll show API of both packages.\n\n### Package dispatcher\n\n#### Make base setup\n\n```go\n\npackage main\n\nimport (\n\t\"os\"\n\n\t\"github.com/vitaliy-ukiru/telebot-filter/v2/dispatcher\"\n\ttb \"gopkg.in/telebot.v4\"\n)\n\nfunc main() {\n\tbot, err := tb.NewBot(tb.Settings{\n\t\tToken: os.Getenv(\"BOT_TOKEN\"),\n\t})\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tdp := dispatcher.NewDispatcher(\n\t\t// creating group, because the dispatcher\n\t\t// does not need access to the bot.\n\t\tbot.Group(),\n\t)\n}\n```\n\n#### Setups handlers\n\n\u003cdetails\u003e\n\u003csummary\u003eMost likely telebot method\u003c/summary\u003e\n\n```go\ndp.Handle(\n    \"/start\",\n    telefilter.NewRawHandler(   \n        func(c tb.Context) error {\n            return c.Send(\"Hi\")\n        },\n        // filters list\n        func(c tb.Context) bool {\n            return c.Message().Chat.Type == tb.ChatPrivate\n        },\n    ),\n    /* middlewares like in telebot*/\n)\n```\n\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003eUsing low-level interface\u003c/summary\u003e\n\n```go\ndp.Dispatch(\n    telefilter.NewRoute(\n        telefilter.NewRawHandler(\n            tb.OnDocument,\n            func (c tb.Context) error {\n                return c.Send(\"I'll read this document later\")\n            },\n            // filter\n            func (c tb.Context) bool {\n                doc := c.Message().Document\n                return doc.MIME == \"plain/text\"\n            },\n        ),\n        // middlewares\n        middleware.Whitelist(\n            CoolChatID,\n        ),\n    ),\n)\n```\n\nUgly? may be. But you don't use this in normal code.\n\u003c/details\u003e\n\n#### Add middlewares\n\nYou can add middleware to router object, handler and endpoint.\n\n```go\nvar dp *Dispatcher\n\ndp.UseOn(endpoint, middleware) // middlewares for all handler at endpoint.\n\ndp.Use() // middleware to root router.\n\nrouter := dp.NewRouter()\nrouter.Use() // middlewares only for this router's handlers.\n\nrouter.Handle(handler, middleware) // middleware only for handler.\n\n```\n\n### Package routing\n\nSimplest way:\n\n```go\nbot.Handle(tele.OnText, routing.New(\n    tf.NewRawHandler(\n        handleHi,\n        filterHiText,\n    ),\n    tf.NewRawHandler(\n        handleWakeUpInGroup,\n        filters.All(\n            filterGroup,\n            filterWakeUpText,\n        ),\n    )\n))\n```\n\nAlternative. With this method you can add handlers in runtime.\n\n```go\n\nroute := new(routing.Route)\n\nroute.Add(handlerStartAtFirstTime)\nroute.Add(handlerStartInGroup)\nrouter.Add(handlerDeeplink)\n\nbot.Handle(\"/start\", route.Handler)\nroute.Add(handlerStartTwice) // it will added in route\n\n```\n\n\n#### Setups handlers\n```go\nbot.Handle(\n    \"/start\",\n    routing.New(\n        // deeplink handler\n        // deeplink is URL t.me/\u003cbot_username\u003e/start=\u003cdeeplink\u003e\n        // that converted like /start \u003cdeeplink\u003e\n        // more into at https://core.telegram.org/api/links#bot-links\n        tf.NewRawHandler(\n            func(c tb.Context) error {\n                deeplink := c.Message().Payload\n                return c.Send(\"You deeplink: \" + deeplink)\n            },\n\n            func(c tb.Context) bool {\n                return c.Message().Payload != \"\"\n            },\n        ),\n\n        // base handler without filter\n        tf.NewRawHandler(func (c tb.Context) error {\n            return c.Send(\"Hi!\")\n        }, nil),\n    ),\n    userDatabaseMiddleware,\n)\n```\n\n**Please note that the order in which handlers are registered is important!**\nWith a different order, we would not have been able to even reach the deeplink filter,\nbecause a basic handler without filters would immediately mark the event as matched.\n\n#### Add middlewares\n\nYou can add middlewares only manually like in default telebot.\n\n## Execute bot\n\nJust like in telebot\n\n```go\nbot.Start()\n```\n\n# Migrate to v2\n\nBreaking changes:\n\n1. Telebot version bumped to v4\n2. Deleted dispatcher.Builder\n3. Deleted pkg/multibot\n4. Changed filter type in telefilter.RawHandler\n\n## Get new telebot version\nYou need upgrade your project to telebot v4. It's main change.\n\n## Delete builder usage\n\nFind dispatcher.Builder usages in your code and replace it to another\nmethod.\n\n## Delete multibot usage\nSimple implementation of multibot no longer available.\n\n## Update RawHandler bindings\nField 'Filters' removed, and replaced by field 'Filter'.\n\n```diff\ntype RawHandler struct {\n-\tFilters   []Filter\n+\tFilter   Filter\n\tCallback tb.HandlerFunc\n}\n```\n\nAlso changed signature of NewRawHandler. \nIt requires to provide filter in any case.\n\nIf you need use many filters you must use `pkg/filters.All` or `pkg/filters.Any`\n\n\n# Technical information\n\nFor more information about internals see [this document](TECHNICAL.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitaliy-ukiru%2Ftelebot-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitaliy-ukiru%2Ftelebot-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitaliy-ukiru%2Ftelebot-filter/lists"}