{"id":15010336,"url":"https://github.com/akeboshiwind/tg-clj","last_synced_at":"2025-10-10T20:07:50.737Z","repository":{"id":225491317,"uuid":"766104602","full_name":"Akeboshiwind/tg-clj","owner":"Akeboshiwind","description":"A telegram bot api wrapper inspired by aws-api","archived":false,"fork":false,"pushed_at":"2025-08-09T19:23:48.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-11T08:06:34.000Z","etag":null,"topics":["clojure","telegram","telegram-bot","telegram-bot-api","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/Akeboshiwind.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2024-03-02T10:56:34.000Z","updated_at":"2025-08-09T19:23:51.000Z","dependencies_parsed_at":"2024-10-12T10:20:34.890Z","dependency_job_id":"890da03f-58e0-4a0c-9540-be116d4744fc","html_url":"https://github.com/Akeboshiwind/tg-clj","commit_stats":null,"previous_names":["akeboshiwind/tg-clj"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Akeboshiwind/tg-clj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akeboshiwind%2Ftg-clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akeboshiwind%2Ftg-clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akeboshiwind%2Ftg-clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akeboshiwind%2Ftg-clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Akeboshiwind","download_url":"https://codeload.github.com/Akeboshiwind/tg-clj/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akeboshiwind%2Ftg-clj/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005261,"owners_count":26083860,"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-10-10T02:00:06.843Z","response_time":62,"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":["clojure","telegram","telegram-bot","telegram-bot-api","wrapper"],"created_at":"2024-09-24T19:33:38.050Z","updated_at":"2025-10-10T20:07:50.732Z","avatar_url":"https://github.com/Akeboshiwind.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tg-clj\n\nA simple-as-possible telegram bot api client inspired by [aws-api](https://github.com/cognitect-labs/aws-api).\n\n\u003cp\u003e\n  \u003ca href=\"#installation\"\u003eInstallation\u003c/a\u003e |\n  \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e |\n  \u003ca href=\"#handling-updates\"\u003eHandling Updates\u003c/a\u003e |\n  \u003ca href=\"https://github.com/Akeboshiwind/tg-clj-server\"\u003etg-clj-server\u003c/a\u003e\n\u003c/p\u003e\n\n\n\n## Why\n\nThis library gets out of the way so you can just use the [Telegram Bot API](https://core.telegram.org/bots/api) (almost) directly.\n\n```clojure\n(require '[tg-clj.core :as tg])\n\n(def client (tg/make-client {:token \"\u003cYour bot token here\u003e\" :timeout 20000}))\n\n(tg/invoke client {:op :sendMessage\n                   :request {:chat_id 1234 ; Replace with your chat_id\n                             :text \"Hello!\"}})\n;; =\u003e {:ok true,\n;;     :result\n;;     {:message_id 4321,\n;;      :from\n;;      {:id 123456789,\n;;       :is_bot true,\n;;       :first_name \"My Awesome Bot\",\n;;       :username \"mybot\"},\n;;      :chat\n;;      {:id 987654321,\n;;       :first_name \"My\",\n;;       :last_name \"Name\",\n;;       :username \"myusername\",\n;;       :type \"private\"},\n;;      :date 1709377902,\n;;      :text \"Hello!\"}}\n```\n\n\n\n## Installation\n\nUse as a dependency in `deps.edn` or `bb.edn`:\n\n```clojure\nio.github.akeboshiwind/tg-clj {:git/tag \"v0.3.0\" :git/sha \"4852eb5\"}\n```\n\n\n\n## Getting Started\n\nThe workflow is as simple as it gets.\n\nFirst require the namespace:\n\n```clojure\n(require '[tg-clj.core :as tg])\n```\n\nMake a client (to learn how to create a bot and/or get it's token see [here](https://core.telegram.org/bots/features#botfather)):\n```clojure\n(def client (tg/make-client {:token \"\u003cYour bot token here\u003e\" :timeout 20000}))\n```\n\nThe browse [telegram's documentation](https://core.telegram.org/bots/api#available-methods) for a method you want to call.\n\nThen `invoke` it as `:op`:\n```clojure\n(tg/invoke client {:op :getMe})\n;; =\u003e {:ok true,\n;;     :result\n;;     {:id 123456789,\n;;      :is_bot true,\n;;      :first_name \"My Awesome Bot\",\n;;      :username \"mybot\",\n;;      :can_join_groups true,\n;;      :can_read_all_group_messages true,\n;;      :supports_inline_queries true}}\n```\n\nYou can provide parameters using the `:request` key:\n```clojure\n(tg/invoke client {:op :sendMessage\n                   :request {:chat_id 1234 ; Replace with your chat_id\n                             :text \"Hello!\"}})\n;; =\u003e {:ok true,\n;;     :result\n;;     {:message_id 4321,\n;;      :from\n;;      {:id 123456789,\n;;       :is_bot true,\n;;       :first_name \"My Awesome Bot\",\n;;       :username \"mybot\"},\n;;      :chat\n;;      {:id 987654321,\n;;       :first_name \"My\",\n;;       :last_name \"Name\",\n;;       :username \"myusername\",\n;;       :type \"private\"},\n;;      :date 1709377902,\n;;      :text \"Hello!\"}}\n```\n\nIf you provide a [`File`](https://clojuredocs.org/clojure.java.io/file) as a top level parameter then the request will be sent correctly (using `multipart/form-data`):\n```clojure\n(require '[clojure.java.io :as io])\n(tg/invoke client {:op :sendPhoto\n                   :request {:chat_id 1234\n                             :photo (io/file \"/path/to/my/pic.png\")}})\n;; =\u003e {:ok true,\n;;     :result\n;;     {:message_id 4321,\n;;      :from\n;;      {:id 123456789,\n;;       :is_bot true,\n;;       :first_name \"My Awesome Bot\",\n;;       :username \"mybot\"},\n;;      :chat\n;;      {:id 987654321,\n;;       :first_name \"My\",\n;;       :last_name \"Name\",\n;;       :username \"myusername\",\n;;       :type \"private\"},\n;;      :date 1709377902,\n;;      :photo [ \u003csnip\u003e ]}}\n```\n\nOther than client errors, errors are given how telegram represents them:\n\n```clojure\n(tg/invoke client {:op :sendMessage\n                   ; Oops, missing the `text` field!\n                   :request {:chat_id 1234}})\n;; =\u003e {:ok false,\n;;     :error_code 400,\n;;     :description \"Bad Request: message text is empty\"}\n```\n\nIf you want to inspect the full response in more detail, it's attached as metadata:\n\n```clojure\n(meta (tg/invoke client {:op :getMe}))\n;; =\u003e {:http-response\n;;     {:opts\n;;      {:as :text,\n;;       :headers {\"Accept\" \"application/json\"},\n;;       :method :post,\n;;       :url\n;;       \"https://api.telegram.org/bot\u003cyour-token\u003e/getMe\"},\n;;      :status 200,\n;;      :headers\n;;      { \u003csnip\u003e },\n;;      :body\n;;      \"{\\\"ok\\\":true,\\\"result\\\":{\\\"id\\\":123456789,\\\"is_bot\\\":true,\\\"first_name\\\":\\\"My Awesome Bot\\\",\\\"username\\\":\\\"mybot\\\",\\\"can_join_groups\\\":true,\\\"can_read_all_group_messages\\\":true,\\\"supports_inline_queries\\\":true}}\"}}\n```\n\nPlease note that the contents of `:http-response` is an implementation detail from [`http-kit`](https://github.com/http-kit/http-kit) and may change.\n\n\n\n## Handling updates\n\nThe simplest way to get updates is to just invoke [`:getUpdates`](https://core.telegram.org/bots/api#getupdates) with a `timeout` (i.e. [long polling](https://en.wikipedia.org/wiki/Push_technology#Long_polling)):\n\n```clojure\n;; For long polling, the client timeout must be longer than the polling timeout\n(def client (tg/make-client {:token \"\u003cYour bot token here\u003e\" :timeout 35000}))\n\n(tg/invoke client {:op :getUpdates\n                   :request {:offset 0\n                             :timeout 30}})\n;; =\u003e {:ok true,\n;;     :result\n;;     [ \u003csnip\u003e ]}\n```\n\nA simple loop to handle basic command events might look like this:\n\n```clojure\n(defn contains-command? [u cmd]\n  (when-let [text (get-in u [:message :text])]\n    (let [pattern (str \"^\" cmd \"($| )\")]\n      (re-find (re-pattern pattern) text))))\n\n(defn hello-handler [u]\n  (let [chat-id (get-in u [:message :chat :id])\n        message-id (get-in u [:message :message_id])]\n    {:op :sendMessage\n     :request {:chat_id chat-id\n               :text \"Hello, world!\"\n               :reply_parameters {:message_id message-id}}}))\n\n(loop [offset 0]\n  (let [{:keys [ok result]}\n        (invoke client {:op :getUpdates\n                        :request {:offset offset\n                                  :timeout 30}})]\n    (if (and ok (seq result))\n      (do (doseq [u result]\n            (when (contains-command? u \"/hello\")\n              (when-let [response (hello-handler u)]\n                (invoke client response))))\n          (recur (-\u003e\u003e result (map :update_id) (apply max) inc)))\n      (recur offset))))\n```\n\n(Checkout [tg-clj-server](https://github.com/Akeboshiwind/tg-clj-server) if this is too \"manual\" for you)\n\n\n\n## Releasing\n\n1. Tag the commit `v\u003cversion\u003e`\n2. `git push --tags`\n3. Update the README.md with the new version and git hash\n4. Update the CHANGELOG.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakeboshiwind%2Ftg-clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakeboshiwind%2Ftg-clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakeboshiwind%2Ftg-clj/lists"}