Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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/