Safe Haskell | None |
---|---|
Language | Haskell2010 |
Line.Messaging.Webhook.Types
Contents
Description
This module provides types to be used with Line.Messaging.Webhook.
- module Line.Messaging.Common.Types
- type Signature = ByteString
- 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
- data EventMessage
- data Postback = Postback {
- data' :: Text
- params :: Maybe PostbackParams
- data PostbackParams
- data BeaconData
- = BeaconEnter ID (Maybe Text)
- | BeaconLeave ID (Maybe Text)
- | BeaconBanner ID (Maybe Text)
- getHWID :: BeaconData -> ID
- getDeviceMessage :: BeaconData -> Maybe Text
Common types
Re-exported for convenience.
module Line.Messaging.Common.Types
Validation
type Signature = ByteString Source #
A type alias for auth signature.
It is set as X-Line-Signature
header in webhook requests
Result and failure
data WebhookFailure Source #
A failure type returned when a webhook request is malformed.
Constructors
SignatureVerificationFailed | When the signature is not valid. |
MessageDecodeFailed | When the request body cannot be decoded into defined event types. |
Instances
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
Constructors
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
.
Constructors
User | |
Group | |
Fields
| |
Room | |
Fields
|
Instances
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.
Constructors
TextEM ID Text | Text event message. |
ImageEM ID | Image event message. |
VideoEM ID | Video event message. |
AudioEM ID | Audio event message. |
FileEM ID Text Integer | File event message. |
LocationEM ID Location | Location event message. |
StickerEM ID Sticker | Sticker event message. |
Instances
Postback event
Represent Postback data.
data PostbackParams Source #
Represent params of Postback data.
It's currently used only for the datetime picker action. For the detail, please refer to the official documentation.
Constructors
PostbackParamsDate Text | |
PostbackParamsTime Text | |
PostbackParamsDatetime Text | |
PostbackParamsUnknown |
Instances
Beacon event
data BeaconData Source #
Represent beacon data.
Constructors
BeaconEnter ID (Maybe Text) | |
BeaconLeave ID (Maybe Text) | |
BeaconBanner ID (Maybe Text) |
Instances
getHWID :: BeaconData -> ID Source #
Get hardware ID of the beacon.
getDeviceMessage :: BeaconData -> Maybe Text Source #
Get device message from the beacon, if exists.