linklater: Write bots for your Slack account, and then go to sleep (because it's so easy and late at night)

[ bsd3, library, network ] [ Propose Tags ]

A library for writing Slack chat bots.

A mistake?

[Skip to Readme]
Versions [faq],,,,,,,,,,,,
Change log changelog
Dependencies aeson (>= && <0.8), base (>=4.6 && <4.8), bytestring (>= && <0.11), containers (==0.5.*), lens (==4.3.*), text (>= && <1.2), wai (>= && <3.1), wreq (>= && <0.2) [details]
License BSD-3-Clause
Author Hao Lian
Category Network
Home page
Uploaded by hao at 2014-07-23T05:46:35Z
Distributions NixOS:
Downloads 8402 total (7 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Successful builds reported [all 1 reports]





Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info


Maintainer's Corner

For package maintainers and hackage trustees

Readme for linklater-

[back to package description]

Who let you in here?

Relax! I'm here to make your life easier. Has your company ever switched to using Slack, and then you wanted to write silly Slack bots in Haskell as a way to learn Haskell?

<sup>Really?<sup>Wow<sup>That was a pretty specific question.</sup></sup>

Uh, do you want to be friends? Well let's talk about it later, because right now I have an example for you.

Show me an example!

Here's a /jpgto bot. If you run this program and then tell Slack about your server (incoming hook and custom slash command) and then type /jpgto diplomatico in one of your channels, you'll get the image from How, you say? Screen scraping.

import Network.Linklater (say, slash,
                          Command(..), Config(..), Icon(..), Message(..), User(..))

urlParser :: Parser B.ByteString
urlParser = p
    p = garbage *> url
    garbage = string "src=\"" <|> (P.take 1 *> garbage)
    url = takeTill (== _quotedbl)

urlFor :: Text -> IO Text
urlFor search = do
  r <- get (T.unpack $ F.format "http://{}" [search])
  (return . handle . parse urlParser . strictly) (r ^. responseBody)
    strictly = B.concat . L.toChunks
    handle (Fail i ctxs s) = error (show (i, ctxs, s))
    handle (Partial f) = handle (f "")
    handle (Done _ r) = toText r

jpgto :: Maybe Command -> Application
jpgto (Just (Command (User user) channel text)) req respond = do
  url <- urlFor (maybe "spolsky" id text)
  say (Message channel (response url) (EmojiIcon "gift")) config
  (respond . responseLBS status200 headers) ""
    response url = F.format "@{} {}" (user, url)
    config = Config token ""
    headers = [("Content-Type", "text/plain")]

main :: IO ()
main = do
  let port = 80
  putStrLn (F.format "+ Listening on port {}" [port])
  run port (slash jpgto)
  return ()

For the full example (since this one is missing a ton of imports), see the examples/ directory on GitHub.

Now! /jpgto corgi:

jpgtobot in action

So easy. Much fast.


  • Uses Text everywhere so you can send your slash commands crazy Unicode characters all day long.
  • Lovely documentation.
  • Battle-tested.


  • Hao Lian, author
  • Ian Henry, design review and future contributor???
  • Shields (the Grizzly Bear album), which I listened all the way through for the first time while I was writing this ★★★★