{"id":30478606,"url":"https://github.com/johnspade/tgbot-utils","last_synced_at":"2025-08-24T11:20:43.048Z","repository":{"id":57742717,"uuid":"334691480","full_name":"johnspade/tgbot-utils","owner":"johnspade","description":"Collection of utilities for building Telegram bots in Scala","archived":false,"fork":false,"pushed_at":"2024-06-20T18:00:52.000Z","size":70,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-23T09:57:58.024Z","etag":null,"topics":["cats","scala","telegram","telegram-bot","telegram-bots","telegram-bots-api"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/johnspade.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-31T15:43:31.000Z","updated_at":"2025-01-07T12:35:30.000Z","dependencies_parsed_at":"2024-06-20T12:22:55.459Z","dependency_job_id":null,"html_url":"https://github.com/johnspade/tgbot-utils","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/johnspade/tgbot-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnspade%2Ftgbot-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnspade%2Ftgbot-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnspade%2Ftgbot-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnspade%2Ftgbot-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johnspade","download_url":"https://codeload.github.com/johnspade/tgbot-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johnspade%2Ftgbot-utils/sbom","scorecard":{"id":529032,"data":{"date":"2025-08-11","repo":{"name":"github.com/johnspade/tgbot-utils","commit":"f599ba29646e4cf456cf887c9f284d1c0df25f1d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:30: update your workflow using https://app.stepsecurity.io/secureworkflow/johnspade/tgbot-utils/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/johnspade/tgbot-utils/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/johnspade/tgbot-utils/ci.yml/master?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Warn: no topLevel permission defined: .github/workflows/clean.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-20T05:16:11.155Z","repository_id":57742717,"created_at":"2025-08-20T05:16:11.155Z","updated_at":"2025-08-20T05:16:11.155Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271852231,"owners_count":24834114,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["cats","scala","telegram","telegram-bot","telegram-bots","telegram-bots-api"],"created_at":"2025-08-24T11:20:40.418Z","updated_at":"2025-08-24T11:20:43.032Z","avatar_url":"https://github.com/johnspade.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tgbot-utils\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/ru.johnspade/tgbot-utils_3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/ru.johnspade/tgbot-utils_3)\n\nCollection of extensions for [Telegramium](https://github.com/apimorphism/telegramium) \n(a pure functional Telegram Bot API implementation for Scala) that I use to build my bots.\n\n# Setup\n\ntgbot-utils is currently available for Scala 3.\n\nWhole utils pack:\n\n```scala\nlibraryDependencies += \"ru.johnspade\" %% \"tgbot-utils\" % \"\u003clatest version in badge\u003e\"\n```\nA specific module:\n```scala\nlibraryDependencies += \"ru.johnspade\" %% \"\u003cmodule name\u003e\" % \"\u003clatest version in badge\u003e\"\n```\n\n## tgbot-callback-data\n\nRepresent your callback query data types as an ADT and use [csv3s](https://github.com/johnspade/csv3s) \nto (de)serialize them to CSV strings.\n\n```scala\nimport ru.johnspade.csv3s.codecs.*\nimport ru.johnspade.csv3s.codecs.instances.given\nimport ru.johnspade.csv3s.parser.*\nimport ru.johnspade.csv3s.printer.CsvPrinter\n\nimport ru.johnspade.tgbot.callbackdata.named.*\nimport ru.johnspade.tgbot.callbackqueries.*\n\nsealed abstract class CallbackData {\n  import CallbackData.{encoder, csvPrinter}\n\n  def toCsv: String = csvPrinter.print(encoder.encode(this))\n}\n\nfinal case class BuyIcecream(flavor: String) extends CallbackData\ncase object SayHello extends CallbackData\n\nobject CallbackData {\n  given encoder: RowEncoder[CallbackData] = MagnoliaRowEncoder.derived\n  given decoder: RowDecoder[CallbackData] = MagnoliaRowDecoder.derived\n\n  val Separator: Char = ','\n  private val csvParser = new CsvParser(Separator)\n  val csvPrinter: CsvPrinter = CsvPrinter.withSeparator(Separator)\n\n  def decode(csv: String): Either[DecodeFailure, CallbackData] =\n    parseRow(csv, csvParser).left\n      .map(e =\u003e ru.johnspade.tgbot.callbackqueries.ParseError(e.toString))\n      .flatMap(\n        decoder\n          .decode(_)\n          .left\n          .map { e =\u003e\n            ru.johnspade.tgbot.callbackqueries.DecodeError(e.getMessage)\n          }\n      )\n}\n\nval csv = BuyIcecream(\"vanilla\").toCsv\n// BuyIceCream,vanilla\n\nval callbackData = CallbackData.decode(csv).getOrElse(sys.error(\"\"))\n// BuyIcecream(vanilla)\n```\n\n## tgbot-callback-queries\n\n[http4s](https://github.com/http4s/http4s) -like DSL to handle callback queries.\n\n```scala\nimport cats.effect.IO\nimport ru.johnspade.tgbot.callbackqueries.CallbackQueryDsl._\nimport ru.johnspade.tgbot.callbackqueries.CallbackQueryRoutes\nimport telegramium.bots.client.Method\n\nval routes = CallbackQueryRoutes.of[CallbackData, Option[Method[_]], IO] {\n  case BuyIcecream(flavor) in cb =\u003e\n    IO {\n      println(s\"${cb.from.firstName} have chosen: $flavor\")\n      None\n    }\n}\n```\n\nExtract and use context information from callback queries with `CallbackQueryContextRoutes`:\n\n```scala\nimport cats.effect.IO\nimport ru.johnspade.tgbot.callbackqueries.CallbackQueryDsl._\nimport ru.johnspade.tgbot.callbackqueries.CallbackQueryContextRoutes\nimport telegramium.bots.high.Methods\n\ncase class User(id: Int, firstName: String, language: String)\n\nval contextRoutes = CallbackQueryContextRoutes.of[CallbackData, User, Option[Method[_]], IO] {\n  case SayHello in cb as user =\u003e\n    IO {\n      Some(Methods.answerCallbackQuery(cb.id, text = Some(s\"Hello, ${user.firstName}\")))\n    }\n}\n```\n\nWe use `CallbackQueryContextMiddleware` for that:\n\n```scala\nimport cats.data.{Kleisli, OptionT}\nimport ru.johnspade.tgbot.callbackqueries.{CallbackQueryContextMiddleware, CallbackQueryData, ContextCallbackQuery}\n\nval userMiddleware: CallbackQueryContextMiddleware[CallbackData, User, Option[Method[_]], IO] =\n  _.compose(\n    Kleisli { (cb: CallbackQueryData[CallbackData]) =\u003e\n      val from = cb.cb.from\n      val user = User(from.id, from.firstName, from.languageCode.getOrElse(\"en\"))\n      OptionT.liftF(IO(ContextCallbackQuery(user, cb)))\n    }\n  )\n```\n\nCombine multiple routes with `\u003c+\u003e` (`combineK`) and handle queries with `CallbackQueryHandler`:\n\n```scala\nimport cats.syntax.semigroupk._\nimport cats.syntax.either._\nimport ru.johnspade.tgbot.callbackqueries.{CallbackQueryHandler, CallbackDataDecoder, ParseError, DecodeError}\n\nval allRoutes = routes \u003c+\u003e userMiddleware(contextRoutes)\n\nprivate val cbDataDecoder: CallbackDataDecoder[IO, CallbackData] =\n  CallbackData.decode(_).left.map {\n    case error: kantan.csv.ParseError =\u003e ParseError(error.getMessage)\n    case error: kantan.csv.DecodeError =\u003e DecodeError(error.getMessage)\n  }\n    .toEitherT[IO]\n\n// query: CallbackQuery\n\nval handler = CallbackQueryHandler.handle(\n  query,\n  routes = allRoutes,\n  decoder = cbDataDecoder, \n  onNotFound = _ =\u003e IO(Option.empty[Method[_]])\n)\n```\n\n## tgbot-message-entities\n\n**REMOVED**: It is now a part of [Telegramium](https://github.com/apimorphism/telegramium) and has been removed.\n\n# Usages\n\n- [s10ns_bot](https://github.com/johnspade/s10ns_bot) – Subscription Management Telegram Bot\n- [Taskobot](https://github.com/johnspade/taskobot-scala) – task collaboration inline Telegram bot \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnspade%2Ftgbot-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohnspade%2Ftgbot-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohnspade%2Ftgbot-utils/lists"}