| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Network.Wai.Middleware.Slack
- data SlackConfig = SlackConfig {
- webHookUrl :: String
- httpManager :: Manager
- responseFilter :: Response -> Bool
- requestFilter :: Request -> Bool
- slack :: SlackConfig -> Middleware
Usage
Settings are controlled via the type SlackConfig:
import Network.HTTP.Types.Status
let slackConfig = SlackConfig {
webHookUrl = "https://hooks.slack.com/services/xxx/xxxxxxxx",
httpManager = appHttpManager foundation,
responseFilter = \resp -> status400 == responseStatus resp,
requestFilter = \_ -> True
}
The above configuration will send slack notification for all 400 http status code.
Integration with Yesod Scaffolding templates
Go to Application.hs and change the makeApplication function to something like this:
makeApplication :: App -> IO Application
makeApplication foundation = do
logWare <- makeLogWare foundation
let slackConfig = SlackConfig {
webHookUrl = "https://hooks.slack.com/services/xxxx/xxxxxxx",
httpManager = appHttpManager foundation,
responseFilter = \resp -> status400 == responseStatus resp,
requestFilter = \_ -> True
}
-- Create the WAI application and apply middlewares
appPlain <- toWaiAppPlain foundation
return $ slack slackConfig $ logWare $ defaultMiddlewaresNoLogging appPlain
data SlackConfig Source #
Slack configuration for the middleware.
Slack notification will be emitted only if this evaluates to True:
responseFilter && requestFilter. This comes handy in situations
where you don't want to send notifications for certain Requests
even if responseFilter results in True.
Constructors
| SlackConfig | |
Fields
| |
slack :: SlackConfig -> Middleware Source #
Slack middleware for Wai. Use the logStatus to control on which
status you want to log the request information in Slack.