line-1.0.1.0: Haskell SDK for the LINE API

Safe HaskellNone
LanguageHaskell2010

Line.Messaging.Webhook

Contents

Description

This module provides webhook handlers both general and WAI-specific.

Synopsis

Types

Re-exported for convenience.

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

webhookApp Source #

Arguments

:: ChannelSecret

Channel secret

-> ([Event] -> IO WebhookResult)

Event handler

-> (WebhookFailure -> Application)

Error handler. Just to return 400 for failures, use defaultOnFailure.

-> 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.