/slack-bot-async

Haskell library for Slack Bots

Primary LanguageHaskellMIT LicenseMIT

slack-bot-async

Haskell library for creating Slack bots using the Slack Real Time Messaging API. Events are handled asynchronously.

This library uses slack-api-types for API definitions and monad-logger for logging.

Example

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Control.Monad.Logger ( runStdoutLoggingT
                            , logInfoNS
                            , filterLogger
                            , LogLevel(LevelDebug)
                            )
import Data.Maybe (fromMaybe)
import System.Environment (lookupEnv)

import Slack.Bot

echoBot :: SlackBot
echoBot (Message cid _ msg _ _ _) = do
  logInfoNS "echoBot" msg
  sendMessage cid msg
echoBot _ = return ()

main :: IO ()
main = do
  token <- fromMaybe (error "SLACK_API_TOKEN not set")
           <$> lookupEnv "SLACK_API_TOKEN"
  runStdoutLoggingT
    $ filterLogger (\_ lvl -> lvl /= LevelDebug)
    $ runBot token echoBot

More examples here.

Credit

This project is forked from slack-api by Matthew Pickering.