Copyright | Pedro Tacla Yamada |
---|---|
License | MIT (see LICENSE) |
Maintainer | Pedro Tacla Yamada <tacla.yamada@gmail.com> |
Stability | unstable |
Portability | unportable |
Safe Haskell | None |
Language | Haskell2010 |
A Wrapper library for the Zulip API. Works on top of a ReaderT
monad
transformer, holding a ZulipOptions
object, which should hold the
state and configuration for the API client.
Using the library is made easier through a set of helper functions. This
design is more concise and than passing around configuration variables;
one could easily bypass it with the use of runZulip
, though that isn't
recommended.
Example usage: > 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 > > -- Listening for events works with a callback based API. More > -- complex patterns for concurrent message handling can be created > -- from it. As long as your zulip user is already subscribed to > -- streams, this is all you have to do: > onNewEvent ["message"] $ msg -> do > liftIO $ putStrLn "Got a new message!" > let usr = messageSender msg > fn = userFullName usr > e = userEmail usr > > sendPrivateMessage [e] $ "Thanks for the message " ++ fn ++ "!!"
- data Event = Event {}
- data Message = Message {
- messageId :: Int
- messageType :: String
- messageContent :: String
- messageAvatarUrl :: String
- messageTimestamp :: Int
- messageDisplayRecipient :: Either String [User]
- messageSender :: User
- messageGravatarHash :: String
- messageRecipientId :: Int
- messageClient :: String
- messageSubjectLinks :: [String]
- messageSubject :: String
- data Queue = Queue {
- queueId :: String
- lastEventId :: Int
- data User = User {
- userId :: Int
- userFullName :: String
- userEmail :: String
- userDomain :: String
- userShortName :: String
- data ZulipOptions = ZulipOptions {}
- type EventCallback = Event -> ZulipM ()
- type MessageCallback = Message -> ZulipM ()
- addSubscriptions :: [String] -> ZulipM ()
- defaultBaseUrl :: String
- eventTypes :: [String]
- getEvents :: Queue -> Bool -> ZulipM (Queue, [Event])
- getStreams :: ZulipM [String]
- getStreamSubscribers :: String -> ZulipM [String]
- getSubscriptions :: ZulipM [String]
- onNewEvent :: [String] -> EventCallback -> ZulipM ()
- onNewMessage :: MessageCallback -> ZulipM ()
- registerQueue :: [String] -> Bool -> ZulipM Queue
- removeSubscriptions :: [String] -> ZulipM ()
- runZulip :: ZulipM a -> ZulipOptions -> IO a
- sendMessage :: String -> [String] -> String -> String -> ZulipM Int
- sendPrivateMessage :: [String] -> String -> ZulipM Int
- sendStreamMessage :: String -> String -> String -> ZulipM Int
- withZulip :: ZulipOptions -> ZulipM a -> IO a
- withZulipCreds :: String -> String -> ZulipM a -> IO a
- zulipOptions :: String -> String -> IO ZulipOptions
Documentation
Represents zulip events
Represents a Zulip Message
Message | |
|
Represents some event queue
Queue | |
|
Represents a zulip user account - for both display_recipient
and
message_sender
representations
User | |
|
data ZulipOptions Source
Represents a Zulip API client
type EventCallback = Event -> ZulipM () Source
The root type for Event callbacks
type MessageCallback = Message -> ZulipM () Source
Type for message callbacks
addSubscriptions :: [String] -> ZulipM () Source
Add new Stream subscriptions to the client.
defaultBaseUrl :: String Source
The default zulip API URL
eventTypes :: [String] Source
The list of all avaiable event types
getStreams :: ZulipM [String] Source
Get a list of all the public streams
getStreamSubscribers :: String -> ZulipM [String] Source
Get all the user emails subscribed to a stream
getSubscriptions :: ZulipM [String] Source
Get a list of the streams the client is currently subscribed to.
onNewEvent :: [String] -> EventCallback -> ZulipM () Source
Registers an event callback for specified events and keeps executing it over events as they come in. Will loop forever
onNewMessage :: MessageCallback -> ZulipM () Source
Registers a callback to be executed whenever a message comes in. Will loop forever
registerQueue :: [String] -> Bool -> ZulipM Queue Source
This registers a new event queue with the zulip API. It's a lower level
function, which shouldn't be used unless you know what you're doing. It
takes a list of names of the events you want to listen for and whether
you'd like for the content to be rendered in HTML format
(if you set the last parameter to False
it will be kept as typed, in
markdown format)
removeSubscriptions :: [String] -> ZulipM () Source
Remove one or more Stream subscriptions from the client
runZulip :: ZulipM a -> ZulipOptions -> IO a Source
Helper to run Actions in the Zulip Monad
sendMessage :: String -> [String] -> String -> String -> ZulipM Int Source
This wraps `POST https://api.zulip.com/v1/messages` with a nicer root API. Simpler helpers for each specific case of this somewhat overloaded endpoint will also be provided in the future.
It takes the message mtype
, mrecipients
, msubject
and mcontent
and returns the created message's id
in the ZulipM
monad.
sendPrivateMessage :: [String] -> String -> ZulipM Int Source
Helper for sending private messages. Takes the list of recipients and the message's content.
sendStreamMessage :: String -> String -> String -> ZulipM Int Source
Helper for sending stream messages. Takes the stream name, the subject and the message.
withZulipCreds :: String -> String -> ZulipM a -> IO a Source
Helper for creating a minimal ZulipOptions
object and running an action
in the ZulipM
monad
zulipOptions :: String -> String -> IO ZulipOptions Source
Helper for creating a ZulipOptions
object with the baseUrl
set to
defaultBaseUrl