OCaml 99.1%
Dune 0.2%
Other 0.7%
29 1 0

Clone this repository

https://tangled.org/anil.recoil.org/ocaml-zulip
git@git.recoil.org:anil.recoil.org/ocaml-zulip

For self-hosted knots, clone URLs may differ based on your setup.

README.md

OCaml Zulip Library#

A complete OCaml implementation of the Zulip REST API using the requests HTTP library and Eio for async operations.

Features#

  • Full Zulip REST API client implementation
  • Uses the modern requests library for HTTP communication
  • Eio-based asynchronous operations
  • Bot framework for building interactive bots (zulip.bot subpackage)
  • Support for Atom/RSS feed bots

Installation#

opam install zulip

Or from source:

dune build
dune install

Configuration#

Create a ~/.zuliprc file with your Zulip credentials:

[api]
email = bot@example.com
key = your-api-key-here
site = https://your-domain.zulipchat.com

Usage#

Basic Client#

let () =
  Eio_main.run @@ fun env ->
  Eio.Switch.run @@ fun sw ->

  (* Load authentication *)
  let auth = Zulip.Auth.from_zuliprc () in

  (* Create client *)
  let client = Zulip.Client.create ~sw env auth in

  (* Send a message *)
  let message = Zulip.Message.create
    ~type_:`Channel
    ~to_:["general"]
    ~topic:"Hello"
    ~content:"Hello from OCaml!"
    ()
  in
  let response = Zulip.Messages.send client message in
  Printf.printf "Sent message %d\n" (Zulip.Message_response.id response)

Bot Framework#

The zulip.bot subpackage provides a fiber-based framework for building Zulip bots:

open Zulip_bot

let echo_handler ~storage:_ ~identity:_ ~flags:_ msg =
  Response.reply ("Echo: " ^ Message.content msg)

let () =
  Eio_main.run @@ fun env ->
  Eio.Switch.run @@ fun sw ->
  let fs = Eio.Stdenv.fs env in
  let config = Config.load ~fs "echo-bot" in
  Bot.run ~sw ~env ~config ~handler:echo_handler ()

License#

ISC License. See LICENSE.md for details.