A haskell wrapper for the zulip API.
Simply installing through cabal with cabal install hzulip
should do it.
import Web.HZulip
main :: IO ()
main = withZulipCreds "zulip-api-user" "zulip-api-key" $ do
-- Since we are inside the ZulipM ReaderT monad transformer, we
-- don't need to pass options around. The above function already
-- created an HTTP manager, for connection pooling and wrapped the
-- default configuration options with the Monad:
print =<< getSubscriptions
-- >> ["haskell"]
-- Sending messages is as easy as:
void $ sendStreamMessage "haskell" -- message stream
"hzulip" -- message topic
"Message from Haskell" -- message content
-- Before receiving messages, our client needs to be subscribed to streams
addAllSubscriptions
-- Listening for events works with a callback based API:
onNewMessage $ \msg -> do
lift $ putStrLn "Got a new message!"
let usr = messageSender msg
fn = userFullName usr
e = userEmail usr
sendPrivateMessage [e] $ "Thanks for the message " ++ fn ++ "!!"
The best resource on this is naturally its haddock documentation, available at yamadapc.github.io/hzulip. You might also be interested in the zulip API documentation as well.
There are a couple of example bots and applications on the
examples
directory. If you're getting started with Haskell, I'd
suggest looking at the ZulipLogger
and
ZulipEchoBot
which show of basic API usage
with minimal noise from anything else.
A Conduit
API is provided as well and an "echo" example is available for it in the
examples directory; here. You can compare the evented implementation and see which you
like best. Right now using streams to handle output is a bit unhandy, but it
provides a nice composable high-level interface for the events.
Other than the echo and logger examples; there's also a pretty logger at ZulipCli
.
Though slightly outdated, there's a remote evaluation Zulip bot using this library at zulip-eval-bot, which might be worth taking a look at as well.
This code is licensed under the GPLv2 license for Pedro Tacla Yamada. Plese refer to LICENSE for more information.
Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y