Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides types to be used with Line.Messaging.Webhook.
- module Line.Messaging.Common.Types
- data WebhookResult
- data WebhookFailure
- newtype Body = Body [Event]
- data Event
- type EventTuple r a = (EventSource, UTCTime, r, a)
- type ReplyToken = Text
- type ReplyableEvent a = EventTuple ReplyToken a
- type NonReplyableEvent a = EventTuple () a
- getSource :: EventTuple r a -> EventSource
- getDatetime :: EventTuple r a -> UTCTime
- getReplyToken :: ReplyableEvent a -> ReplyToken
- getMessage :: ReplyableEvent EventMessage -> EventMessage
- getPostback :: ReplyableEvent Postback -> Postback
- getBeacon :: ReplyableEvent BeaconData -> BeaconData
- data EventSource
- getID :: EventSource -> ID
- data EventMessage
- data BeaconData = BeaconEnter {}
Common types
Re-exported for convenience.
module Line.Messaging.Common.Types
Result and failure
data WebhookResult Source #
A result type a webhook event handler should return.
It is eventually transformed to a WAI response or application.
Ok | Respond with an empty 200 OK response. |
WaiResponse Response | Respond with a WAI response. |
WaiApp Application | Respond with a WAI application. |
data WebhookFailure Source #
A failure type returned when a webhook request is malformed.
SignatureVerificationFailed | When the signature is not valid. |
MessageDecodeFailed | When the request body cannot be decoded into defined event types. |
Webhook request body
The following types and functions are about decoding a webhook request body.
Body
This type represents a whole request body.
It is mainly for JSON parsing, and users may not need to use this type directly.
Event
Webhook event data types and instances for proper type classes
(e.g. FromJSON
) are implemented here.
For the event spec, please refer to the LINE documentation.
A type to represent each webhook event. The type of an event can be determined with pattern matching.
handleEvent :: Event -> IO () handleEvent (MessageEvent event) = handleMessageEvent event handleEvent (BeaconEvent event) = handleBeaconEvent event handleEvent _ = return () handleMessageEvent :: ReplyableEvent EventMessage -> IO () handleMessageEvent = undefined handleBeaconEvent :: ReplyableEvent BeaconData -> IO () handleBeaconEvent = undefined
All the data contstructors have a type
.EventTuple
r a -> Event
type EventTuple r a = (EventSource, UTCTime, r, a) Source #
The base type for an event. It is a type alias for 4-tuple containing event data.
The type variable r
is for a reply token, which is ()
in the case of
non-replyable events. The type variable a
is a content type, which is
()
for events without content.
type ReplyToken = Text Source #
A type alias for reply token. It is also consumed by the
reply
API.
type ReplyableEvent a = EventTuple ReplyToken a Source #
A type alias to represent a replyable event.
type NonReplyableEvent a = EventTuple () a Source #
A type alias to represent a non-replyable event.
getSource :: EventTuple r a -> EventSource Source #
Retrieve event source from an event.
getDatetime :: EventTuple r a -> UTCTime Source #
Retrieve datetime when event is sent.
getReplyToken :: ReplyableEvent a -> ReplyToken Source #
Retrieve a reply token of an event. It can be used only for
ReplyableEvent
.
getMessage :: ReplyableEvent EventMessage -> EventMessage Source #
Retrieve event message from an event. It can be used only for events whose content is a message.
handleMessageEvent :: ReplyableEvent EventMessage -> IO () handleMessageEvent event = do let message = getMessage event print message
getPostback :: ReplyableEvent Postback -> Postback Source #
Retrieve postback data from an event. It can be used only for events whose content is postback data.
import qualified Data.Text.IO as TIO handlePostbackEvent :: ReplyableEvent Postback -> IO () handlePostbackEvent event = do let postback = getPostback event TIO.putStrLn postback
getBeacon :: ReplyableEvent BeaconData -> BeaconData Source #
Retrieve beacon data from an event. It can be used only for events whose content is beacon data.
handleBeaconEvent :: ReplyableEvent BeaconData -> IO () handleBeaconEvent event = do let beaconData = getBeacon event print beaconData
Event source
data EventSource Source #
A source from which an event is sent. It can be retrieved from events with
getSource
.
getID :: EventSource -> ID Source #
Retrieve identifier from event source
Message event
data EventMessage Source #
Represent message types sent with MessageEvent
. It can be retrieved from
message events with getMessage
.
There is no actual content body sent with image, video and audio
messages. It should be manually downloaded via the
getContent
API.
For more details of event messages, please refer to the Message event section of the LINE documentation.