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 https://slack.com/ Slack chat bots.

A mistake?


[Skip to Readme]

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
developerDisabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0.0.0, 1.0.0.1, 1.0.0.2, 1.0.0.3, 2.0.0.0, 2.0.0.1, 2.0.0.2, 2.0.0.3, 3.1.0.0, 3.2.0.0, 4.0.0.0, 4.0.0.1, 4.0.0.2
Change log changelog
Dependencies aeson (>=0.7.0.6 && <0.8), base (>=4.6 && <4.8), bytestring (>=0.10.4.0 && <0.11), containers (>=0.5 && <0.6), lens (>=4.3 && <4.4), text (>=1.1.1.3 && <1.2), wai (>=3.0.0.2 && <3.1), wreq (>=0.1.0.1 && <0.2) [details]
License BSD-3-Clause
Author Hao Lian
Maintainer me@haolian.org
Category Network
Home page https://github.com/hlian/linklater
Uploaded by hao at 2014-07-23T05:46:35Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 9549 total (29 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]

Readme for linklater-1.0.0.3

[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?

Really?WowThat was a pretty specific question.

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 http://diplomatico.jpg.to. How, you say? Screen scraping.

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

urlParser :: Parser B.ByteString
urlParser = p
  where
    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://{}.jpg.to/" [search])
  (return . handle . parse urlParser . strictly) (r ^. responseBody)
  where
    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) ""
  where
    response url = F.format "@{} {}" (user, url)
    config = Config token "trello.slack.com"
    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.

Features

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

Contributors

  • 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 ★★★★