Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides webhook handlers both general and WAI-specific.
- module Line.Messaging.Webhook.Types
- webhook :: ChannelSecret -> Request -> ExceptT WebhookFailure IO [Event]
- webhookApp :: ChannelSecret -> ([Event] -> IO WebhookResult) -> (WebhookFailure -> Application) -> Application
- defaultOnFailure :: WebhookFailure -> Application
Types
Re-exported for convenience.
module Line.Messaging.Webhook.Types
Basic webhook
webhook :: ChannelSecret -> Request -> ExceptT WebhookFailure IO [Event] Source #
A basic webhook function. It validates a request with a channel secret, and parses the request into a list of webhook events.
To handle failures, the result is in the form of
.ExceptT
WebhookFailure
Webhook as a WAI application
:: ChannelSecret | Channel secret |
-> ([Event] -> IO WebhookResult) | Event handler |
-> (WebhookFailure -> Application) | Error handler. Just to return 400 for failures, use |
-> Application |
A webhook handler for WAI. It uses webhook
internally and returns a WAI
Application
.
An example webhook server using WAI will be like below:
app :: Application app req f = case pathInfo req of "webhook" : _ -> do secret <- getChannelSecret webhookApp secret handler defaultOnFailure req f _ -> undefined handler :: [Event] -> IO WebhookResult handler events = forM_ events handleEvent $> Ok handleEvent :: Event -> IO () handleEvent (MessageEvent event) = undefined -- handle a message event handleEvent _ = return ()
defaultOnFailure :: WebhookFailure -> Application Source #
A basic error handler to be used with webhookApp
. It returns 400 Bad
Request with the WebhookFailure
code for its body.