-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormAction.hs
47 lines (37 loc) · 1.39 KB
/
FormAction.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE OverloadedStrings #-}
module Aitu.Bot.Forms.FormAction
( FormAction(..)
, FormActionType(..)
, DataTemplate(..)
)
where
import Data.Aeson
import Data.Text
type UserName = Text
type Url = Text
type Template = Text
data FormActionType = SendMessageAction | SubmitFormAction | CloseFormAction | OpenUrlAction | ShareDataAction | OpenPeerAction deriving (Show)
instance ToJSON FormActionType where
toJSON SendMessageAction = String "send_message"
toJSON SubmitFormAction = String "submit_form"
toJSON CloseFormAction = String "close_form"
toJSON OpenUrlAction = String "open_url"
toJSON ShareDataAction = String "share_data"
toJSON OpenPeerAction = String "open_peer"
data DataTemplate = DataTemplate Template | EmptyTemplate deriving (Show)
instance ToJSON DataTemplate where
toJSON (DataTemplate template) = String template
toJSON EmptyTemplate = String ("" :: Text)
data FormAction = FormAction {
action :: FormActionType
, dataTemplate :: DataTemplate
-- , hiddenMetadata :: Maybe Text
} deriving (Show)
instance ToJSON FormAction where
toJSON FormAction {..} = object
[ "action" .= action
, "data_template" .= dataTemplate
-- , "hidden_metadata" .= hiddenMetadata
]