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
requestslibrary for HTTP communication - Eio-based asynchronous operations
- Bot framework for building interactive bots (
zulip.botsubpackage) - 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.