-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | The fast and fun way to write Slack.com bots -- -- __A library for writing https://slack.com/ Slack chat bots.__ -- -- Tutorial: https://github.com/hlian/linklater/wiki/Tutorial -- -- Features you could take advantage of right now, should you -- choose: -- -- -- -- For example, maybe you want this little guy to show up in your -- channel: -- -- -- Find out how by clicking on Network.Linklater! @package linklater @version 2.0.0.2 -- | 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 baby corgi in one of your channels, you'll -- get the image from http:baby.corgi.jpg.to. How, you -- say? Screen scraping. -- --
--   -- Remaining imports left as an exercise to the reader.
--   import Network.Linklater (say, slashSimple, Command(..), Config(..), Message(..), Icon(..), Format(..))
--   --
--   
--   findUrl :: Text -> Maybe Text
--   findUrl = fmap fromStrict . maybeResult . parse (manyTill (notChar '\n') (string "src=\"") *> takeTill (== '"'))
--   
--   jpgto :: Maybe Command -> IO Text
--   jpgto (Just (Command user channel (Just text))) = do
--     message <- (fmap messageOf . findUrl . decodeUtf8 . flip (^.) responseBody) <$> get ("http://" <> (unpack subdomain) <> ".jpg.to/")
--     case (debug, message) of
--       (True, _) -> putStrLn ("+ Pretending to post " <> (unpack . decodeUtf8 . encode) message) >> return ""
--       (False, Just m) -> config' >>= say m >> return ""
--       (False, Nothing) -> return "Something went wrong!"
--     where config' = (Config "trello.slack.com" . filter (/= '\n') . pack) <$> readFile "token"
--           subdomain = (intercalate "." . fmap (filter isLetter . filter isAscii) . words) text
--           messageOf url = FormattedMessage (EmojiIcon "gift") "jpgtobot" channel [FormatAt user, FormatLink url (subdomain <> ".jpg.to>"), FormatString "no way!: &<>"]
--           debug = True
--   jpgto _ = return "Type more! (Did you know? jpgtobot is only 26 lines of Haskell. <https://github.com/hlian/jpgtobot/blob/master/Main.hs>)"
--   
--   main :: IO ()
--   main = let port = 3000 in putStrLn ("+ Listening on port " <> show port) >> run port (slashSimple jpgto)
--   
-- -- One /jpgto baby corgi, et voila. -- -- -- For the full example (since this one is missing a ton of imports), see -- the examples/ directory on GitHub. -- -- https:github.comhlianlinklater module Network.Linklater -- | The say function posts a Message, with a capital M, to -- Slack. It'll, however, need a Config (a.k.a. incoming token) -- first. say :: Message -> Config -> IO (Response ByteString) -- | A bot server! As if by magic. This acts like a WAI middleware: -- Linklater wraps around your application. (Really, it just gives you a -- Command to work with instead of a raw HTTP request.) slash :: (Maybe Command -> Application) -> Application -- | A bot server for people who are in a hurry. Make a function that takes -- a Command and returns some Text in IO world, and -- we'll convert it into a WAI application. If you want more -- control over the request and respond, see slash. slashSimple :: (Maybe Command -> IO Text) -> Application -- | Where slash commands come from, and where Messages go. data Channel -- | A public or private group. GroupChannel :: Text -> Channel -- | A private conversation with your best friend -- or lover ;). IMChannel :: Text -> Channel -- | A username: no at-signs, just text! newtype User User :: Text -> User -- | Here's how you talk: you make one of these and pass it to say. -- Before the day is done, Linklater will convert this to a JSON blob -- using Aeson. -- -- data Message SimpleMessage :: Icon -> Text -> Channel -> Text -> Message FormattedMessage :: Icon -> Text -> Channel -> [Format] -> Message -- | Like a curiosity about the world, you'll need one of these to -- say something. data Config Config :: Text -> Text -> Config -- | This is where your Slack account is hosted. For example, -- trello.slack.com. _configHostname :: Config -> Text -- | This is the incoming web hook token that Slack gave you. It's usually -- a long alphanumberic string of garbage. _configIncomingHookToken :: Config -> Text -- | Incoming HTTP requests to the slash function get parsed into one of -- these babies. data Command Command :: User -> Channel -> Maybe Text -> Command -- | Who ran your slash command. _commandUser :: Command -> User -- | Where the person ran your slash command. _commandChannel :: Command -> Channel -- | Text for the slash command, if any. _commandText :: Command -> Maybe Text -- | The icon next to the messages you say. (Images unsupported -- right now, sorry.) newtype Icon -- | For example, :stars2:. EmojiIcon :: Text -> Icon -- | A little DSL for Slack formatting. data Format -- |
--   <@user|user>
--   
FormatAt :: User -> Format -- |
--   <@user|user did this and that>
--   
FormatUser :: User -> Text -> Format FormatLink :: Text -> Text -> Format -- |
--   user did this &amp; that
--   
FormatString :: Text -> Format instance Eq Channel instance Ord Channel instance Show Channel instance Eq User instance Ord User instance Show User instance Eq Command instance Ord Command instance Show Command instance Eq Icon instance Ord Icon instance Show Icon instance ToJSON Message