line-1.0.1.0: Haskell SDK for the LINE API

Safe HaskellNone
LanguageHaskell2010

Line.Messaging.Webhook.Types

Contents

Description

This module provides types to be used with Line.Messaging.Webhook.

Synopsis

Common types

Re-exported for convenience.

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.

Constructors

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.

Constructors

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

newtype Body Source #

This type represents a whole request body.

It is mainly for JSON parsing, and users may not need to use this type directly.

Constructors

Body [Event] 

Instances

Eq Body Source # 

Methods

(==) :: Body -> Body -> Bool #

(/=) :: Body -> Body -> Bool #

Show Body Source # 

Methods

showsPrec :: Int -> Body -> ShowS #

show :: Body -> String #

showList :: [Body] -> ShowS #

FromJSON Body Source # 

Methods

parseJSON :: Value -> Parser Body #

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.

data Event Source #

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.

Instances

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 ID 
Group ID 
Room ID 

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.

Constructors

TextEM ID Text

Text event message.

ImageEM ID

Image event message.

VideoEM ID

Video event message.

AudioEM ID

Audio event message.

LocationEM ID Location

Location event message.

StickerEM ID Sticker

Sticker event message.

Beacon event

data BeaconData Source #

Represent beacon data.

Constructors

BeaconEnter 

Fields