module TD.Data.CallbackQueryAnswer
(CallbackQueryAnswer(..)) 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
data CallbackQueryAnswer
= CallbackQueryAnswer
{ CallbackQueryAnswer -> Maybe Text
text :: Maybe T.Text
, CallbackQueryAnswer -> Maybe Bool
show_alert :: Maybe Bool
, CallbackQueryAnswer -> Maybe Text
url :: Maybe T.Text
}
deriving (CallbackQueryAnswer -> CallbackQueryAnswer -> Bool
(CallbackQueryAnswer -> CallbackQueryAnswer -> Bool)
-> (CallbackQueryAnswer -> CallbackQueryAnswer -> Bool)
-> Eq CallbackQueryAnswer
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CallbackQueryAnswer -> CallbackQueryAnswer -> Bool
== :: CallbackQueryAnswer -> CallbackQueryAnswer -> Bool
$c/= :: CallbackQueryAnswer -> CallbackQueryAnswer -> Bool
/= :: CallbackQueryAnswer -> CallbackQueryAnswer -> Bool
Eq, Int -> CallbackQueryAnswer -> ShowS
[CallbackQueryAnswer] -> ShowS
CallbackQueryAnswer -> String
(Int -> CallbackQueryAnswer -> ShowS)
-> (CallbackQueryAnswer -> String)
-> ([CallbackQueryAnswer] -> ShowS)
-> Show CallbackQueryAnswer
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CallbackQueryAnswer -> ShowS
showsPrec :: Int -> CallbackQueryAnswer -> ShowS
$cshow :: CallbackQueryAnswer -> String
show :: CallbackQueryAnswer -> String
$cshowList :: [CallbackQueryAnswer] -> ShowS
showList :: [CallbackQueryAnswer] -> ShowS
Show)
instance I.ShortShow CallbackQueryAnswer where
shortShow :: CallbackQueryAnswer -> String
shortShow CallbackQueryAnswer
{ text :: CallbackQueryAnswer -> Maybe Text
text = Maybe Text
text_
, show_alert :: CallbackQueryAnswer -> Maybe Bool
show_alert = Maybe Bool
show_alert_
, url :: CallbackQueryAnswer -> Maybe Text
url = Maybe Text
url_
}
= String
"CallbackQueryAnswer"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"text" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
text_
, String
"show_alert" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
show_alert_
, String
"url" String -> Maybe Text -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Text
url_
]
instance AT.FromJSON CallbackQueryAnswer where
parseJSON :: Value -> Parser CallbackQueryAnswer
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
"callbackQueryAnswer" -> Value -> Parser CallbackQueryAnswer
parseCallbackQueryAnswer Value
v
String
_ -> Parser CallbackQueryAnswer
forall a. Monoid a => a
mempty
where
parseCallbackQueryAnswer :: A.Value -> AT.Parser CallbackQueryAnswer
parseCallbackQueryAnswer :: Value -> Parser CallbackQueryAnswer
parseCallbackQueryAnswer = String
-> (Object -> Parser CallbackQueryAnswer)
-> Value
-> Parser CallbackQueryAnswer
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"CallbackQueryAnswer" ((Object -> Parser CallbackQueryAnswer)
-> Value -> Parser CallbackQueryAnswer)
-> (Object -> Parser CallbackQueryAnswer)
-> Value
-> Parser CallbackQueryAnswer
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Text
text_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"text"
Maybe Bool
show_alert_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"show_alert"
Maybe Text
url_ <- Object
o Object -> Key -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"url"
CallbackQueryAnswer -> Parser CallbackQueryAnswer
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CallbackQueryAnswer -> Parser CallbackQueryAnswer)
-> CallbackQueryAnswer -> Parser CallbackQueryAnswer
forall a b. (a -> b) -> a -> b
$ CallbackQueryAnswer
{ text :: Maybe Text
text = Maybe Text
text_
, show_alert :: Maybe Bool
show_alert = Maybe Bool
show_alert_
, url :: Maybe Text
url = Maybe Text
url_
}
parseJSON Value
_ = Parser CallbackQueryAnswer
forall a. Monoid a => a
mempty