module TD.Data.QuickReplyMessage
(QuickReplyMessage(..)) where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as AT
import qualified TD.Lib.Internal as I
import qualified TD.Data.MessageSendingState as MessageSendingState
import qualified TD.Data.MessageContent as MessageContent
import qualified TD.Data.ReplyMarkup as ReplyMarkup
data QuickReplyMessage
= QuickReplyMessage
{ QuickReplyMessage -> Maybe Int
_id :: Maybe Int
, QuickReplyMessage -> Maybe MessageSendingState
sending_state :: Maybe MessageSendingState.MessageSendingState
, QuickReplyMessage -> Maybe Bool
can_be_edited :: Maybe Bool
, QuickReplyMessage -> Maybe Int
reply_to_message_id :: Maybe Int
, QuickReplyMessage -> Maybe Int
via_bot_user_id :: Maybe Int
, QuickReplyMessage -> Maybe Int
media_album_id :: Maybe Int
, QuickReplyMessage -> Maybe MessageContent
content :: Maybe MessageContent.MessageContent
, QuickReplyMessage -> Maybe ReplyMarkup
reply_markup :: Maybe ReplyMarkup.ReplyMarkup
}
deriving (QuickReplyMessage -> QuickReplyMessage -> Bool
(QuickReplyMessage -> QuickReplyMessage -> Bool)
-> (QuickReplyMessage -> QuickReplyMessage -> Bool)
-> Eq QuickReplyMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: QuickReplyMessage -> QuickReplyMessage -> Bool
== :: QuickReplyMessage -> QuickReplyMessage -> Bool
$c/= :: QuickReplyMessage -> QuickReplyMessage -> Bool
/= :: QuickReplyMessage -> QuickReplyMessage -> Bool
Eq, Int -> QuickReplyMessage -> ShowS
[QuickReplyMessage] -> ShowS
QuickReplyMessage -> String
(Int -> QuickReplyMessage -> ShowS)
-> (QuickReplyMessage -> String)
-> ([QuickReplyMessage] -> ShowS)
-> Show QuickReplyMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> QuickReplyMessage -> ShowS
showsPrec :: Int -> QuickReplyMessage -> ShowS
$cshow :: QuickReplyMessage -> String
show :: QuickReplyMessage -> String
$cshowList :: [QuickReplyMessage] -> ShowS
showList :: [QuickReplyMessage] -> ShowS
Show)
instance I.ShortShow QuickReplyMessage where
shortShow :: QuickReplyMessage -> String
shortShow QuickReplyMessage
{ _id :: QuickReplyMessage -> Maybe Int
_id = Maybe Int
_id_
, sending_state :: QuickReplyMessage -> Maybe MessageSendingState
sending_state = Maybe MessageSendingState
sending_state_
, can_be_edited :: QuickReplyMessage -> Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
, reply_to_message_id :: QuickReplyMessage -> Maybe Int
reply_to_message_id = Maybe Int
reply_to_message_id_
, via_bot_user_id :: QuickReplyMessage -> Maybe Int
via_bot_user_id = Maybe Int
via_bot_user_id_
, media_album_id :: QuickReplyMessage -> Maybe Int
media_album_id = Maybe Int
media_album_id_
, content :: QuickReplyMessage -> Maybe MessageContent
content = Maybe MessageContent
content_
, reply_markup :: QuickReplyMessage -> Maybe ReplyMarkup
reply_markup = Maybe ReplyMarkup
reply_markup_
}
= String
"QuickReplyMessage"
String -> ShowS
forall a. [a] -> [a] -> [a]
++ [String] -> String
I.cc
[ String
"_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
_id_
, String
"sending_state" String -> Maybe MessageSendingState -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageSendingState
sending_state_
, String
"can_be_edited" String -> Maybe Bool -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Bool
can_be_edited_
, String
"reply_to_message_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
reply_to_message_id_
, String
"via_bot_user_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
via_bot_user_id_
, String
"media_album_id" String -> Maybe Int -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe Int
media_album_id_
, String
"content" String -> Maybe MessageContent -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe MessageContent
content_
, String
"reply_markup" String -> Maybe ReplyMarkup -> String
forall a. ShortShow a => String -> Maybe a -> String
`I.p` Maybe ReplyMarkup
reply_markup_
]
instance AT.FromJSON QuickReplyMessage where
parseJSON :: Value -> Parser QuickReplyMessage
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
"quickReplyMessage" -> Value -> Parser QuickReplyMessage
parseQuickReplyMessage Value
v
String
_ -> Parser QuickReplyMessage
forall a. Monoid a => a
mempty
where
parseQuickReplyMessage :: A.Value -> AT.Parser QuickReplyMessage
parseQuickReplyMessage :: Value -> Parser QuickReplyMessage
parseQuickReplyMessage = String
-> (Object -> Parser QuickReplyMessage)
-> Value
-> Parser QuickReplyMessage
forall a. String -> (Object -> Parser a) -> Value -> Parser a
A.withObject String
"QuickReplyMessage" ((Object -> Parser QuickReplyMessage)
-> Value -> Parser QuickReplyMessage)
-> (Object -> Parser QuickReplyMessage)
-> Value
-> Parser QuickReplyMessage
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe Int
_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"id"
Maybe MessageSendingState
sending_state_ <- Object
o Object -> Key -> Parser (Maybe MessageSendingState)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"sending_state"
Maybe Bool
can_be_edited_ <- Object
o Object -> Key -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"can_be_edited"
Maybe Int
reply_to_message_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reply_to_message_id"
Maybe Int
via_bot_user_id_ <- Object
o Object -> Key -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"via_bot_user_id"
Maybe Int
media_album_id_ <- (String -> Int) -> Maybe String -> Maybe Int
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap String -> Int
I.readInt64 (Maybe String -> Maybe Int)
-> Parser (Maybe String) -> Parser (Maybe Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
o Object -> Key -> Parser (Maybe String)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"media_album_id"
Maybe MessageContent
content_ <- Object
o Object -> Key -> Parser (Maybe MessageContent)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"content"
Maybe ReplyMarkup
reply_markup_ <- Object
o Object -> Key -> Parser (Maybe ReplyMarkup)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
A..:? Key
"reply_markup"
QuickReplyMessage -> Parser QuickReplyMessage
forall a. a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QuickReplyMessage -> Parser QuickReplyMessage)
-> QuickReplyMessage -> Parser QuickReplyMessage
forall a b. (a -> b) -> a -> b
$ QuickReplyMessage
{ _id :: Maybe Int
_id = Maybe Int
_id_
, sending_state :: Maybe MessageSendingState
sending_state = Maybe MessageSendingState
sending_state_
, can_be_edited :: Maybe Bool
can_be_edited = Maybe Bool
can_be_edited_
, reply_to_message_id :: Maybe Int
reply_to_message_id = Maybe Int
reply_to_message_id_
, via_bot_user_id :: Maybe Int
via_bot_user_id = Maybe Int
via_bot_user_id_
, media_album_id :: Maybe Int
media_album_id = Maybe Int
media_album_id_
, content :: Maybe MessageContent
content = Maybe MessageContent
content_
, reply_markup :: Maybe ReplyMarkup
reply_markup = Maybe ReplyMarkup
reply_markup_
}
parseJSON Value
_ = Parser QuickReplyMessage
forall a. Monoid a => a
mempty