Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thieman/clojure-zulip
Unofficial Clojure bindings to Zulip using core.async
https://github.com/thieman/clojure-zulip
Last synced: 7 days ago
JSON representation
Unofficial Clojure bindings to Zulip using core.async
- Host: GitHub
- URL: https://github.com/thieman/clojure-zulip
- Owner: thieman
- License: epl-1.0
- Created: 2013-12-10T23:33:01.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-02-26T00:34:46.000Z (over 4 years ago)
- Last Synced: 2024-04-14T19:16:40.690Z (7 months ago)
- Language: Clojure
- Size: 17.6 KB
- Stars: 4
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clojure-zulip
An asynchronous Clojure client for the Zulip API.
## Getting Started
```clojure
[clojure-zulip "0.1.0-SNAPSHOT"]
```### Connections
You'll usually want to define one connection for each Zulip bot you're controlling and pass that to every call you make. The `connection` function only returns an options dict and does not immediately open any connections to Zulip.
```clojure
(require '[clojure-zulip.core :as zulip])
(def conn (zulip/connection {:username "my username" :api-key "my key"}))
```### Basic Commands
Every API command returns a `core.async` channel to which the HTTP response will be published. For each request, a new future is created to make the request, publish the response to the channel, and then terminate. Connection pooling is currently not implemented, so if you are making a ton of concurrent requests, you may need to create a pool yourself.
A `sync*` wrapper macro is also provided to make any request synchronous.
```clojure
(def channel (zulip/subscriptions conn))
(async/ {:msg "", :result "success", :subscriptions []}(zulip/sync* (zulip/subscriptions conn))
=> {:msg "", :result "success", :subscriptions []}
```Functions are provided for the commands listed on the [Zulip endpoints page](zulip.com/api/endpoints) as well as some undocumented commands such as those used for managing subscriptions.
### Subscribing to Events
A common pattern in bot design is to subscribe to a list of streams and then respond to any messages received on those streams or through private messages. The `subscribe-events` function is provided to make this easier.
```clojure
(def queue-id (:queue_id (zulip/synchronous (zulip/register conn))))
(def events-channel (zulip/subscribe-events conn queue-id))
(loop [] (println (async/