module TD.Data.ReplyMarkup
(ReplyMarkup(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified Data.Text as T
import qualified TD.Data.KeyboardButton as KeyboardButton
import qualified TD.Data.InlineKeyboardButton as InlineKeyboardButton
data ReplyMarkup
= ReplyMarkupRemoveKeyboard
{ ReplyMarkup -> Maybe Bool
is_personal :: Maybe Bool
}
| ReplyMarkupForceReply
{ is_personal :: Maybe Bool
, ReplyMarkup -> Maybe Text
input_field_placeholder :: Maybe T.Text
}
| ReplyMarkupShowKeyboard
{ ReplyMarkup -> Maybe [[KeyboardButton]]
rows :: Maybe [[KeyboardButton.KeyboardButton]]
, ReplyMarkup -> Maybe Bool
is_persistent :: Maybe Bool
, ReplyMarkup -> Maybe Bool
resize_keyboard :: Maybe Bool
, ReplyMarkup -> Maybe Bool
one_time :: Maybe Bool
, is_personal :: Maybe Bool
, input_field_placeholder :: Maybe T.Text
}
| ReplyMarkupInlineKeyboard
{ ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows :: Maybe [[InlineKeyboardButton.InlineKeyboardButton]]
}
deriving (ReplyMarkup -> ReplyMarkup -> Bool
(ReplyMarkup -> ReplyMarkup -> Bool)
-> (ReplyMarkup -> ReplyMarkup -> Bool) -> Eq ReplyMarkup
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ReplyMarkup -> ReplyMarkup -> Bool
== :: ReplyMarkup -> ReplyMarkup -> Bool
$c/= :: ReplyMarkup -> ReplyMarkup -> Bool
/= :: ReplyMarkup -> ReplyMarkup -> Bool
Eq, Int -> ReplyMarkup -> ShowS
[ReplyMarkup] -> ShowS
ReplyMarkup -> String
(Int -> ReplyMarkup -> ShowS)
-> (ReplyMarkup -> String)
-> ([ReplyMarkup] -> ShowS)
-> Show ReplyMarkup
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ReplyMarkup -> ShowS
showsPrec :: Int -> ReplyMarkup -> ShowS
$cshow :: ReplyMarkup -> String
show :: ReplyMarkup -> String
$cshowList :: [ReplyMarkup] -> ShowS
showList :: [ReplyMarkup] -> ShowS
Show)
instance I.ShortShow ReplyMarkup where
shortShow :: ReplyMarkup -> String
shortShow ReplyMarkupRemoveKeyboard
{ is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
}
= String
"ReplyMarkupRemoveKeyboard"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_personal" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
]
shortShow ReplyMarkupForceReply
{ is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
= String
"ReplyMarkupForceReply"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"is_personal" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
, String
"input_field_placeholder" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
input_field_placeholder_
]
shortShow ReplyMarkupShowKeyboard
{ rows :: ReplyMarkup -> Maybe [[KeyboardButton]]
rows = Maybe [[KeyboardButton]]
rows_
, is_persistent :: ReplyMarkup -> Maybe Bool
is_persistent = Maybe Bool
is_persistent_
, resize_keyboard :: ReplyMarkup -> Maybe Bool
resize_keyboard = Maybe Bool
resize_keyboard_
, one_time :: ReplyMarkup -> Maybe Bool
one_time = Maybe Bool
one_time_
, is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
= String
"ReplyMarkupShowKeyboard"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"rows" String -> Maybe [[KeyboardButton]] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [[KeyboardButton]]
rows_
, String
"is_persistent" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_persistent_
, String
"resize_keyboard" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
resize_keyboard_
, String
"one_time" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
one_time_
, String
"is_personal" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
is_personal_
, String
"input_field_placeholder" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
input_field_placeholder_
]
shortShow ReplyMarkupInlineKeyboard
{ _rows :: ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
}
= String
"ReplyMarkupInlineKeyboard"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_rows" String -> Maybe [[InlineKeyboardButton]] -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe [[InlineKeyboardButton]]
_rows_
]
instance AT.FromJSON ReplyMarkup where
parseJSON :: Value -> Parser ReplyMarkup
parseJSON v :: Value
v@(AT.Object Object
obj) = do
String
t <- Object
obj Object -> Key -> Parser String
forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
"@type" :: AT.Parser String
case String
t of
String
"replyMarkupRemoveKeyboard" -> Value -> Parser ReplyMarkup
parseReplyMarkupRemoveKeyboard Value
v
String
"replyMarkupForceReply" -> Value -> Parser ReplyMarkup
parseReplyMarkupForceReply Value
v
String
"replyMarkupShowKeyboard" -> Value -> Parser ReplyMarkup
parseReplyMarkupShowKeyboard Value
v
String
"replyMarkupInlineKeyboard" -> Value -> Parser ReplyMarkup
parseReplyMarkupInlineKeyboard Value
v
String
_ -> Parser ReplyMarkup
forall a. Monoid a => a
mempty
where
parseReplyMarkupRemoveKeyboard :: A.Value -> AT.Parser ReplyMarkup
parseReplyMarkupRemoveKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupRemoveKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupRemoveKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_personal_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_personal"
ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupRemoveKeyboard
{ is_personal :: Maybe Bool
is_personal = Maybe Bool
is_personal_
}
parseReplyMarkupForceReply :: A.Value -> AT.Parser ReplyMarkup
parseReplyMarkupForceReply :: Value -> Parser ReplyMarkup
parseReplyMarkupForceReply = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupForceReply" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Bool
is_personal_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_personal"
Maybe Text
input_field_placeholder_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"input_field_placeholder"
ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupForceReply
{ is_personal :: Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
parseReplyMarkupShowKeyboard :: A.Value -> AT.Parser ReplyMarkup
parseReplyMarkupShowKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupShowKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupShowKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [[KeyboardButton]]
rows_ <- Object
o Object -> Key -> Parser (Maybe [[KeyboardButton]])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rows"
Maybe Bool
is_persistent_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_persistent"
Maybe Bool
resize_keyboard_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"resize_keyboard"
Maybe Bool
one_time_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"one_time"
Maybe Bool
is_personal_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"is_personal"
Maybe Text
input_field_placeholder_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"input_field_placeholder"
ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupShowKeyboard
{ rows :: Maybe [[KeyboardButton]]
rows = Maybe [[KeyboardButton]]
rows_
, is_persistent :: Maybe Bool
is_persistent = Maybe Bool
is_persistent_
, resize_keyboard :: Maybe Bool
resize_keyboard = Maybe Bool
resize_keyboard_
, one_time :: Maybe Bool
one_time = Maybe Bool
one_time_
, is_personal :: Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
parseReplyMarkupInlineKeyboard :: A.Value -> AT.Parser ReplyMarkup
parseReplyMarkupInlineKeyboard :: Value -> Parser ReplyMarkup
parseReplyMarkupInlineKeyboard = String
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"ReplyMarkupInlineKeyboard" ((Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup)
-> (Object -> Parser ReplyMarkup) -> Value -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe [[InlineKeyboardButton]]
_rows_ <- Object
o Object -> Key -> Parser (Maybe [[InlineKeyboardButton]])
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"rows"
ReplyMarkup -> Parser ReplyMarkup
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ReplyMarkup -> Parser ReplyMarkup)
-> ReplyMarkup -> Parser ReplyMarkup
forall a b. (a -> b) -> a -> b
$ ReplyMarkupInlineKeyboard
{ _rows :: Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
}
parseJSON Value
_ = Parser ReplyMarkup
forall a. Monoid a => a
mempty
instance AT.ToJSON ReplyMarkup where
toJSON :: ReplyMarkup -> Value
toJSON ReplyMarkupRemoveKeyboard
{ is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"replyMarkupRemoveKeyboard"
, Key
"is_personal" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
]
toJSON ReplyMarkupForceReply
{ is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"replyMarkupForceReply"
, Key
"is_personal" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
, Key
"input_field_placeholder" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
input_field_placeholder_
]
toJSON ReplyMarkupShowKeyboard
{ rows :: ReplyMarkup -> Maybe [[KeyboardButton]]
rows = Maybe [[KeyboardButton]]
rows_
, is_persistent :: ReplyMarkup -> Maybe Bool
is_persistent = Maybe Bool
is_persistent_
, resize_keyboard :: ReplyMarkup -> Maybe Bool
resize_keyboard = Maybe Bool
resize_keyboard_
, one_time :: ReplyMarkup -> Maybe Bool
one_time = Maybe Bool
one_time_
, is_personal :: ReplyMarkup -> Maybe Bool
is_personal = Maybe Bool
is_personal_
, input_field_placeholder :: ReplyMarkup -> Maybe Text
input_field_placeholder = Maybe Text
input_field_placeholder_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"replyMarkupShowKeyboard"
, Key
"rows" Key -> Maybe [[KeyboardButton]] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [[KeyboardButton]]
rows_
, Key
"is_persistent" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_persistent_
, Key
"resize_keyboard" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
resize_keyboard_
, Key
"one_time" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
one_time_
, Key
"is_personal" Key -> Maybe Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Bool
is_personal_
, Key
"input_field_placeholder" Key -> Maybe Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe Text
input_field_placeholder_
]
toJSON ReplyMarkupInlineKeyboard
{ _rows :: ReplyMarkup -> Maybe [[InlineKeyboardButton]]
_rows = Maybe [[InlineKeyboardButton]]
_rows_
}
= [Pair] -> Value
A.object
[ Key
"@type" Key -> Value -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Text -> Value
AT.String Text
"replyMarkupInlineKeyboard"
, Key
"rows" Key -> Maybe [[InlineKeyboardButton]] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
forall v. ToJSON v => Key -> v -> Pair
A..= Maybe [[InlineKeyboardButton]]
_rows_
]