{"id":16681757,"url":"https://github.com/casidiablo/slack-rtm","last_synced_at":"2025-03-17T00:32:41.671Z","repository":{"id":27943567,"uuid":"31436174","full_name":"casidiablo/slack-rtm","owner":"casidiablo","description":"Clojure library to deal with Slack's Real Time Messaging API","archived":false,"fork":false,"pushed_at":"2018-05-17T03:17:45.000Z","size":23,"stargazers_count":40,"open_issues_count":7,"forks_count":14,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-25T15:41:36.572Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casidiablo.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}},"created_at":"2015-02-27T19:48:01.000Z","updated_at":"2020-04-02T08:49:30.000Z","dependencies_parsed_at":"2022-09-04T09:10:24.534Z","dependency_job_id":null,"html_url":"https://github.com/casidiablo/slack-rtm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fslack-rtm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fslack-rtm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fslack-rtm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casidiablo%2Fslack-rtm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casidiablo","download_url":"https://codeload.github.com/casidiablo/slack-rtm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221669385,"owners_count":16860862,"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":[],"created_at":"2024-10-12T14:05:12.941Z","updated_at":"2024-10-27T11:35:44.559Z","avatar_url":"https://github.com/casidiablo.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# slack-rtm [![ci-status](https://travis-ci.org/casidiablo/slack-rtm.svg?branch=master)](https://travis-ci.org/casidiablo/slack-rtm)\n\nA Clojure library to interact with the [Slack][1] [Real Time Messaging API][2].\nIt's powered by [`clj-slack`][3] and `core.async`.\n\n## Usage\n\nInclude `[slack-rtm \"0.1.7\"]` in your dependencies. Get a\n[Slack token][4] (it can be a bot token too).  Then:\n\n```clojure\n(use 'slack-rtm.core)\n\n;; connect to the Real Time Messaging API\n;; you can also use (start \"your-token\") see difference here: https://api.slack.com/rtm\n(def rtm-conn (connect \"your-token\"))\n\n;; rtm-conn is a map with publications and channels that\n;; allows you to receive and send data to and from Slack.\n\n;; :events-publication allows you to listen for slack events\n(def events-publication (:events-publication rtm-conn))\n\n;; let's listen for events of type :pong\n(def pong-receiver #(println \"got this:\" %))\n(sub-to-event events-publication :pong pong-receiver)\n\n;; send events to Slack by getting the dispatcher channel\n(def dispatcher (:dispatcher rtm-conn))\n(send-event dispatcher {:type \"ping\"})\n\n;; at this point pong-receiver should have been called with a pong response\n\n```\n\nThe map returned by `connect` has four items:\n\n- `:start` is map containing the response from the Slack API\n  [rtm.start](https://api.slack.com/methods/rtm.start)\n  method, which contains data about the current state of the team:\n\n- `:events-publication` is a `core.async` [publication][5] that you can\n use to subscribe to the different kind of [slack event types][6]. You\n can use `core.async`'s `sub` method using as topic the string version\n of the event type (e.g. `\"message\"`, `\"im_open\"`, etc.). Or better yet,\n use the `sub-to-event` function that allows you to subscribe both a\n `core.async` channel or an unary function; it also allows you to\n subscribe using keywords (e.g. `:message`, `:im_open`, etc.).\n\n- `:dispatcher` is a `core.async` channel you can use to send events to\nslack. You can use `core.async` primitive methods (`\u003e!!`, `\u003e!`, `put!`),\nor better yet use `send-event` which automatically adds an `:id` to\nthe map if none is present.\n\n- `:websocket-publication` is a `core.async` publication that allows\nyou to subscribe to raw WebSocket callbacks. It support the following\ntopics: `:on-connect`, `:on-receive`, `:on-binary`, `:on-close`, `:on-error`.\nRefer to [stylefruits/gniazdo][7] for information on these.\n\n### Hook subscriptions before connecting\n\nUsing `(connect \"token\")` will connect right away, which means you can\nmiss events (like the `hello` event) by the time you subscribe. You can\nsubscribe to any event before the connection has been performed by\nspecifying a list of `:topics channel-or-function` pairs to `connect`\nlike this:\n\n```clojure\n(connect \"token\"\n         :hello #(prn %)\n         :on-close (fn [{:keys [status reason]}] (prn status reason)))\n```\n\n## Running Tests\n\nExport a `TOKEN` environment variable with your Slack token or create file\n```.slack.clj``` to your home directory with following content:\n\n```clojure\n{:slack-rtm \"your-legacy-token-here\"}\n```\n\nYou can get yours from [https://api.slack.com/custom-integrations/legacy-tokens](https://api.slack.com/custom-integrations/legacy-tokens).\n\nRun the test suite:\n\n```bash\nlein test\n```\n\n### Wait until the connection is closed\n\nIf you are starting the client from a `-main` function then you likely want to wait until the connection is closed before exiting from the function. (All the threads are started in the background and do not prevent main and thus the application from exiting.) You might do something like this:\n\n```clojure\n(defn -main []\n  (let [{:keys [events-publication dispatcher start]} (connect)]\n    ; ...\n    (let [c (sub-to-event events-publication :message #(msg-receiver dispatcher %))]\n      (loop []\n        (a/\u003c!! c)\n        (recur)))))\n```\n\nExplanation: `sub-to-event` returns a channel that gets closed when the connection is closed.\n(You could also use `go-loop` or listen for the `:on-close` event ...)\n\n## Deploying\n\n\n``` bash\nexport GPG_TTY=$(tty)\nCLOJARS_USERNAME=cristian CLOJARS_PASSWORD=*** lein deploy clojars\n```\n\n\n## License\n\nDistributed under the WTFPL.\n\n\n  [1]: http://slack.com\n  [2]: https://api.slack.com/rtm\n  [3]: https://github.com/julienXX/clj-slack\n  [4]: https://api.slack.com/tokens\n  [5]: https://clojure.github.io/core.async/#clojure.core.async/pub\n  [6]: https://api.slack.com/events\n  [7]: https://github.com/stylefruits/gniazdo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fslack-rtm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasidiablo%2Fslack-rtm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasidiablo%2Fslack-rtm/lists"}